Improve handling of edited long message attachments

This commit is contained in:
trevor-signal
2025-02-25 14:23:36 -05:00
committed by GitHub
parent da2741ba31
commit 6f9438c74f
9 changed files with 357 additions and 77 deletions

View File

@@ -33,6 +33,8 @@ import { isAciString } from '../util/isAciString';
import { normalizeAci } from '../util/normalizeAci';
import { bytesToUuid } from '../util/uuidToBytes';
import { createName } from '../util/attachmentPath';
import { partitionBodyAndNormalAttachments } from '../types/Attachment';
import { isNotNil } from '../util/isNotNil';
const FLAGS = Proto.DataMessage.Flags;
export const ATTACHMENT_MAX = 32;
@@ -316,14 +318,22 @@ export function processDataMessage(
);
}
const processedAttachments = message.attachments
?.map((attachment: Proto.IAttachmentPointer) => ({
...processAttachment(attachment),
downloadPath: doCreateName(),
}))
.filter(isNotNil);
const { bodyAttachment, attachments } = partitionBodyAndNormalAttachments(
{ attachments: processedAttachments ?? [] },
{ logId: `processDataMessage(${timestamp})` }
);
const result: ProcessedDataMessage = {
body: dropNull(message.body),
attachments: (message.attachments ?? []).map(
(attachment: Proto.IAttachmentPointer) => ({
...processAttachment(attachment),
downloadPath: doCreateName(),
})
),
bodyAttachment,
attachments,
groupV2: processGroupV2Context(message.groupV2),
flags: message.flags ?? 0,
expireTimer: DurationInSeconds.fromSeconds(message.expireTimer ?? 0),