2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-24 20:57:54 +00:00
|
|
|
import { DeletesModelType } from '../model-types.d';
|
|
|
|
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,
|
2020-07-27 18:15:32 +00:00
|
|
|
doe: DeletesModelType,
|
2020-09-14 21:56:35 +00:00
|
|
|
shouldPersist = true
|
2020-07-27 18:15:32 +00:00
|
|
|
): Promise<void> {
|
|
|
|
// Make sure the server timestamps for the DOE and the matching message
|
|
|
|
// are less than one day apart
|
|
|
|
const delta = Math.abs(
|
2020-09-09 02:25:05 +00:00
|
|
|
doe.get('serverTimestamp') - (message.get('serverTimestamp') || 0)
|
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'),
|
|
|
|
deleteServerTimestamp: doe.get('serverTimestamp'),
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await message.handleDeleteForEveryone(doe, shouldPersist);
|
|
|
|
}
|