From ae3839580e4d0e6cf0974d019964d66dd012156b Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Thu, 4 Mar 2021 08:33:58 +1100 Subject: [PATCH] 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 --- app/models/post.rb | 1 + spec/models/post_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index 1b525a16413..3d835009136 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 856d46426f4..5db5dab72cf 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -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