2022-07-01 00:52:03 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { ConversationAttributesType } from '../model-types.d';
|
|
|
|
import type { ConversationQueueJobData } from '../jobs/conversationJobQueue';
|
|
|
|
import * as Errors from '../types/errors';
|
2023-10-13 21:54:36 +00:00
|
|
|
import { DAY } from './durations';
|
2022-07-01 00:52:03 +00:00
|
|
|
import * as log from '../logging/log';
|
|
|
|
import {
|
|
|
|
conversationJobQueue,
|
|
|
|
conversationQueueJobEnum,
|
|
|
|
} from '../jobs/conversationJobQueue';
|
|
|
|
import { deleteForEveryone } from './deleteForEveryone';
|
2022-10-20 22:10:10 +00:00
|
|
|
import {
|
|
|
|
getConversationIdForLogging,
|
|
|
|
getMessageIdForLogging,
|
|
|
|
} from './idForLogging';
|
2023-10-04 00:12:57 +00:00
|
|
|
import { __DEPRECATED$getMessageById } from '../messages/getMessageById';
|
2022-07-01 00:52:03 +00:00
|
|
|
import { getRecipientConversationIds } from './getRecipientConversationIds';
|
|
|
|
import { getRecipients } from './getRecipients';
|
|
|
|
import { repeat, zipObject } from './iterables';
|
2023-11-26 22:22:56 +00:00
|
|
|
import { isMe } from './whatTypeOfConversation';
|
2022-07-01 00:52:03 +00:00
|
|
|
|
|
|
|
export async function sendDeleteForEveryoneMessage(
|
|
|
|
conversationAttributes: ConversationAttributesType,
|
|
|
|
options: {
|
|
|
|
deleteForEveryoneDuration?: number;
|
|
|
|
id: string;
|
|
|
|
timestamp: number;
|
|
|
|
}
|
|
|
|
): Promise<void> {
|
|
|
|
const {
|
|
|
|
deleteForEveryoneDuration,
|
|
|
|
timestamp: targetTimestamp,
|
|
|
|
id: messageId,
|
|
|
|
} = options;
|
2023-10-04 00:12:57 +00:00
|
|
|
const message = await __DEPRECATED$getMessageById(messageId);
|
2022-07-01 00:52:03 +00:00
|
|
|
if (!message) {
|
|
|
|
throw new Error('sendDeleteForEveryoneMessage: Cannot find message!');
|
|
|
|
}
|
2022-11-29 02:07:26 +00:00
|
|
|
const idForLogging = getMessageIdForLogging(message.attributes);
|
2022-07-01 00:52:03 +00:00
|
|
|
|
2023-11-26 22:22:56 +00:00
|
|
|
// If conversation is a Note To Self, no deletion time limits apply.
|
|
|
|
if (!isMe(conversationAttributes)) {
|
|
|
|
const timestamp = Date.now();
|
|
|
|
const maxDuration = deleteForEveryoneDuration || DAY;
|
|
|
|
if (timestamp - targetTimestamp > maxDuration) {
|
2023-11-26 23:52:47 +00:00
|
|
|
throw new Error(
|
|
|
|
`Cannot send DOE for a message older than ${maxDuration}`
|
|
|
|
);
|
2023-11-26 22:22:56 +00:00
|
|
|
}
|
2022-07-01 00:52:03 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 02:07:26 +00:00
|
|
|
message.set({
|
2022-07-01 00:52:03 +00:00
|
|
|
deletedForEveryoneSendStatus: zipObject(
|
|
|
|
getRecipientConversationIds(conversationAttributes),
|
|
|
|
repeat(false)
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
2022-11-11 23:09:10 +00:00
|
|
|
const conversationIdForLogging = getConversationIdForLogging(
|
|
|
|
conversationAttributes
|
|
|
|
);
|
|
|
|
|
|
|
|
log.info(
|
2023-01-01 11:41:40 +00:00
|
|
|
`sendDeleteForEveryoneMessage: enqueuing DeleteForEveryone: ${idForLogging} ` +
|
2022-11-11 23:09:10 +00:00
|
|
|
`in conversation ${conversationIdForLogging}`
|
|
|
|
);
|
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
try {
|
|
|
|
const jobData: ConversationQueueJobData = {
|
|
|
|
type: conversationQueueJobEnum.enum.DeleteForEveryone,
|
|
|
|
conversationId: conversationAttributes.id,
|
|
|
|
messageId,
|
|
|
|
recipients: getRecipients(conversationAttributes),
|
|
|
|
revision: conversationAttributes.revision,
|
|
|
|
targetTimestamp,
|
|
|
|
};
|
|
|
|
await conversationJobQueue.add(jobData, async jobToInsert => {
|
|
|
|
log.info(
|
2022-10-20 22:10:10 +00:00
|
|
|
`sendDeleteForEveryoneMessage: Deleting message ${idForLogging} ` +
|
|
|
|
`in conversation ${conversationIdForLogging} with job ${jobToInsert.id}`
|
2022-07-01 00:52:03 +00:00
|
|
|
);
|
2022-11-29 02:07:26 +00:00
|
|
|
await window.Signal.Data.saveMessage(message.attributes, {
|
2022-07-01 00:52:03 +00:00
|
|
|
jobToInsert,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
2022-07-01 00:52:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
log.error(
|
2022-10-20 22:10:10 +00:00
|
|
|
`sendDeleteForEveryoneMessage: Failed to queue delete for everyone for message ${idForLogging}`,
|
2022-07-01 00:52:03 +00:00
|
|
|
Errors.toLogFormat(error)
|
|
|
|
);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2023-08-07 16:36:37 +00:00
|
|
|
await deleteForEveryone(message, {
|
2022-07-01 00:52:03 +00:00
|
|
|
targetSentTimestamp: targetTimestamp,
|
|
|
|
serverTimestamp: Date.now(),
|
|
|
|
fromId: window.ConversationController.getOurConversationIdOrThrow(),
|
|
|
|
});
|
|
|
|
}
|