FIX: message bus when group private message (#12269)

When the private message was addressed to the group.
Group members didn't receive MessageBus messages about new posts.
To see content, they needed to refresh the page.

Meta: https://meta.discourse.org/t/group-private-message-message-bus-issue/181009/7
This commit is contained in:
Krzysztof Kotlarek 2021-03-04 08:33:58 +11:00 committed by GitHub
parent e06076268a
commit ae3839580e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -214,6 +214,7 @@ class Post < ActiveRecord::Base
if topic.private_message?
opts[:user_ids] = User.human_users.where("admin OR moderator").pluck(:id)
opts[:user_ids] |= topic.allowed_users.pluck(:id)
opts[:user_ids] |= topic.allowed_group_users.pluck(:id)
else
opts[:group_ids] = topic.secure_group_ids
end

View File

@ -1714,4 +1714,30 @@ describe Post do
expect(urls).to be_empty
end
end
describe "#publish_changes_to_client!" do
fab!(:user1) { Fabricate(:user) }
fab!(:user3) { Fabricate(:user) }
fab!(:topic) { Fabricate(:private_message_topic, user: user1) }
fab!(:post) { Fabricate(:post, topic: topic) }
fab!(:group_user) { Fabricate(:group_user, user: user3) }
fab!(:topic_allowed_group) { Fabricate(:topic_allowed_group, topic: topic, group: group_user.group) }
let(:user2) { topic.allowed_users.last }
it 'send message to all users participating in private conversation' do
freeze_time
message = {
id: post.id,
post_number: post.post_number,
updated_at: Time.now,
user_id: post.user_id,
last_editor_id: post.last_editor_id,
type: :created,
version: post.version
}
MessageBus.expects(:publish).with("/topic/#{topic.id}", message, user_ids: [user1.id, user2.id, user3.id]).once
post.publish_change_to_clients!(:created)
end
end
end