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 { getContactId } from '../messages/helpers';
|
||||||
import { handleEditMessage } from '../util/handleEditMessage';
|
import { handleEditMessage } from '../util/handleEditMessage';
|
||||||
import { getMessageSentTimestamp } from '../util/getMessageSentTimestamp';
|
import { getMessageSentTimestamp } from '../util/getMessageSentTimestamp';
|
||||||
|
import {
|
||||||
|
isAttachmentDownloadQueueEmpty,
|
||||||
|
registerQueueEmptyCallback,
|
||||||
|
} from '../util/attachmentDownloadQueue';
|
||||||
|
|
||||||
export type EditAttributesType = {
|
export type EditAttributesType = {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
|
@ -40,6 +44,14 @@ export function forMessage(
|
||||||
const sentAt = getMessageSentTimestamp(messageAttributes, { log });
|
const sentAt = getMessageSentTimestamp(messageAttributes, { log });
|
||||||
const editValues = Array.from(edits.values());
|
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 => {
|
const matchingEdits = editValues.filter(item => {
|
||||||
return (
|
return (
|
||||||
item.targetSentTimestamp === sentAt &&
|
item.targetSentTimestamp === sentAt &&
|
||||||
|
@ -66,11 +78,26 @@ export function forMessage(
|
||||||
return [];
|
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> {
|
export async function onEdit(edit: EditAttributesType): Promise<void> {
|
||||||
edits.set(edit.envelopeId, edit);
|
edits.set(edit.envelopeId, edit);
|
||||||
|
|
||||||
const logId = `Edits.onEdit(timestamp=${edit.message.timestamp};target=${edit.targetSentTimestamp})`;
|
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 {
|
try {
|
||||||
// The conversation the edited message was in; we have to find it in the database
|
// The conversation the edited message was in; we have to find it in the database
|
||||||
// to to figure that out.
|
// 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 isEnabled = true;
|
||||||
let attachmentDownloadQueue: Array<MessageModel> | undefined = [];
|
let attachmentDownloadQueue: Array<MessageModel> | undefined = [];
|
||||||
|
const queueEmptyCallbacks: Set<() => void> = new Set();
|
||||||
|
|
||||||
export function shouldUseAttachmentDownloadQueue(): boolean {
|
export function shouldUseAttachmentDownloadQueue(): boolean {
|
||||||
return isEnabled;
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isAttachmentDownloadQueueEmpty(): boolean {
|
||||||
|
return !(attachmentDownloadQueue ?? []).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerQueueEmptyCallback(callback: () => void): void {
|
||||||
|
queueEmptyCallbacks.add(callback);
|
||||||
|
}
|
||||||
|
|
||||||
export function addToAttachmentDownloadQueue(
|
export function addToAttachmentDownloadQueue(
|
||||||
idLog: string,
|
idLog: string,
|
||||||
message: MessageModel
|
message: MessageModel
|
||||||
|
@ -71,4 +80,6 @@ export async function flushAttachmentDownloadQueue(): Promise<void> {
|
||||||
});
|
});
|
||||||
|
|
||||||
attachmentDownloadQueue = undefined;
|
attachmentDownloadQueue = undefined;
|
||||||
|
queueEmptyCallbacks.forEach(callback => callback());
|
||||||
|
queueEmptyCallbacks.clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue