Files
discourse/plugins/chat/assets/javascripts/discourse/services/chat-channel-pane-subscriptions-manager.js
Martin Brennan 180e3e11d1 FEATURE: Better thread reply counter cache (#21108)
This commit introduces a redis cache over the top of the thread
replies_count DB cache, so that we can quickly and accurately
increment/decrement the reply count for all users and not have
to constantly update the database-level count. This is done so
the UI can have a count that is displayed to the users on each
thread indicator, that appears to live update on each chat
message create/trash/recover inside the thread.

This commit also introduces the `Chat::RestoreMessage` service
and moves the restore endpoint into the `Api::ChannelMessages`
controller as part of incremental migrations to move things out
of ChatController.

Finally, this commit refactors `Chat::Publisher` to be less repetitive
with its `MessageBus` sending code.
2023-04-18 14:01:01 +10:00

46 lines
1.3 KiB
JavaScript

import { inject as service } from "@ember/service";
import ChatPaneBaseSubscriptionsManager from "./chat-pane-base-subscriptions-manager";
export default class ChatChannelPaneSubscriptionsManager extends ChatPaneBaseSubscriptionsManager {
@service chat;
@service currentUser;
get messageBusChannel() {
return `/chat/${this.model.id}`;
}
get messageBusLastId() {
return this.model.channelMessageBusLastId;
}
// TODO (martin) Implement this for the channel, since it involves a bunch
// of scrolling and pane-specific logic. Will leave the existing sub inside
// ChatLivePane for now.
handleSentMessage() {
return;
}
// TODO (martin) Move scrolling functionality to pane from ChatLivePane?
afterProcessedMessage() {
// this.scrollToLatestMessage();
return;
}
handleThreadCreated(data) {
const message = this.messagesManager.findMessage(data.chat_message.id);
if (message) {
message.threadId = data.chat_message.thread_id;
message.threadReplyCount = 0;
}
}
handleThreadOriginalMessageUpdate(data) {
const message = this.messagesManager.findMessage(data.original_message_id);
if (message) {
if (data.replies_count) {
message.threadReplyCount = data.replies_count;
}
}
}
}