From 95a51b7d8aae5c613ea6155886beab2e3985ebb7 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 2 Jun 2023 18:06:13 +0200 Subject: [PATCH] FIX: correctly set last message bus ids on resync (#21911) Replaces `channel.meta.message_bust_last_ids` on full resync instead of restarting the subscriptions, which was moreover not using a correct id. --- .../services/chat-subscriptions-manager.js | 9 --------- .../assets/javascripts/discourse/services/chat.js | 15 ++++++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-subscriptions-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-subscriptions-manager.js index 5dd75258bf7..b0ed9f1b264 100644 --- a/plugins/chat/assets/javascripts/discourse/services/chat-subscriptions-manager.js +++ b/plugins/chat/assets/javascripts/discourse/services/chat-subscriptions-manager.js @@ -54,15 +54,6 @@ export default class ChatSubscriptionsManager extends Service { this._channelSubscriptions.delete(channel.id); } - restartChannelsSubscriptions(messageBusIds) { - this.stopChannelsSubscriptions(); - this.startChannelsSubscriptions(messageBusIds); - - (this.chatChannelsManager.channels || []).forEach((channel) => { - this.startChannelSubscription(channel); - }); - } - startChannelsSubscriptions(messageBusIds) { this._startNewChannelSubscription(messageBusIds.new_channel); this._startChannelArchiveStatusSubscription(messageBusIds.archive_status); diff --git a/plugins/chat/assets/javascripts/discourse/services/chat.js b/plugins/chat/assets/javascripts/discourse/services/chat.js index dcf145aa837..fbe7e9008b2 100644 --- a/plugins/chat/assets/javascripts/discourse/services/chat.js +++ b/plugins/chat/assets/javascripts/discourse/services/chat.js @@ -115,14 +115,10 @@ export default class Chat extends Service { if (present) { // NOTE: channels is more than a simple array, it also contains // tracking and membership data, see Chat::StructuredChannelSerializer - this.chatApi.listCurrentUserChannels().then((channels) => { - this.chatSubscriptionsManager.restartChannelsSubscriptions( - channels.meta.message_bus_last_ids - ); - + this.chatApi.listCurrentUserChannels().then((channelsView) => { [ - ...channels.public_channels, - ...channels.direct_message_channels, + ...channelsView.public_channels, + ...channelsView.direct_message_channels, ].forEach((channelObject) => { this.chatChannelsManager .find(channelObject.id, { fetchIfNotFound: false }) @@ -135,10 +131,11 @@ export default class Chat extends Service { // endpoint that gives you all channel tracking state and the // thread tracking state for the current channel. if (channel) { + channel.meta.message_bus_last_ids = + channelObject.meta.message_bus_last_ids; channel.updateMembership(channelObject.current_user_membership); - const channelTrackingState = - channels.tracking.channel_tracking[channel.id]; + channelsView.tracking.channel_tracking[channel.id]; channel.tracking.unreadCount = channelTrackingState.unread_count; channel.tracking.mentionCount =