Joffrey JAFFEUX 4de1d3952b
FIX: improves draft for channels (#21724)
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.
2023-05-24 15:36:46 +02:00

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 = {};
}
}