Properly handle long message attachments for edited messages

This commit is contained in:
Scott Nonnenberg 2024-01-30 13:22:23 -08:00 committed by GitHub
parent 4daa1e4569
commit 304287efef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 114 additions and 19 deletions

View file

@ -115,6 +115,7 @@ export async function handleEditMessage(
{
attachments: mainMessage.attachments,
body: mainMessage.body,
bodyAttachment: mainMessage.bodyAttachment,
bodyRanges: mainMessage.bodyRanges,
preview: mainMessage.preview,
quote: mainMessage.quote,
@ -278,6 +279,25 @@ export async function handleEditMessage(
const updatedFields = await queueAttachmentDownloads(
mainMessageModel.attributes
);
// If we've scheduled a bodyAttachment download, we need that edit to know about it
if (updatedFields?.bodyAttachment) {
const existing =
updatedFields.editHistory || mainMessageModel.get('editHistory') || [];
updatedFields.editHistory = existing.map(item => {
if (item.timestamp !== editedMessage.timestamp) {
return item;
}
return {
...item,
attachments: updatedFields.attachments,
bodyAttachment: updatedFields.bodyAttachment,
};
});
}
if (updatedFields) {
mainMessageModel.set(updatedFields);
}