FEATURE: Warn when reviving a topic that has been inactive for X days. Setting warn_reviving_old_topic_age controls when the warning is shown. Set it to 0 to disable this feature.

This commit is contained in:
Neil Lalonde 2014-03-12 10:44:08 -04:00
parent 363fabd3e7
commit 659e7fa4ce
4 changed files with 72 additions and 0 deletions

View File

@ -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"

View File

@ -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

View File

@ -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?

View File

@ -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