Files
discourse/plugins/chat/assets/javascripts/discourse/models/chat-thread.js
Joffrey JAFFEUX c6b43ce68b FEATURE: Thread list initial UI (#21412)
This commit adds an initial thread list UI. There are several limitations
with this that will be addressed in future PRs:

* There is no MessageBus reactivity, so e.g. if someone edits the original
   message of the thread it will not be reflected in the list. However if
   the thread title is updated the original message indicator will be updated.
* There is no unread functionality for threads in the list, if new messages
   come into the thread there is no indicator in the UI.
* There is no unread indicator on the actual button to open the thread list.
* No pagination.

In saying that, this is the functionality so far:

* We show a list of the 50 threads that the user has most recently participated
   in (i.e. sent a message) for the channel in descending order.
* Each thread we show a rich excerpt, the title, and the user who is the OM creator.
* The title is editable by staff and by the OM creator.
* Thread indicators show a title. We also replace emojis in the titles.
* Thread list works in the drawer/mobile.
2023-05-10 11:42:32 +02:00

69 lines
1.7 KiB
JavaScript

import { getOwner } from "discourse-common/lib/get-owner";
import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager";
import { escapeExpression } from "discourse/lib/utilities";
import { tracked } from "@glimmer/tracking";
import guid from "pretty-text/guid";
import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message";
export const THREAD_STATUSES = {
open: "open",
readOnly: "read_only",
closed: "closed",
archived: "archived",
};
export default class ChatThread {
@tracked id;
@tracked title;
@tracked status;
@tracked draft;
@tracked staged;
@tracked channel;
@tracked originalMessage;
@tracked threadMessageBusLastId;
@tracked replyCount;
messagesManager = new ChatMessagesManager(getOwner(this));
constructor(channel, args = {}) {
this.title = args.title;
this.id = args.id;
this.channel = channel;
this.status = args.status;
this.draft = args.draft;
this.staged = args.staged;
this.replyCount = args.reply_count;
this.originalMessage = ChatMessage.create(channel, args.original_message);
}
stageMessage(message) {
message.id = guid();
message.staged = true;
message.draft = false;
message.createdAt ??= moment.utc().format();
message.cook();
this.messagesManager.addMessages([message]);
}
get routeModels() {
return [...this.channel.routeModels, this.id];
}
get messages() {
return this.messagesManager.messages;
}
set messages(messages) {
this.messagesManager.messages = messages;
}
get selectedMessages() {
return this.messages.filter((message) => message.selected);
}
get escapedTitle() {
return escapeExpression(this.title);
}
}