2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-08-07 16:36:37 +00:00
|
|
|
import type { DeleteAttributesType } from '../messageModifiers/Deletes';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { MessageModel } from '../models/messages';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../logging/log';
|
2022-11-30 19:21:13 +00:00
|
|
|
import { isMe } from './whatTypeOfConversation';
|
2022-08-05 16:05:30 +00:00
|
|
|
import { getContactId } from '../messages/helpers';
|
2022-11-30 19:21:13 +00:00
|
|
|
import { isStory } from '../state/selectors/message';
|
2023-09-12 20:12:07 +00:00
|
|
|
import { isTooOldToModifyMessage } from './isTooOldToModifyMessage';
|
2020-07-27 18:15:32 +00:00
|
|
|
|
|
|
|
export async function deleteForEveryone(
|
2020-09-24 20:57:54 +00:00
|
|
|
message: MessageModel,
|
2023-08-07 16:36:37 +00:00
|
|
|
doe: Pick<
|
|
|
|
DeleteAttributesType,
|
|
|
|
'fromId' | 'targetSentTimestamp' | 'serverTimestamp'
|
|
|
|
>,
|
2020-09-14 21:56:35 +00:00
|
|
|
shouldPersist = true
|
2020-07-27 18:15:32 +00:00
|
|
|
): Promise<void> {
|
2022-08-05 16:05:30 +00:00
|
|
|
if (isDeletionByMe(message, doe)) {
|
2022-11-30 19:21:13 +00:00
|
|
|
const conversation = message.getConversation();
|
|
|
|
|
|
|
|
// Our 1:1 stories are deleted through ts/util/onStoryRecipientUpdate.ts
|
|
|
|
if (
|
|
|
|
isStory(message.attributes) &&
|
|
|
|
conversation &&
|
|
|
|
isMe(conversation.attributes)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-05 16:05:30 +00:00
|
|
|
await message.handleDeleteForEveryone(doe, shouldPersist);
|
|
|
|
return;
|
|
|
|
}
|
2021-08-13 16:02:28 +00:00
|
|
|
|
2023-09-12 20:12:07 +00:00
|
|
|
if (isTooOldToModifyMessage(doe.serverTimestamp, message.attributes)) {
|
2022-08-05 16:05:30 +00:00
|
|
|
log.warn('Received late DOE. Dropping.', {
|
2023-08-07 16:36:37 +00:00
|
|
|
fromId: doe.fromId,
|
|
|
|
targetSentTimestamp: doe.targetSentTimestamp,
|
2020-07-27 18:15:32 +00:00
|
|
|
messageServerTimestamp: message.get('serverTimestamp'),
|
2021-08-13 16:02:28 +00:00
|
|
|
messageSentAt: message.get('sent_at'),
|
2023-08-07 16:36:37 +00:00
|
|
|
deleteServerTimestamp: doe.serverTimestamp,
|
2020-07-27 18:15:32 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await message.handleDeleteForEveryone(doe, shouldPersist);
|
|
|
|
}
|
2022-08-05 16:05:30 +00:00
|
|
|
|
|
|
|
function isDeletionByMe(
|
|
|
|
message: Readonly<MessageModel>,
|
2023-08-07 16:36:37 +00:00
|
|
|
doe: Pick<DeleteAttributesType, 'fromId'>
|
2022-08-05 16:05:30 +00:00
|
|
|
): boolean {
|
|
|
|
const ourConversationId =
|
|
|
|
window.ConversationController.getOurConversationIdOrThrow();
|
|
|
|
return (
|
|
|
|
getContactId(message.attributes) === ourConversationId &&
|
2023-08-07 16:36:37 +00:00
|
|
|
doe.fromId === ourConversationId
|
2022-08-05 16:05:30 +00:00
|
|
|
);
|
|
|
|
}
|