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