fix: group admin delete attachments subset of attachments only

pull/3281/head
Audric Ackermann 4 months ago
parent 946812a362
commit b7cd4fc247
No known key found for this signature in database

@ -811,11 +811,20 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
networkTimestamp networkTimestamp
); );
const attachmentsWithVoiceMessage = attachments
? attachments.map(attachment => {
if (attachment.isVoiceMessage) {
return { ...attachment, flags: SignalService.AttachmentPointer.Flags.VOICE_MESSAGE };
}
return attachment;
})
: undefined;
const messageModel = await this.addSingleOutgoingMessage({ const messageModel = await this.addSingleOutgoingMessage({
body, body,
quote: isEmpty(quote) ? undefined : quote, quote: isEmpty(quote) ? undefined : quote,
preview, preview,
attachments, attachments: attachmentsWithVoiceMessage,
sent_at: networkTimestamp, // overridden later, but we need one to have the sorting done in the UI even when the sending is pending sent_at: networkTimestamp, // overridden later, but we need one to have the sorting done in the UI even when the sending is pending
expirationType: DisappearingMessages.changeToDisappearingMessageType( expirationType: DisappearingMessages.changeToDisappearingMessageType(
this, this,

@ -727,11 +727,14 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
thumbnail, thumbnail,
fileName, fileName,
caption, caption,
isVoiceMessage: isVoiceMessageFromDb,
} = attachment; } = attachment;
const isVoiceMessageBool = const isVoiceMessageBool =
!!isVoiceMessageFromDb ||
// eslint-disable-next-line no-bitwise // eslint-disable-next-line no-bitwise
Boolean(flags && flags & SignalService.AttachmentPointer.Flags.VOICE_MESSAGE) || false; !!(flags && flags & SignalService.AttachmentPointer.Flags.VOICE_MESSAGE) ||
false;
return { return {
id, id,

@ -22,6 +22,7 @@ import {
last, last,
map, map,
omit, omit,
some,
uniq, uniq,
} from 'lodash'; } from 'lodash';
@ -1107,7 +1108,7 @@ async function getAllMessagesWithAttachmentsInConversationSentBefore(
.all({ conversationId, beforeMs: deleteAttachBeforeSeconds * 1000 }); .all({ conversationId, beforeMs: deleteAttachBeforeSeconds * 1000 });
const messages = map(rows, row => jsonToObject(row.json)); const messages = map(rows, row => jsonToObject(row.json));
const messagesWithAttachments = messages.filter(m => { const messagesWithAttachments = messages.filter(m => {
return getExternalFilesForMessage(m, false).some(a => !isEmpty(a) && isString(a)); // when we remove an attachment, we set the path to '' so it should be excluded here return hasUserVisibleAttachments(m);
}); });
return messagesWithAttachments; return messagesWithAttachments;
} }
@ -2092,7 +2093,7 @@ function getMessagesWithFileAttachments(conversationId: string, limit: number) {
return map(rows, row => jsonToObject(row.json)); return map(rows, row => jsonToObject(row.json));
} }
function getExternalFilesForMessage(message: any, includePreview = true) { function getExternalFilesForMessage(message: any) {
const { attachments, quote, preview } = message; const { attachments, quote, preview } = message;
const files: Array<string> = []; const files: Array<string> = [];
@ -2110,7 +2111,6 @@ function getExternalFilesForMessage(message: any, includePreview = true) {
files.push(screenshot.path); files.push(screenshot.path);
} }
}); });
if (quote && quote.attachments && quote.attachments.length) { if (quote && quote.attachments && quote.attachments.length) {
forEach(quote.attachments, attachment => { forEach(quote.attachments, attachment => {
const { thumbnail } = attachment; const { thumbnail } = attachment;
@ -2121,7 +2121,7 @@ function getExternalFilesForMessage(message: any, includePreview = true) {
}); });
} }
if (includePreview && preview && preview.length) { if (preview && preview.length) {
forEach(preview, item => { forEach(preview, item => {
const { image } = item; const { image } = item;
@ -2134,6 +2134,30 @@ function getExternalFilesForMessage(message: any, includePreview = true) {
return files; return files;
} }
/**
* This looks like `getExternalFilesForMessage`, but it does not include some type of attachments not visible from the right panel.
* It should only be used when we look for messages to mark as deleted when an admin
* triggers a "delete messages with attachments since".
* Note: quoted attachments are referencing the original message, so we don't need to include them here.
* Note: previews are not considered user visible (because not visible from the right panel),
* so we don't need to include them here
* Note: voice messages are not considered user visible (because not visible from the right panel),
*/
function hasUserVisibleAttachments(message: any) {
const { attachments } = message;
return some(attachments, attachment => {
const { path: file, flags, thumbnail, screenshot } = attachment;
return (
// eslint-disable-next-line no-bitwise
(file && !(flags & SignalService.AttachmentPointer.Flags.VOICE_MESSAGE)) ||
thumbnail?.path ||
screenshot?.path
);
});
}
function getExternalFilesForConversation( function getExternalFilesForConversation(
conversationAvatar: conversationAvatar:
| string | string

Loading…
Cancel
Save