Support for local deletes synced to all your devices

This commit is contained in:
Scott Nonnenberg 2024-05-29 01:56:00 +10:00 committed by GitHub
parent 06f71a7ef8
commit 11eb1782a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 2094 additions and 72 deletions

View file

@ -115,7 +115,7 @@ const exclusiveInterface: ClientExclusiveInterface = {
flushUpdateConversationBatcher,
shutdown,
removeAllMessagesInConversation,
removeMessagesInConversation,
removeOtherData,
cleanupOrphanedAttachments,
@ -592,6 +592,21 @@ async function removeMessage(id: string): Promise<void> {
}
}
export async function deleteAndCleanup(
messages: Array<MessageAttributesType>,
logId: string
): Promise<void> {
const ids = messages.map(message => message.id);
log.info(`deleteAndCleanup/${logId}: Deleting ${ids.length} messages...`);
await channels.removeMessages(ids);
log.info(`deleteAndCleanup/${logId}: Cleanup for ${ids.length} messages...`);
await _cleanupMessages(messages);
log.info(`deleteAndCleanup/${logId}: Complete`);
}
async function _cleanupMessages(
messages: ReadonlyArray<MessageAttributesType>
): Promise<void> {
@ -664,12 +679,14 @@ async function getConversationRangeCenteredOnMessage(
};
}
async function removeAllMessagesInConversation(
async function removeMessagesInConversation(
conversationId: string,
{
logId,
receivedAt,
}: {
logId: string;
receivedAt?: number;
}
): Promise<void> {
let messages;
@ -685,6 +702,7 @@ async function removeAllMessagesInConversation(
conversationId,
limit: chunkSize,
includeStoryReplies: true,
receivedAt,
storyId: undefined,
});
@ -692,15 +710,8 @@ async function removeAllMessagesInConversation(
return;
}
const ids = messages.map(message => message.id);
log.info(`removeAllMessagesInConversation/${logId}: Cleanup...`);
// eslint-disable-next-line no-await-in-loop
await _cleanupMessages(messages);
log.info(`removeAllMessagesInConversation/${logId}: Deleting...`);
// eslint-disable-next-line no-await-in-loop
await channels.removeMessages(ids);
await deleteAndCleanup(messages, logId);
} while (messages.length > 0);
}