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

Channels and threads are cached as much as possible, as a result the `last_message_bus_id` can become stalled.

It was for example exhibited with the following actions:
- open a channel (A)
- send a message
- navigate to another channel (B)
- come back to channel (A), and you would actually get all the messages replayed since you opened (A) for the first time as the `last_message_bus_id` would only refresh on a full page reload

This was technically not causing known bugs ATM, but was probably the source of few hard to repro bugs and would for sure cause issues in the future.

Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
This commit is contained in:
Joffrey JAFFEUX 2023-08-25 19:17:48 +02:00 committed by GitHub
parent dcbfb8c54b
commit 4ee0f4e5ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 15 deletions

View File

@ -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() {

View File

@ -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() {

View File

@ -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) {