Don't process edits until attachmentDownloadQueue finishes

This commit is contained in:
ayumi-signal 2023-10-19 10:10:08 -07:00 committed by GitHub
parent 5ccb3af040
commit 6906e39c87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 796 additions and 541 deletions

View file

@ -11,11 +11,20 @@ const MAX_ATTACHMENT_MSGS_TO_DOWNLOAD = 250;
let isEnabled = true;
let attachmentDownloadQueue: Array<MessageModel> | undefined = [];
const queueEmptyCallbacks: Set<() => void> = new Set();
export function shouldUseAttachmentDownloadQueue(): boolean {
return isEnabled;
}
export function isAttachmentDownloadQueueEmpty(): boolean {
return !(attachmentDownloadQueue ?? []).length;
}
export function registerQueueEmptyCallback(callback: () => void): void {
queueEmptyCallbacks.add(callback);
}
export function addToAttachmentDownloadQueue(
idLog: string,
message: MessageModel
@ -71,4 +80,6 @@ export async function flushAttachmentDownloadQueue(): Promise<void> {
});
attachmentDownloadQueue = undefined;
queueEmptyCallbacks.forEach(callback => callback());
queueEmptyCallbacks.clear();
}