Forward: Don't re-use timestamp or attachment files

This commit is contained in:
Scott Nonnenberg 2021-06-03 14:26:56 -07:00 committed by GitHub
parent 2370c227e3
commit 6d82acd23c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 7 deletions

View file

@ -3526,7 +3526,12 @@ export class ConversationModel extends window.Backbone
preview: WhatIsThis, preview: WhatIsThis,
sticker?: WhatIsThis, sticker?: WhatIsThis,
mentions?: BodyRangesType, mentions?: BodyRangesType,
{ dontClearDraft = false } = {} {
dontClearDraft,
timestamp,
}: { dontClearDraft: boolean; timestamp?: number } = {
dontClearDraft: false,
}
): void { ): void {
if (this.isGroupV1AndDisabled()) { if (this.isGroupV1AndDisabled()) {
return; return;
@ -3549,7 +3554,7 @@ export class ConversationModel extends window.Backbone
const recipients = this.getRecipients(); const recipients = this.getRecipients();
this.queueJob(async () => { this.queueJob(async () => {
const now = Date.now(); const now = timestamp || Date.now();
await this.maybeApplyUniversalTimer(); await this.maybeApplyUniversalTimer();

View file

@ -54,6 +54,7 @@ const {
getAbsoluteAttachmentPath, getAbsoluteAttachmentPath,
getAbsoluteDraftPath, getAbsoluteDraftPath,
getAbsoluteTempPath, getAbsoluteTempPath,
loadAttachmentData,
loadPreviewData, loadPreviewData,
loadStickerData, loadStickerData,
openFileInFolder, openFileInFolder,
@ -2350,6 +2351,9 @@ Whisper.ConversationView = Whisper.View.extend({
attachments?: Array<AttachmentType>, attachments?: Array<AttachmentType>,
linkPreview?: LinkPreviewType linkPreview?: LinkPreviewType
): Promise<boolean> { ): Promise<boolean> {
window.log.info(
`maybeForwardMessage/${message.idForLogging()}: Starting...`
);
const attachmentLookup = new Set(); const attachmentLookup = new Set();
if (attachments) { if (attachments) {
attachments.forEach(attachment => { attachments.forEach(attachment => {
@ -2420,31 +2424,49 @@ Whisper.ConversationView = Whisper.View.extend({
} }
const sendMessageOptions = { dontClearDraft: true }; const sendMessageOptions = { dontClearDraft: true };
let timestamp = Date.now();
// Actually send the message // Actually send the message
// load any sticker data, attachments, or link previews that we need to // load any sticker data, attachments, or link previews that we need to
// send along with the message and do the send to each conversation. // send along with the message and do the send to each conversation.
await Promise.all( await Promise.all(
conversations.map(async conversation => { conversations.map(async conversation => {
timestamp += 1;
if (conversation) { if (conversation) {
const sticker = message.get('sticker'); const sticker = message.get('sticker');
if (sticker) { if (sticker) {
const stickerWithData = await loadStickerData(sticker); const stickerWithData = await loadStickerData(sticker);
const stickerNoPath = stickerWithData
? {
...stickerWithData,
data: {
...stickerWithData.data,
path: undefined,
},
}
: undefined;
conversation.sendMessage( conversation.sendMessage(
null, null,
[], [],
null, null,
[], [],
stickerWithData, stickerNoPath,
undefined, undefined,
sendMessageOptions { ...sendMessageOptions, timestamp }
); );
} else { } else {
const preview = linkPreview const preview = linkPreview
? await loadPreviewData([linkPreview]) ? await loadPreviewData([linkPreview])
: []; : [];
const allAttachments = message.getAttachmentsForMessage(); const attachmentsWithData = await Promise.all(
const attachmentsToSend = allAttachments.filter( (attachments || []).map(async item => ({
...(await loadAttachmentData(item)),
path: undefined,
}))
);
const attachmentsToSend = attachmentsWithData.filter(
(attachment: Partial<AttachmentType>) => (attachment: Partial<AttachmentType>) =>
attachmentLookup.has( attachmentLookup.has(
`${attachment.fileName}/${attachment.contentType}` `${attachment.fileName}/${attachment.contentType}`
@ -2458,7 +2480,7 @@ Whisper.ConversationView = Whisper.View.extend({
preview, preview,
null, // sticker null, // sticker
undefined, // BodyRanges undefined, // BodyRanges
sendMessageOptions { ...sendMessageOptions, timestamp }
); );
} }
} }