From 1365bab0d7840e4b1ff83287db557d35a04b909a Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 6 Mar 2018 14:38:43 +0800 Subject: [PATCH] FEATURE: Live updates for user's messages page. https://meta.discourse.org/t/group-inbox-messages-not-updated-for-new-posts/38189 --- .../components/basic-topic-list.js.es6 | 8 +- .../controllers/discovery/topics.js.es6 | 2 +- .../controllers/user-private-messages.js.es6 | 1 - .../controllers/user-topics-list.js.es6 | 42 +++++- .../discourse/models/topic-list.js.es6 | 6 +- .../build-private-messages-route.js.es6 | 8 +- .../user-private-messages-archive.js.es6 | 2 +- ...user-private-messages-group-archive.js.es6 | 1 + .../routes/user-private-messages-group.js.es6 | 1 + .../routes/user-private-messages-index.js.es6 | 2 +- .../routes/user-private-messages-sent.js.es6 | 2 +- .../templates/components/basic-topic-list.hbs | 9 ++ .../discourse/templates/user-topics-list.hbs | 5 +- app/assets/stylesheets/common/base/user.scss | 9 ++ app/controllers/topics_controller.rb | 8 +- app/models/group_archived_message.rb | 15 +- app/models/topic_tracking_state.rb | 38 +++++ app/models/user_archived_message.rb | 17 ++- lib/post_creator.rb | 4 +- lib/post_jobs_enqueuer.rb | 6 +- lib/topics_bulk_action.rb | 8 +- spec/models/topic_tracking_state_spec.rb | 131 ++++++++++++++++-- spec/models/user_archived_message_spec.rb | 4 +- spec/services/user_merger_spec.rb | 8 +- 24 files changed, 296 insertions(+), 41 deletions(-) diff --git a/app/assets/javascripts/discourse/components/basic-topic-list.js.es6 b/app/assets/javascripts/discourse/components/basic-topic-list.js.es6 index 260d13ce288..986ac0ff6cb 100644 --- a/app/assets/javascripts/discourse/components/basic-topic-list.js.es6 +++ b/app/assets/javascripts/discourse/components/basic-topic-list.js.es6 @@ -61,5 +61,11 @@ export default Ember.Component.extend({ } return false; } - } + }, + + actions: { + showInserted() { + this.sendAction('showInserted'); + }, + }, }); diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index e955208acc2..8d3f4b4b86c 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -42,7 +42,7 @@ const controllerOpts = { const tracker = this.topicTrackingState; // Move inserted into topics - this.get('content').loadBefore(tracker.get('newIncoming')); + this.get('content').loadBefore(tracker.get('newIncoming'), true); tracker.resetTracking(); return false; }, diff --git a/app/assets/javascripts/discourse/controllers/user-private-messages.js.es6 b/app/assets/javascripts/discourse/controllers/user-private-messages.js.es6 index bb79db55d37..87d477ffd22 100644 --- a/app/assets/javascripts/discourse/controllers/user-private-messages.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user-private-messages.js.es6 @@ -33,7 +33,6 @@ export default Ember.Controller.extend({ return hasSelection && pmView !== "archive" && !archive; }, - bulkOperation(operation) { const selected = this.get('selected'); var params = {type: operation}; diff --git a/app/assets/javascripts/discourse/controllers/user-topics-list.js.es6 b/app/assets/javascripts/discourse/controllers/user-topics-list.js.es6 index 8e150fd2890..804f0ebf508 100644 --- a/app/assets/javascripts/discourse/controllers/user-topics-list.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user-topics-list.js.es6 @@ -1,18 +1,58 @@ +import computed from 'ember-addons/ember-computed-decorators'; + // Lists of topics on a user's page. export default Ember.Controller.extend({ application: Ember.inject.controller(), hideCategory: false, showPosters: false, + newIncoming: [], + incomingCount: 0, + channel: null, _showFooter: function() { this.set("application.showFooter", !this.get("model.canLoadMore")); }.observes("model.canLoadMore"), + @computed('incomingCount') + hasIncoming(incomingCount) { + return incomingCount > 0; + }, + + subscribe(channel) { + this.set('channel', channel); + + this.messageBus.subscribe(channel, data => { + if (this.get('newIncoming').indexOf(data.topic_id) === -1) { + this.get('newIncoming').push(data.topic_id); + this.incrementProperty('incomingCount'); + } + }); + }, + + unsubscribe() { + this.messageBus.unsubscribe(this.get('channel')); + this._resetTracking(); + }, + + _resetTracking() { + this.setProperties({ + "newIncoming": [], + "incomingCount": 0, + "channel": null, + }); + }, + actions: { loadMore: function() { this.get('model').loadMore(); - } + }, + + showInserted() { + this.get('model').loadBefore(this.get('newIncoming')); + this._resetTracking(); + return false; + }, }, }); diff --git a/app/assets/javascripts/discourse/models/topic-list.js.es6 b/app/assets/javascripts/discourse/models/topic-list.js.es6 index 3e39ae5c895..61fdac3e298 100644 --- a/app/assets/javascripts/discourse/models/topic-list.js.es6 +++ b/app/assets/javascripts/discourse/models/topic-list.js.es6 @@ -70,14 +70,14 @@ const TopicList = RestModel.extend({ // loads topics with these ids "before" the current topics - loadBefore(topic_ids) { + loadBefore(topic_ids, storeInSession) { const topicList = this, topics = this.get('topics'); // refresh dupes topics.removeObjects(topics.filter(topic => topic_ids.indexOf(topic.get('id')) >= 0)); - const url = `${Discourse.getURL("/")}${this.get('filter')}?topic_ids=${topic_ids.join(",")}`; + const url = `${Discourse.getURL("/")}${this.get('filter')}.json?topic_ids=${topic_ids.join(",")}`; const store = this.store; return ajax({ url }).then(result => { @@ -88,7 +88,7 @@ const TopicList = RestModel.extend({ topics.insertAt(i,t); i++; }); - Discourse.Session.currentProp('topicList', topicList); + if (storeInSession) Discourse.Session.currentProp('topicList', topicList); }); } }); diff --git a/app/assets/javascripts/discourse/routes/build-private-messages-route.js.es6 b/app/assets/javascripts/discourse/routes/build-private-messages-route.js.es6 index b20e9e1b3dc..a0ae48b6b3e 100644 --- a/app/assets/javascripts/discourse/routes/build-private-messages-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-private-messages-route.js.es6 @@ -1,7 +1,7 @@ import UserTopicListRoute from "discourse/routes/user-topic-list"; // A helper to build a user topic list route -export default (viewName, path) => { +export default (viewName, path, channel) => { return UserTopicListRoute.extend({ userActionType: Discourse.UserAction.TYPES.messages_received, @@ -19,6 +19,10 @@ export default (viewName, path) => { setupController() { this._super.apply(this, arguments); + if (channel) { + this.controllerFor("user-topics-list").subscribe(`/private-messages/${channel}`); + } + this.controllerFor("user-topics-list").setProperties({ hideCategory: true, showPosters: true, @@ -32,6 +36,8 @@ export default (viewName, path) => { }, deactivate() { + this.controllerFor('user-topics-list').unsubscribe(); + this.searchService.set( 'searchContext', this.controllerFor("user").get("model.searchContext") diff --git a/app/assets/javascripts/discourse/routes/user-private-messages-archive.js.es6 b/app/assets/javascripts/discourse/routes/user-private-messages-archive.js.es6 index 7ebf279b290..ef304e9094b 100644 --- a/app/assets/javascripts/discourse/routes/user-private-messages-archive.js.es6 +++ b/app/assets/javascripts/discourse/routes/user-private-messages-archive.js.es6 @@ -1,3 +1,3 @@ import createPMRoute from "discourse/routes/build-private-messages-route"; -export default createPMRoute('archive', 'private-messages-archive'); +export default createPMRoute('archive', 'private-messages-archive', 'archive'); diff --git a/app/assets/javascripts/discourse/routes/user-private-messages-group-archive.js.es6 b/app/assets/javascripts/discourse/routes/user-private-messages-group-archive.js.es6 index 19d84f9b7e1..0f446249383 100644 --- a/app/assets/javascripts/discourse/routes/user-private-messages-group-archive.js.es6 +++ b/app/assets/javascripts/discourse/routes/user-private-messages-group-archive.js.es6 @@ -22,5 +22,6 @@ export default createPMRoute('groups', 'private-messages-groups').extend({ const group = split[split.length-2]; this.controllerFor("user-private-messages").set("groupFilter", group); this.controllerFor("user-private-messages").set("archive", true); + this.controllerFor("user-topics-list").subscribe(`/private-messages/group/${group}/archive`); } }); diff --git a/app/assets/javascripts/discourse/routes/user-private-messages-group.js.es6 b/app/assets/javascripts/discourse/routes/user-private-messages-group.js.es6 index 0b7f923f208..f02361f3bad 100644 --- a/app/assets/javascripts/discourse/routes/user-private-messages-group.js.es6 +++ b/app/assets/javascripts/discourse/routes/user-private-messages-group.js.es6 @@ -20,5 +20,6 @@ export default createPMRoute('groups', 'private-messages-groups').extend({ const group = _.last(model.get("filter").split('/')); this.controllerFor("user-private-messages").set("groupFilter", group); this.controllerFor("user-private-messages").set("archive", false); + this.controllerFor("user-topics-list").subscribe(`/private-messages/group/${group}`); } }); diff --git a/app/assets/javascripts/discourse/routes/user-private-messages-index.js.es6 b/app/assets/javascripts/discourse/routes/user-private-messages-index.js.es6 index d1e2bf3c275..127d64cfee6 100644 --- a/app/assets/javascripts/discourse/routes/user-private-messages-index.js.es6 +++ b/app/assets/javascripts/discourse/routes/user-private-messages-index.js.es6 @@ -1,3 +1,3 @@ import createPMRoute from "discourse/routes/build-private-messages-route"; -export default createPMRoute('index', 'private-messages'); +export default createPMRoute('index', 'private-messages', 'inbox'); diff --git a/app/assets/javascripts/discourse/routes/user-private-messages-sent.js.es6 b/app/assets/javascripts/discourse/routes/user-private-messages-sent.js.es6 index b31c2f4c9fe..2312be91796 100644 --- a/app/assets/javascripts/discourse/routes/user-private-messages-sent.js.es6 +++ b/app/assets/javascripts/discourse/routes/user-private-messages-sent.js.es6 @@ -1,3 +1,3 @@ import createPMRoute from "discourse/routes/build-private-messages-route"; -export default createPMRoute('sent', 'private-messages-sent'); +export default createPMRoute('sent', 'private-messages-sent', 'sent'); diff --git a/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs index c174d4a9b42..fbcad14b57a 100644 --- a/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs @@ -1,4 +1,13 @@ {{#conditional-loading-spinner condition=loading}} + {{#if hasIncoming}} +
+
+ {{count-i18n key="topic_count_" suffix="latest" count=incomingCount}} + {{i18n 'click_to_show'}} +
+
+ {{/if}} + {{#if topics}} {{topic-list showParticipants=showParticipants showPosters=showPosters diff --git a/app/assets/javascripts/discourse/templates/user-topics-list.hbs b/app/assets/javascripts/discourse/templates/user-topics-list.hbs index 355e4aee776..0749c7c837c 100644 --- a/app/assets/javascripts/discourse/templates/user-topics-list.hbs +++ b/app/assets/javascripts/discourse/templates/user-topics-list.hbs @@ -4,7 +4,10 @@ showParticipants=showParticipants showPosters=showPosters bulkSelectEnabled=bulkSelectEnabled - selected=selected}} + selected=selected + hasIncoming=hasIncoming + incomingCount=incomingCount + showInserted="showInserted"}} {{conditional-loading-spinner condition=model.loadingMore}} {{/load-more}} diff --git a/app/assets/stylesheets/common/base/user.scss b/app/assets/stylesheets/common/base/user.scss index 98608496a0a..ba4ccf5c094 100644 --- a/app/assets/stylesheets/common/base/user.scss +++ b/app/assets/stylesheets/common/base/user.scss @@ -7,6 +7,15 @@ margin-right: 10px; } } + + .paginated-topics-list { + position: relative; + } + + .show-mores { + position: absolute; + width: 100%; + } } .user-main { diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 1f5188eec66..505882f67b0 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -386,19 +386,19 @@ class TopicsController < ApplicationController .where('topic_allowed_groups.group_id IN (?)', group_ids).pluck(:id) allowed_groups.each do |id| if archive - GroupArchivedMessage.archive!(id, topic.id) + GroupArchivedMessage.archive!(id, topic) group_id = id else - GroupArchivedMessage.move_to_inbox!(id, topic.id) + GroupArchivedMessage.move_to_inbox!(id, topic) end end end if topic.allowed_users.include?(current_user) if archive - UserArchivedMessage.archive!(current_user.id, topic.id) + UserArchivedMessage.archive!(current_user.id, topic) else - UserArchivedMessage.move_to_inbox!(current_user.id, topic.id) + UserArchivedMessage.move_to_inbox!(current_user.id, topic) end end diff --git a/app/models/group_archived_message.rb b/app/models/group_archived_message.rb index 5ec3b9d6bac..9bc45aa8c98 100644 --- a/app/models/group_archived_message.rb +++ b/app/models/group_archived_message.rb @@ -2,17 +2,21 @@ class GroupArchivedMessage < ActiveRecord::Base belongs_to :user belongs_to :topic - def self.move_to_inbox!(group_id, topic_id) + def self.move_to_inbox!(group_id, topic) + topic_id = topic.id GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all trigger(:move_to_inbox, group_id, topic_id) MessageBus.publish("/topic/#{topic_id}", { type: "move_to_inbox" }, group_ids: [group_id]) + publish_topic_tracking_state(topic, false) end - def self.archive!(group_id, topic_id) + def self.archive!(group_id, topic) + topic_id = topic.id GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all GroupArchivedMessage.create!(group_id: group_id, topic_id: topic_id) trigger(:archive_message, group_id, topic_id) MessageBus.publish("/topic/#{topic_id}", { type: "archived" }, group_ids: [group_id]) + publish_topic_tracking_state(topic, true) end def self.trigger(event, group_id, topic_id) @@ -23,6 +27,13 @@ class GroupArchivedMessage < ActiveRecord::Base end end + private + + def self.publish_topic_tracking_state(topic, archived) + TopicTrackingState.publish_private_message( + topic, group_archived: archived + ) + end end # == Schema Information diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index 67cad80d857..aa4854a6c2b 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -246,4 +246,42 @@ SQL sql end + def self.publish_private_message(topic, archived: false, post: nil, group_archived: false) + return unless topic.private_message? + channels = {} + + allowed_user_ids = topic.allowed_users.pluck(:id) + + if allowed_user_ids.include?(post&.user_id) + channels["/private-messages/sent"] = [post.user_id] + end + + if archived + channels["/private-messages/archive"] = allowed_user_ids + else + topic.allowed_groups.each do |group| + channel = "/private-messages/group/#{group.name.downcase}" + channel = "#{channel}/archive" if group_archived + channels[channel] = group.users.pluck(:id) + end + end + + if channels.except("/private-messages/sent").blank? + channels["/private-messages/inbox"] = allowed_user_ids + end + + message = { + topic_id: topic.id + } + + admin_ids = User.admins.human_users.pluck(:id) + + channels.each do |channel, user_ids| + MessageBus.publish( + channel, + message.as_json, + user_ids: user_ids | admin_ids + ) + end + end end diff --git a/app/models/user_archived_message.rb b/app/models/user_archived_message.rb index 556667e3f79..010e75dd604 100644 --- a/app/models/user_archived_message.rb +++ b/app/models/user_archived_message.rb @@ -2,7 +2,9 @@ class UserArchivedMessage < ActiveRecord::Base belongs_to :user belongs_to :topic - def self.move_to_inbox!(user_id, topic_id) + def self.move_to_inbox!(user_id, topic) + topic_id = topic.id + return if (TopicUser.where( user_id: user_id, topic_id: topic_id, @@ -12,13 +14,16 @@ class UserArchivedMessage < ActiveRecord::Base UserArchivedMessage.where(user_id: user_id, topic_id: topic_id).destroy_all trigger(:move_to_inbox, user_id, topic_id) MessageBus.publish("/topic/#{topic_id}", { type: "move_to_inbox" }, user_ids: [user_id]) + publish_topic_tracking_state(topic, false) end - def self.archive!(user_id, topic_id) + def self.archive!(user_id, topic) + topic_id = topic.id UserArchivedMessage.where(user_id: user_id, topic_id: topic_id).destroy_all UserArchivedMessage.create!(user_id: user_id, topic_id: topic_id) trigger(:archive_message, user_id, topic_id) MessageBus.publish("/topic/#{topic_id}", { type: "archived" }, user_ids: [user_id]) + publish_topic_tracking_state(topic, true) end def self.trigger(event, user_id, topic_id) @@ -28,6 +33,14 @@ class UserArchivedMessage < ActiveRecord::Base DiscourseEvent.trigger(event, user: user, topic: topic) end end + + private + + def self.publish_topic_tracking_state(topic, archived) + TopicTrackingState.publish_private_message( + topic, archived: archived + ) + end end # == Schema Information diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 67694d527c8..bc21c7254f2 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -365,11 +365,11 @@ class PostCreator return unless @topic.private_message? && @topic.id UserArchivedMessage.where(topic_id: @topic.id).pluck(:user_id).each do |user_id| - UserArchivedMessage.move_to_inbox!(user_id, @topic.id) + UserArchivedMessage.move_to_inbox!(user_id, @topic) end GroupArchivedMessage.where(topic_id: @topic.id).pluck(:group_id).each do |group_id| - GroupArchivedMessage.move_to_inbox!(group_id, @topic.id) + GroupArchivedMessage.move_to_inbox!(group_id, @topic) end end diff --git a/lib/post_jobs_enqueuer.rb b/lib/post_jobs_enqueuer.rb index cb8fdb56c1a..898743e44a5 100644 --- a/lib/post_jobs_enqueuer.rb +++ b/lib/post_jobs_enqueuer.rb @@ -17,6 +17,10 @@ class PostJobsEnqueuer after_post_create after_topic_create end + + if @topic.private_message? + TopicTrackingState.publish_private_message(@topic, post: @post) + end end private @@ -35,7 +39,7 @@ class PostJobsEnqueuer def after_post_create TopicTrackingState.publish_unread(@post) if @post.post_number > 1 - TopicTrackingState.publish_latest(@topic, @post.post_type == Post.types[:whisper]) + TopicTrackingState.publish_latest(@topic, @post.whisper?) Jobs.enqueue_in( SiteSetting.email_time_window_mins.minutes, diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rb index a3675ff4265..2d16fb5c219 100644 --- a/lib/topics_bulk_action.rb +++ b/lib/topics_bulk_action.rb @@ -43,9 +43,9 @@ class TopicsBulkAction topics.each do |t| if guardian.can_see?(t) && t.private_message? if group - GroupArchivedMessage.move_to_inbox!(group.id, t.id) + GroupArchivedMessage.move_to_inbox!(group.id, t) else - UserArchivedMessage.move_to_inbox!(@user.id, t.id) + UserArchivedMessage.move_to_inbox!(@user.id, t) end end end @@ -56,9 +56,9 @@ class TopicsBulkAction topics.each do |t| if guardian.can_see?(t) && t.private_message? if group - GroupArchivedMessage.archive!(group.id, t.id) + GroupArchivedMessage.archive!(group.id, t) else - UserArchivedMessage.archive!(@user.id, t.id) + UserArchivedMessage.archive!(@user.id, t) end end end diff --git a/spec/models/topic_tracking_state_spec.rb b/spec/models/topic_tracking_state_spec.rb index f96e73ee47d..22cc79150fb 100644 --- a/spec/models/topic_tracking_state_spec.rb +++ b/spec/models/topic_tracking_state_spec.rb @@ -11,6 +11,8 @@ describe TopicTrackingState do end let(:topic) { post.topic } + let(:private_message_post) { Fabricate(:private_message_post) } + let(:private_message_topic) { private_message_post.topic } describe '#publish_latest' do it 'can correctly publish latest' do @@ -26,11 +28,9 @@ describe TopicTrackingState do end describe 'private message' do - let(:topic) { Fabricate(:private_message_topic) } - it 'should not publish any message' do messages = MessageBus.track_publish do - described_class.publish_latest(topic) + described_class.publish_latest(private_message_topic) end expect(messages).to eq([]) @@ -52,13 +52,10 @@ describe TopicTrackingState do end describe 'for a private message' do - let(:private_message_post) { Fabricate(:private_message_post) } - let(:topic) { private_message_post.topic } - before do TopicUser.change( - topic.allowed_users.first.id, - topic.id, + private_message_topic.allowed_users.first.id, + private_message_topic.id, notification_level: TopicUser.notification_levels[:tracking] ) end @@ -73,6 +70,124 @@ describe TopicTrackingState do end end + describe '#publish_private_message' do + let!(:admin) { Fabricate(:admin) } + + describe 'normal topic' do + it 'should publish the right message' do + allowed_users = private_message_topic.allowed_users + + messages = MessageBus.track_publish do + TopicTrackingState.publish_private_message(private_message_topic) + end + + expect(messages.count).to eq(1) + + message = messages.first + + expect(message.channel).to eq('/private-messages/inbox') + expect(message.data["topic_id"]).to eq(private_message_topic.id) + expect(message.user_ids).to eq(allowed_users.map(&:id) << admin.id) + end + end + + describe 'topic with groups' do + let(:group1) { Fabricate(:group, users: [Fabricate(:user)]) } + let(:group2) { Fabricate(:group, users: [Fabricate(:user), Fabricate(:user)]) } + + before do + [group1, group2].each do |group| + private_message_topic.allowed_groups << group + end + end + + it "should publish the right message" do + messages = MessageBus.track_publish do + TopicTrackingState.publish_private_message( + private_message_topic, + ) + end + + [group1, group2].each do |group| + message = messages.find do |message| + message.channel == "/private-messages/group/#{group.name}" + end + + expect(message.data["topic_id"]).to eq(private_message_topic.id) + expect(message.user_ids).to eq(group.users.map(&:id) << admin.id) + end + end + end + + describe 'topic with new post' do + let(:user) { private_message_topic.allowed_users.last } + + let!(:post) do + Fabricate(:post, + topic: private_message_topic, + user: user + ) + end + + it 'should publish the right message' do + messages = MessageBus.track_publish do + TopicTrackingState.publish_private_message( + private_message_topic, + post: post + ) + end + + expect(messages.count).to eq(2) + + [ + ['/private-messages/inbox', private_message_topic.allowed_users.map(&:id)], + ['/private-messages/sent', [user.id]] + ].each do |channel, user_ids| + message = messages.find do |message| + message.channel == channel + end + + expect(message.data["topic_id"]).to eq(private_message_topic.id) + expect(message.user_ids).to eq(user_ids << admin.id) + end + end + end + + describe 'archived topic' do + it 'should publish the right message' do + messages = MessageBus.track_publish do + TopicTrackingState.publish_private_message( + private_message_topic, + archived: true + ) + end + + expect(messages.count).to eq(1) + + message = messages.first + + expect(message.channel).to eq('/private-messages/archive') + expect(message.data["topic_id"]).to eq(private_message_topic.id) + + expect(message.user_ids).to eq( + private_message_topic.allowed_users.map(&:id) << admin.id + ) + end + end + + describe 'for a regular topic' do + it 'should not publish any message' do + topic.allowed_users << Fabricate(:user) + + messages = MessageBus.track_publish do + TopicTrackingState.publish_private_message(topic) + end + + expect(messages).to eq([]) + end + end + end + it "correctly handles muted categories" do user = Fabricate(:user) diff --git a/spec/models/user_archived_message_spec.rb b/spec/models/user_archived_message_spec.rb index 060a097de82..73f1a3e2601 100644 --- a/spec/models/user_archived_message_spec.rb +++ b/spec/models/user_archived_message_spec.rb @@ -10,11 +10,11 @@ describe UserArchivedMessage do target_usernames: [user2.username, user.username].join(","), archetype: Archetype.private_message).topic - UserArchivedMessage.archive!(user.id, topic.id) + UserArchivedMessage.archive!(user.id, topic) expect(topic.message_archived?(user)).to eq(true) TopicUser.change(user.id, topic.id, notification_level: TopicUser.notification_levels[:muted]) - UserArchivedMessage.move_to_inbox!(user.id, topic.id) + UserArchivedMessage.move_to_inbox!(user.id, topic) expect(topic.message_archived?(user)).to eq(true) end end diff --git a/spec/services/user_merger_spec.rb b/spec/services/user_merger_spec.rb index 0890645a9e6..91b1cbac862 100644 --- a/spec/services/user_merger_spec.rb +++ b/spec/services/user_merger_spec.rb @@ -762,10 +762,10 @@ describe UserMerger do Fabricate.build(:topic_allowed_user, user: source_user) ]) - UserArchivedMessage.archive!(source_user.id, pm_topic1.id) - UserArchivedMessage.archive!(target_user.id, pm_topic1.id) - UserArchivedMessage.archive!(source_user.id, pm_topic2.id) - UserArchivedMessage.archive!(walter.id, pm_topic2.id) + UserArchivedMessage.archive!(source_user.id, pm_topic1) + UserArchivedMessage.archive!(target_user.id, pm_topic1) + UserArchivedMessage.archive!(source_user.id, pm_topic2) + UserArchivedMessage.archive!(walter.id, pm_topic2) merge_users!