A platform for community discussion. Free, open, simple.
FIX: Make sure marking channels read propagates to all tabs (#20802)
Martin Brennan55ef4d9a98ab
diff --git a/plugins/chat/app/services/chat/mark_all_user_channels_read.rb b/plugins/chat/app/services/chat/mark_all_user_channels_read.rbindex e9291148d8a..57aff2eb77f 100644--- a/plugins/chat/app/services/chat/mark_all_user_channels_read.rb+++ b/plugins/chat/app/services/chat/mark_all_user_channels_read.rb@@ -17,6 +17,7 @@ module Chattransaction dostep :update_last_read_message_idsstep :mark_associated_mentions_as_read+ step :publish_user_tracking_stateendprivate@@ -51,5 +52,15 @@ module Chatchannel_ids: updated_memberships.map(&:channel_id),)end++ def publish_user_tracking_state(guardian:, updated_memberships:, **)+ updated_memberships.each do |membership|+ Chat::Publisher.publish_user_tracking_state(+ guardian.user,+ membership.channel_id,+ membership.last_read_message_id,+ )+ end+ endendenddiff --git a/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.jsindex 232023c3f97..d96cd1baebf 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js@@ -85,17 +85,8 @@ export default class ChatChannelsManager extends Service {@debounce(300)async markAllChannelsRead() {- return this.chatApi.markAllChannelsAsRead().then((response) => {- response.updated_memberships.forEach((membership) => {- let channel = this.channels.findBy("id", membership.channel_id);- if (channel) {- channel.currentUserMembership.unread_count = 0;- channel.currentUserMembership.unread_mentions = 0;- channel.currentUserMembership.last_read_message_id =- membership.last_read_message_id;- }- });- });+ // The user tracking state for each channel marked read will be propagated by MessageBus+ return this.chatApi.markAllChannelsAsRead();}remove(model) {diff --git a/plugins/chat/spec/services/chat/mark_all_user_channels_read_spec.rb b/plugins/chat/spec/services/chat/mark_all_user_channels_read_spec.rbindex 31adc20f294..55a987ea73a 100644--- a/plugins/chat/spec/services/chat/mark_all_user_channels_read_spec.rb+++ b/plugins/chat/spec/services/chat/mark_all_user_channels_read_spec.rb@@ -128,6 +128,13 @@ RSpec.describe Chat::MarkAllUserChannelsRead do).count}.by(-2)end++ it "publishes tracking state for all affected channels" do+ messages = MessageBus.track_publish { result }+ expect(+ messages.select { |m| m.channel == "/chat/user-tracking-state/#{current_user.id}" }.count,+ ).to eq(3)+ endendendend