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