mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 09:08:10 +08:00
DEV: allows to add a draft without persisting it (#31457)
On chat setup we get the initial state of drafts for the current users, we need to add them to the drafts manager, but we don't need to store them again on the backend. This commit adds a persist (boolean) parameter to the `ChatDraftsManager.add` service which when set to true will only add the draft on the frontend and not send it to the backend. No test, as the behavior is already tested and unchanged, this is only a performance improvement.
This commit is contained in:
@ -11,10 +11,13 @@ export default class ChatDraftsManager extends Service {
|
||||
cancel(this._persistHandler);
|
||||
}
|
||||
|
||||
async add(message, channelId, threadId) {
|
||||
async add(message, channelId, threadId, persist = true) {
|
||||
try {
|
||||
this.drafts[this.key(channelId, threadId)] = message;
|
||||
await this.persistDraft(message, channelId, threadId);
|
||||
|
||||
if (persist) {
|
||||
await this.persistDraft(message, channelId, threadId);
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log("Couldn't save draft", e);
|
||||
|
@ -236,7 +236,8 @@ export default class Chat extends Service {
|
||||
)
|
||||
),
|
||||
storedDraft.channel_id,
|
||||
storedDraft.thread_id
|
||||
storedDraft.thread_id,
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user