Enforce a minimum amount of posters in a topic for `get_a_room`
This commit is contained in:
parent
e863d66e33
commit
d27575176a
|
@ -136,7 +136,7 @@ class ComposerMessagesFinder
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_get_a_room
|
def check_get_a_room(min_users_posted: 5)
|
||||||
return unless educate_reply?(:notified_about_get_a_room)
|
return unless educate_reply?(:notified_about_get_a_room)
|
||||||
return unless @details[:post_id].present?
|
return unless @details[:post_id].present?
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ class ComposerMessagesFinder
|
||||||
find_all {|uid| uid != @user.id && uid == reply_to_user_id}
|
find_all {|uid| uid != @user.id && uid == reply_to_user_id}
|
||||||
|
|
||||||
return unless last_x_replies.size == SiteSetting.get_a_room_threshold
|
return unless last_x_replies.size == SiteSetting.get_a_room_threshold
|
||||||
|
return unless @topic.posts.count('distinct user_id') >= min_users_posted
|
||||||
|
|
||||||
UserHistory.create!(action: UserHistory.actions[:notified_about_get_a_room],
|
UserHistory.create!(action: UserHistory.actions[:notified_about_get_a_room],
|
||||||
target_user_id: @user.id,
|
target_user_id: @user.id,
|
||||||
|
|
|
@ -331,11 +331,11 @@ describe ComposerMessagesFinder do
|
||||||
|
|
||||||
it "does not show the message for new topics" do
|
it "does not show the message for new topics" do
|
||||||
finder = ComposerMessagesFinder.new(user, composer_action: 'createTopic')
|
finder = ComposerMessagesFinder.new(user, composer_action: 'createTopic')
|
||||||
expect(finder.check_get_a_room).to be_blank
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not give a message without a topic id" do
|
it "does not give a message without a topic id" do
|
||||||
expect(ComposerMessagesFinder.new(user, composer_action: 'reply').check_get_a_room).to be_blank
|
expect(ComposerMessagesFinder.new(user, composer_action: 'reply').check_get_a_room(min_users_posted: 2)).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
context "reply" do
|
context "reply" do
|
||||||
|
@ -343,7 +343,7 @@ describe ComposerMessagesFinder do
|
||||||
|
|
||||||
it "does not give a message to users who are still in the 'education' phase" do
|
it "does not give a message to users who are still in the 'education' phase" do
|
||||||
user.stubs(:post_count).returns(9)
|
user.stubs(:post_count).returns(9)
|
||||||
expect(finder.check_get_a_room).to be_blank
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't notify a user it has already notified about sequential replies" do
|
it "doesn't notify a user it has already notified about sequential replies" do
|
||||||
|
@ -352,7 +352,7 @@ describe ComposerMessagesFinder do
|
||||||
target_user_id: user.id,
|
target_user_id: user.id,
|
||||||
topic_id: topic.id
|
topic_id: topic.id
|
||||||
)
|
)
|
||||||
expect(finder.check_get_a_room).to be_blank
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
it "will notify you if it hasn't in the current topic" do
|
it "will notify you if it hasn't in the current topic" do
|
||||||
|
@ -361,28 +361,28 @@ describe ComposerMessagesFinder do
|
||||||
target_user_id: user.id,
|
target_user_id: user.id,
|
||||||
topic_id: topic.id+1
|
topic_id: topic.id+1
|
||||||
)
|
)
|
||||||
expect(finder.check_get_a_room).to be_present
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it "won't notify you if you haven't had enough posts" do
|
it "won't notify you if you haven't had enough posts" do
|
||||||
SiteSetting.get_a_room_threshold = 10
|
SiteSetting.get_a_room_threshold = 10
|
||||||
expect(finder.check_get_a_room).to be_blank
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't notify you if the posts aren't all to the same person" do
|
it "doesn't notify you if the posts aren't all to the same person" do
|
||||||
first_reply.update_column(:reply_to_user_id, user.id)
|
first_reply.update_column(:reply_to_user_id, user.id)
|
||||||
expect(finder.check_get_a_room).to be_blank
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't notify you of posts to yourself" do
|
it "doesn't notify you of posts to yourself" do
|
||||||
first_reply.update_column(:reply_to_user_id, user.id)
|
first_reply.update_column(:reply_to_user_id, user.id)
|
||||||
second_reply.update_column(:reply_to_user_id, user.id)
|
second_reply.update_column(:reply_to_user_id, user.id)
|
||||||
expect(finder.check_get_a_room).to be_blank
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't notify in a message" do
|
it "doesn't notify in a message" do
|
||||||
topic.update_columns(category_id: nil, archetype: 'private_message')
|
topic.update_columns(category_id: nil, archetype: 'private_message')
|
||||||
expect(finder.check_get_a_room).to be_blank
|
expect(finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't notify when replying to a different user" do
|
it "doesn't notify when replying to a different user" do
|
||||||
|
@ -393,11 +393,19 @@ describe ComposerMessagesFinder do
|
||||||
post_id: other_user_reply.id
|
post_id: other_user_reply.id
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(other_finder.check_get_a_room).to be_blank
|
expect(other_finder.check_get_a_room(min_users_posted: 2)).to be_blank
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a default min_users_posted value" do
|
||||||
|
let!(:message) { finder.check_get_a_room }
|
||||||
|
|
||||||
|
it "works as expected" do
|
||||||
|
expect(message).to be_blank
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "success" do
|
context "success" do
|
||||||
let!(:message) { finder.check_get_a_room }
|
let!(:message) { finder.check_get_a_room(min_users_posted: 2) }
|
||||||
|
|
||||||
it "works as expected" do
|
it "works as expected" do
|
||||||
expect(message).to be_present
|
expect(message).to be_present
|
||||||
|
|
Loading…
Reference in New Issue