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:
Joffrey JAFFEUX
2025-02-22 01:29:12 +01:00
committed by GitHub
parent eb1ef04ed5
commit cb257ff658
2 changed files with 7 additions and 3 deletions

View File

@ -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);

View File

@ -236,7 +236,8 @@ export default class Chat extends Service {
)
),
storedDraft.channel_id,
storedDraft.thread_id
storedDraft.thread_id,
false
);
});