Merge pull request #1916 from vikhyat/pm-dominating

Don't notify about dominating private messages
This commit is contained in:
Régis Hanol 2014-02-07 00:28:27 -08:00
commit e47f462f54
3 changed files with 15 additions and 9 deletions

View File

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

View File

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

View File

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