diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 5e68dce6e8..5c820fc154 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -170,6 +170,13 @@ en: Instead of adding another reply, please consider editing your previous replies, or visiting other topics. + reviving_old_topic: | + ### Revive this topic? + + The last reply to this topic is now over %{days} days old. Your reply will bump the topic to the top of its list and notify anyone previously involved in the conversation. + + Are you sure you want to continue this old conversation? + activerecord: attributes: category: @@ -838,6 +845,7 @@ en: invites_shown: "Maximum invites shown on a user page" short_progress_text_threshold: "After the number of posts in a topic goes above this number, the progress bar will only show the current post number. If you change the progress bar's width, you may need to change this value." default_code_lang: "Default programming language syntax highlighting applied to GitHub code blocks (lang-auto, ruby, python etc.)" + warn_reviving_old_topic_age: "When someone starts replying to a topic older than this many days, a warning will be displayed to discourage the user from reviving an old discussion. Disable by setting to 0." embeddable_host: "Host that can embed the comments from this Discourse forum" feed_polling_enabled: "Whether to import a RSS/ATOM feed as posts" diff --git a/config/site_settings.yml b/config/site_settings.yml index 4758abd872..3d59f776a0 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -238,6 +238,7 @@ posting: default_code_lang: client: true default: "lang-auto" + warn_reviving_old_topic_age: 180 email: email_time_window_mins: 10 diff --git a/lib/composer_messages_finder.rb b/lib/composer_messages_finder.rb index fef9c25bce..50394baed1 100644 --- a/lib/composer_messages_finder.rb +++ b/lib/composer_messages_finder.rb @@ -6,6 +6,7 @@ class ComposerMessagesFinder end def find + check_reviving_old_topic || check_education_message || check_new_user_many_replies || check_avatar_notification || @@ -123,6 +124,21 @@ class ComposerMessagesFinder body: PrettyText.cook(I18n.t('education.dominating_topic', percent: (ratio * 100).round)) } end + def check_reviving_old_topic + return unless @details[:topic_id] + + topic = Topic.where(id: @details[:topic_id]).first + + return if topic.nil? || + SiteSetting.warn_reviving_old_topic_age < 1 || + topic.last_posted_at > SiteSetting.warn_reviving_old_topic_age.days.ago + + {templateName: 'composer/education', + wait_for_typing: false, + extraClass: 'urgent', + body: PrettyText.cook(I18n.t('education.reviving_old_topic', days: (Time.zone.now - topic.last_posted_at).round / 1.day)) } + end + private def creating_topic? diff --git a/spec/components/composer_messages_finder_spec.rb b/spec/components/composer_messages_finder_spec.rb index 2406795920..f7cd9519d0 100644 --- a/spec/components/composer_messages_finder_spec.rb +++ b/spec/components/composer_messages_finder_spec.rb @@ -14,6 +14,7 @@ describe ComposerMessagesFinder do finder.expects(:check_avatar_notification).once finder.expects(:check_sequential_replies).once finder.expects(:check_dominating_topic).once + finder.expects(:check_reviving_old_topic).once finder.find end @@ -277,5 +278,51 @@ describe ComposerMessagesFinder do end + context '.check_reviving_old_topic' do + let(:user) { Fabricate(:user) } + let(:topic) { Fabricate(:topic) } + + it "does not give a message without a topic id" do + described_class.new(user, composerAction: 'createTopic').check_reviving_old_topic.should be_blank + described_class.new(user, composerAction: 'reply').check_reviving_old_topic.should be_blank + end + + context "a reply" do + let(:finder) { described_class.new(user, composerAction: 'reply') } + + context "warn_reviving_old_topic_age is 180 days" do + before do + SiteSetting.stubs(:warn_reviving_old_topic_age).returns(180) + end + + it "does not notify if last post is recent" do + topic = Fabricate(:topic, last_posted_at: 1.hour.ago) + described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic.should be_blank + end + + it "notifies if last post is old" do + topic = Fabricate(:topic, last_posted_at: 181.days.ago) + described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic.should_not be_blank + end + end + + context "warn_reviving_old_topic_age is 0" do + before do + SiteSetting.stubs(:warn_reviving_old_topic_age).returns(0) + end + + it "does not notify if last post is new" do + topic = Fabricate(:topic, last_posted_at: 1.hour.ago) + described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic.should be_blank + end + + it "does not notify if last post is old" do + topic = Fabricate(:topic, last_posted_at: 365.days.ago) + described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic.should be_blank + end + end + end + end + end