Move to MessageCache.saveMessage, queue downloads piecemeal

This commit is contained in:
Scott Nonnenberg 2025-01-24 06:37:18 -10:00 committed by GitHub
parent 197660a966
commit ed30059bd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 138 additions and 298 deletions

View file

@ -33,7 +33,6 @@ import {
} from '../types/Receipt';
import { drop } from '../util/drop';
import { getMessageById } from '../messages/getMessageById';
import { postSaveUpdates } from '../util/cleanup';
import { MessageModel } from '../models/messages';
const { deleteSentProtoRecipient, removeSyncTaskById } = DataWriter;
@ -200,8 +199,7 @@ async function processReceiptsForMessage(
const { validReceipts } = await updateMessageWithReceipts(message, receipts);
const ourAci = window.textsecure.storage.user.getCheckedAci();
await DataWriter.saveMessage(message.attributes, { ourAci, postSaveUpdates });
await window.MessageCache.saveMessage(message.attributes);
// Confirm/remove receipts, and delete sent protos
for (const receipt of validReceipts) {

View file

@ -39,7 +39,6 @@ import {
conversationJobQueue,
conversationQueueJobEnum,
} from '../jobs/conversationJobQueue';
import { postSaveUpdates } from '../util/cleanup';
export type ReactionAttributesType = {
emoji: string;
@ -389,10 +388,8 @@ export async function handleReaction(
shouldSave: false,
});
// Note: generatedMessage comes with an id, so we have to force this save
await DataWriter.saveMessage(generatedMessage.attributes, {
ourAci: window.textsecure.storage.user.getCheckedAci(),
await window.MessageCache.saveMessage(generatedMessage.attributes, {
forceSave: true,
postSaveUpdates,
});
log.info('Reactions.onReaction adding reaction to story', {
@ -555,10 +552,8 @@ export async function handleReaction(
await hydrateStoryContext(generatedMessage.id, message.attributes, {
shouldSave: false,
});
await DataWriter.saveMessage(generatedMessage.attributes, {
ourAci: window.textsecure.storage.user.getCheckedAci(),
await window.MessageCache.saveMessage(generatedMessage.attributes, {
forceSave: true,
postSaveUpdates,
});
window.MessageCache.register(generatedMessage);
@ -586,20 +581,15 @@ export async function handleReaction(
jobToInsert.id
}`
);
await DataWriter.saveMessage(message.attributes, {
await window.MessageCache.saveMessage(message.attributes, {
jobToInsert,
ourAci: window.textsecure.storage.user.getCheckedAci(),
postSaveUpdates,
});
});
} else {
await conversationJobQueue.add(jobData);
}
} else if (shouldPersist && !isStory(message.attributes)) {
await DataWriter.saveMessage(message.attributes, {
ourAci: window.textsecure.storage.user.getCheckedAci(),
postSaveUpdates,
});
await window.MessageCache.saveMessage(message.attributes);
window.reduxActions.conversations.markOpenConversationRead(conversation.id);
}
}

View file

@ -124,12 +124,11 @@ export async function onSync(sync: ViewSyncAttributesType): Promise<void> {
const attachments = message.get('attachments');
if (!attachments?.every(isDownloaded)) {
const updatedFields = await queueAttachmentDownloads(
message.attributes,
{ urgency: AttachmentDownloadUrgency.STANDARD }
);
if (updatedFields) {
message.set(updatedFields);
const didQueueDownload = await queueAttachmentDownloads(message, {
urgency: AttachmentDownloadUrgency.STANDARD,
});
if (didQueueDownload) {
didChangeMessage = true;
}
}
}