mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 06:27:25 +08:00

This commit attempts to correctly change draft when the channel changes. It moves responsibility to the composer instead of the channel. A new service `chatDraftsManager` is being introduced here to allow finer control and pave the way for future thread draft support. These changes also now allow an editing message to be stored as a draft.
26 lines
561 B
JavaScript
26 lines
561 B
JavaScript
import Service from "@ember/service";
|
|
import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message";
|
|
export default class ChatDraftsManager extends Service {
|
|
drafts = {};
|
|
|
|
add(message) {
|
|
if (message instanceof ChatMessage) {
|
|
this.drafts[message.channel.id] = message;
|
|
} else {
|
|
throw new Error("message must be an instance of ChatMessage");
|
|
}
|
|
}
|
|
|
|
get({ channelId }) {
|
|
return this.drafts[channelId];
|
|
}
|
|
|
|
remove({ channelId }) {
|
|
delete this.drafts[channelId];
|
|
}
|
|
|
|
reset() {
|
|
this.drafts = {};
|
|
}
|
|
}
|