From 2f38316bfcac9c0828c1f89a98f88daf329e9a57 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Fri, 7 Feb 2014 05:49:45 +0530 Subject: [PATCH] Don't notify about dominating private messages. --- app/models/user_history.rb | 2 +- lib/composer_messages_finder.rb | 9 +++++---- spec/components/composer_messages_finder_spec.rb | 13 +++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/models/user_history.rb b/app/models/user_history.rb index 73bc57379..3ae417b26 100644 --- a/app/models/user_history.rb +++ b/app/models/user_history.rb @@ -18,7 +18,7 @@ class UserHistory < ActiveRecord::Base :checked_for_custom_avatar, :notified_about_avatar, :notified_about_sequential_replies, - :notitied_about_dominating_topic, + :notified_about_dominating_topic, :suspend_user, :unsuspend_user) end diff --git a/lib/composer_messages_finder.rb b/lib/composer_messages_finder.rb index c7f27bcba..c27616bc0 100644 --- a/lib/composer_messages_finder.rb +++ b/lib/composer_messages_finder.rb @@ -97,12 +97,13 @@ class ComposerMessagesFinder return unless replying? && @details[:topic_id] && (@user.post_count >= SiteSetting.educate_until_posts) && - !UserHistory.exists_for_user?(@user, :notitied_about_dominating_topic, topic_id: @details[:topic_id]) + !UserHistory.exists_for_user?(@user, :notified_about_dominating_topic, topic_id: @details[:topic_id]) topic = Topic.where(id: @details[:topic_id]).first return if topic.blank? || topic.user_id == @user.id || - topic.posts_count < SiteSetting.summary_posts_required + topic.posts_count < SiteSetting.summary_posts_required || + topic.archetype == Archetype.private_message posts_by_user = @user.posts.where(topic_id: topic.id).count @@ -110,7 +111,7 @@ class ComposerMessagesFinder return if ratio < (SiteSetting.dominating_topic_minimum_percent.to_f / 100.0) # Log the topic notification - UserHistory.create!(action: UserHistory.actions[:notitied_about_dominating_topic], + UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic], target_user_id: @user.id, topic_id: @details[:topic_id]) @@ -130,4 +131,4 @@ class ComposerMessagesFinder return @details[:composerAction] == "reply" end -end \ No newline at end of file +end diff --git a/spec/components/composer_messages_finder_spec.rb b/spec/components/composer_messages_finder_spec.rb index f211157a1..240679592 100644 --- a/spec/components/composer_messages_finder_spec.rb +++ b/spec/components/composer_messages_finder_spec.rb @@ -232,12 +232,12 @@ describe ComposerMessagesFinder do end it "doesn't notify a user it has already notified in this topic" do - UserHistory.create!(action: UserHistory.actions[:notitied_about_dominating_topic], topic_id: topic.id, target_user_id: user.id ) + UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic], topic_id: topic.id, target_user_id: user.id ) finder.check_dominating_topic.should be_blank end it "notifies a user if the topic is different" do - UserHistory.create!(action: UserHistory.actions[:notitied_about_dominating_topic], topic_id: topic.id+1, target_user_id: user.id ) + UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic], topic_id: topic.id+1, target_user_id: user.id ) finder.check_dominating_topic.should be_present end @@ -256,6 +256,11 @@ describe ComposerMessagesFinder do finder.check_dominating_topic.should be_blank end + it "doesn't notify you in a private message" do + topic.update_column(:archetype, Archetype.private_message) + finder.check_dominating_topic.should be_blank + end + context "success" do let!(:message) { finder.check_dominating_topic } @@ -263,8 +268,8 @@ describe ComposerMessagesFinder do message.should be_present end - it "creates a notitied_about_dominating_topic log" do - UserHistory.exists_for_user?(user, :notitied_about_dominating_topic).should be_true + it "creates a notified_about_dominating_topic log" do + UserHistory.exists_for_user?(user, :notified_about_dominating_topic).should be_true end end