Don't process edits until attachmentDownloadQueue finishes
This commit is contained in:
parent
5ccb3af040
commit
6906e39c87
3 changed files with 796 additions and 541 deletions
|
@ -8,6 +8,10 @@ import { drop } from '../util/drop';
|
|||
import { getContactId } from '../messages/helpers';
|
||||
import { handleEditMessage } from '../util/handleEditMessage';
|
||||
import { getMessageSentTimestamp } from '../util/getMessageSentTimestamp';
|
||||
import {
|
||||
isAttachmentDownloadQueueEmpty,
|
||||
registerQueueEmptyCallback,
|
||||
} from '../util/attachmentDownloadQueue';
|
||||
|
||||
export type EditAttributesType = {
|
||||
conversationId: string;
|
||||
|
@ -40,6 +44,14 @@ export function forMessage(
|
|||
const sentAt = getMessageSentTimestamp(messageAttributes, { log });
|
||||
const editValues = Array.from(edits.values());
|
||||
|
||||
if (!isAttachmentDownloadQueueEmpty()) {
|
||||
log.info(
|
||||
'Edits.forMessage attachmentDownloadQueue not empty, not processing edits'
|
||||
);
|
||||
registerQueueEmptyCallback(flushEdits);
|
||||
return [];
|
||||
}
|
||||
|
||||
const matchingEdits = editValues.filter(item => {
|
||||
return (
|
||||
item.targetSentTimestamp === sentAt &&
|
||||
|
@ -66,11 +78,26 @@ export function forMessage(
|
|||
return [];
|
||||
}
|
||||
|
||||
export async function flushEdits(): Promise<void> {
|
||||
log.info('Edits.flushEdits running');
|
||||
return drop(
|
||||
Promise.all(Array.from(edits.values()).map(edit => onEdit(edit)))
|
||||
);
|
||||
}
|
||||
|
||||
export async function onEdit(edit: EditAttributesType): Promise<void> {
|
||||
edits.set(edit.envelopeId, edit);
|
||||
|
||||
const logId = `Edits.onEdit(timestamp=${edit.message.timestamp};target=${edit.targetSentTimestamp})`;
|
||||
|
||||
if (!isAttachmentDownloadQueueEmpty()) {
|
||||
log.info(
|
||||
`${logId}: attachmentDownloadQueue not empty, not processing edits`
|
||||
);
|
||||
registerQueueEmptyCallback(flushEdits);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// The conversation the edited message was in; we have to find it in the database
|
||||
// to to figure that out.
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue