Skip to content

A platform for community discussion. Free, open, simple.

FIX: ensures we update cached model last message bus id (#23271)

Joffrey JAFFEUX4ee0f4e5ba68
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-channel-pane-subscriptions-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-channel-pane-subscriptions-manager.js
index e2e53ea15f6..f5cab64c176 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat-channel-pane-subscriptions-manager.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat-channel-pane-subscriptions-manager.js
@@ -11,12 +11,13 @@ export default class ChatChannelPaneSubscriptionsManager extends ChatPaneBaseSub
@tracked notices = new TrackedArray();
- get messageBusChannel() {
- return `/chat/${this.model.id}`;
+ beforeSubscribe(model) {
+ this.messageBusChannel = `/chat/${model.id}`;
+ this.messageBusLastId = model.channelMessageBusLastId;
}
- get messageBusLastId() {
- return this.model.channelMessageBusLastId;
+ afterMessage(model, _, __, lastMessageBusId) {
+ model.channelMessageBusLastId = lastMessageBusId;
}
handleSentMessage() {
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-pane-base-subscriptions-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-pane-base-subscriptions-manager.js
index 327b9e2bbf8..56b16e6d349 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat-pane-base-subscriptions-manager.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat-pane-base-subscriptions-manager.js
@@ -39,21 +39,25 @@ export default class ChatPaneBaseSubscriptionsManager extends Service {
@service currentUser;
@service chatStagedThreadMapping;
- get messageBusChannel() {
- throw "not implemented";
- }
-
- get messageBusLastId() {
- throw "not implemented";
- }
+ messageBusChannel = null;
+ messageBusLastId = null;
get messagesManager() {
return this.model.messagesManager;
}
+ beforeSubscribe() {}
+ afterMessage() {}
+
subscribe(model) {
this.unsubscribe();
+ this.beforeSubscribe(model);
this.model = model;
+
+ if (!this.messageBusChannel) {
+ return;
+ }
+
this.messageBus.subscribe(
this.messageBusChannel,
this.onMessage,
@@ -120,6 +124,8 @@ export default class ChatPaneBaseSubscriptionsManager extends Service {
this.handleNotice(busData);
break;
}
+
+ this.afterMessage(this.model, ...arguments);
}
handleSentMessage() {
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-thread-pane-subscriptions-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-thread-pane-subscriptions-manager.js
index 1b1845eafae..365c478b1aa 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat-thread-pane-subscriptions-manager.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat-thread-pane-subscriptions-manager.js
@@ -2,12 +2,13 @@ import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message";
import ChatPaneBaseSubscriptionsManager from "./chat-pane-base-subscriptions-manager";
export default class ChatThreadPaneSubscriptionsManager extends ChatPaneBaseSubscriptionsManager {
- get messageBusChannel() {
- return `/chat/${this.model.channel.id}/thread/${this.model.id}`;
+ beforeSubscribe(model) {
+ this.messageBusChannel = `/chat/${model.channel.id}/thread/${model.id}`;
+ this.messageBusLastId = model.threadMessageBusLastId;
}
- get messageBusLastId() {
- return this.model.threadMessageBusLastId;
+ afterMessage(model, _, __, lastMessageBusId) {
+ model.threadMessageBusLastId = lastMessageBusId;
}
handleSentMessage(data) {