diff --git a/app/assets/javascripts/discourse/views/topic-closing.js.es6 b/app/assets/javascripts/discourse/views/topic-closing.js.es6 index 23a303c153c..bfbd211a6e2 100644 --- a/app/assets/javascripts/discourse/views/topic-closing.js.es6 +++ b/app/assets/javascripts/discourse/views/topic-closing.js.es6 @@ -11,39 +11,37 @@ export default Discourse.View.extend({ elementId: 'topic-closing-info', delayedRerender: null, - shouldRerender: Discourse.View.renderIfChanged('topic.details.auto_close_at'), + shouldRerender: Discourse.View.renderIfChanged('topic.closed', 'topic.details.{auto_close_at,auto_close_based_on_last_post,auto_close_hours}'), render: function(buffer) { if (!this.present('topic.details.auto_close_at')) return; + if (this.get("topic.closed")) return; var autoCloseAt = moment(this.get('topic.details.auto_close_at')); - if (autoCloseAt < new Date()) return; var duration = moment.duration(autoCloseAt - moment()); + var minutesLeft = duration.asMinutes(); + var timeLeftString = duration.humanize(true); + var rerenderDelay = 1000; - var timeLeftString, rerenderDelay, minutesLeft = duration.asMinutes(); - - if (minutesLeft > 1410) { - timeLeftString = I18n.t('in_n_days', {count: Math.round(duration.asDays())}); - if( minutesLeft > 2160 ) { - rerenderDelay = 12 * 60 * 60000; - } else { - rerenderDelay = 60 * 60000; - } + if (minutesLeft > 2160) { + rerenderDelay = 12 * 60 * 60000; + } else if (minutesLeft > 1410) { + rerenderDelay = 60 * 60000; } else if (minutesLeft > 90) { - timeLeftString = I18n.t('in_n_hours', {count: Math.round(duration.asHours())}); rerenderDelay = 30 * 60000; } else if (minutesLeft > 2) { - timeLeftString = I18n.t('in_n_minutes', {count: Math.round(duration.asMinutes())}); rerenderDelay = 60000; - } else { - timeLeftString = I18n.t('in_n_seconds', {count: Math.round(duration.asSeconds())}); - rerenderDelay = 1000; } + var basedOnLastPost = this.get("topic.details.auto_close_based_on_last_post"); + var key = basedOnLastPost ? 'topic.auto_close_notice_based_on_last_post' : 'topic.auto_close_notice' + + var autoCloseHours = this.get("topic.details.auto_close_hours") || 0; + buffer.push('

'); - buffer.push( I18n.t('topic.auto_close_notice', {timeLeft: timeLeftString}) ); + buffer.push( I18n.t(key, { timeLeft: timeLeftString, duration: moment.duration(autoCloseHours, "hours").humanize() }) ); buffer.push('

'); // TODO Sam: concerned this can cause a heavy rerender loop diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 3d55b4dc11e..0d274365b5e 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -141,19 +141,6 @@ en: one: "{{count}} character" other: "{{count}} characters" - in_n_seconds: - one: "in 1 second" - other: "in {{count}} seconds" - in_n_minutes: - one: "in 1 minute" - other: "in {{count}} minutes" - in_n_hours: - one: "in 1 hour" - other: "in {{count}} hours" - in_n_days: - one: "in 1 day" - other: "in {{count}} days" - suggested_topics: title: "Suggested Topics" @@ -885,6 +872,7 @@ en: deleted: "The topic has been deleted" auto_close_notice: "This topic will automatically close %{timeLeft}." + auto_close_notice_based_on_last_post: "This topic will close %{duration} after the last reply." auto_close_title: 'Auto-Close Settings' auto_close_save: "Save" auto_close_remove: "Don't Auto-Close This Topic"