FIX: Exclude PMs that user sent to themselves. (#14496)
Regression from016efeadf6
Follow-up to016efeadf6
This commit is contained in:
parent
d39315239e
commit
34cebfd867
|
@ -5,6 +5,15 @@ class TopicQuery
|
||||||
def list_private_messages(user)
|
def list_private_messages(user)
|
||||||
list = private_messages_for(user, :user)
|
list = private_messages_for(user, :user)
|
||||||
list = not_archived(list, user)
|
list = not_archived(list, user)
|
||||||
|
|
||||||
|
list = list.where(<<~SQL)
|
||||||
|
NOT (
|
||||||
|
topics.participant_count = 1
|
||||||
|
AND topics.user_id = #{user.id.to_i}
|
||||||
|
AND topics.moderator_posts_count = 0
|
||||||
|
)
|
||||||
|
SQL
|
||||||
|
|
||||||
create_list(:private_messages, {}, list)
|
create_list(:private_messages, {}, list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe TopicQuery::PrivateMessageLists do
|
describe TopicQuery::PrivateMessageLists do
|
||||||
|
fab!(:admin) { Fabricate(:admin) }
|
||||||
fab!(:user) { Fabricate(:user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
fab!(:user_2) { Fabricate(:user) }
|
fab!(:user_2) { Fabricate(:user) }
|
||||||
fab!(:user_3) { Fabricate(:user) }
|
fab!(:user_3) { Fabricate(:user) }
|
||||||
|
@ -50,6 +51,17 @@ describe TopicQuery::PrivateMessageLists do
|
||||||
|
|
||||||
expect(topics).to contain_exactly(private_message)
|
expect(topics).to contain_exactly(private_message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "includes topics with moderator posts" do
|
||||||
|
pm = Fabricate(:private_message_post, user: user_4).topic
|
||||||
|
|
||||||
|
expect(TopicQuery.new(user_4).list_private_messages(user_4).topics).to be_empty
|
||||||
|
|
||||||
|
pm.add_moderator_post(admin, "Thank you for your flag")
|
||||||
|
|
||||||
|
expect(TopicQuery.new(user_4).list_private_messages(user_4).topics)
|
||||||
|
.to contain_exactly(pm)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#list_private_messages_group' do
|
describe '#list_private_messages_group' do
|
||||||
|
|
Loading…
Reference in New Issue