2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { DeleteModel } from '../messageModifiers/Deletes';
|
|
|
|
import type { MessageModel } from '../models/messages';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../logging/log';
|
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) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('Received late DOE. Dropping.', {
|
2020-07-27 18:15:32 +00:00
|
|
|
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);
|
|
|
|
}
|