2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
import { DeleteModel } from '../messageModifiers/Deletes';
|
2020-09-24 20:57:54 +00:00
|
|
|
import { MessageModel } from '../models/messages';
|
2020-07-27 18:15:32 +00:00
|
|
|
|
|
|
|
const ONE_DAY = 24 * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
export async function deleteForEveryone(
|
2020-09-24 20:57:54 +00:00
|
|
|
message: MessageModel,
|
2021-06-17 17:15:10 +00:00
|
|
|
doe: DeleteModel,
|
2020-09-14 21:56:35 +00:00
|
|
|
shouldPersist = true
|
2020-07-27 18:15:32 +00:00
|
|
|
): Promise<void> {
|
2021-08-13 16:02:28 +00:00
|
|
|
const messageTimestamp =
|
|
|
|
message.get('serverTimestamp') || message.get('sent_at') || 0;
|
|
|
|
|
2020-07-27 18:15:32 +00:00
|
|
|
// Make sure the server timestamps for the DOE and the matching message
|
|
|
|
// are less than one day apart
|
2021-08-13 16:02:28 +00:00
|
|
|
const delta = Math.abs(doe.get('serverTimestamp') - messageTimestamp);
|
|
|
|
|
2020-07-27 18:15:32 +00:00
|
|
|
if (delta > ONE_DAY) {
|
|
|
|
window.log.info('Received late DOE. Dropping.', {
|
|
|
|
fromId: doe.get('fromId'),
|
|
|
|
targetSentTimestamp: doe.get('targetSentTimestamp'),
|
|
|
|
messageServerTimestamp: message.get('serverTimestamp'),
|
2021-08-13 16:02:28 +00:00
|
|
|
messageSentAt: message.get('sent_at'),
|
2020-07-27 18:15:32 +00:00
|
|
|
deleteServerTimestamp: doe.get('serverTimestamp'),
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await message.handleDeleteForEveryone(doe, shouldPersist);
|
|
|
|
}
|