diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index b875ca1b1614..f3b5836ad3e5 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -134,7 +134,6 @@ import type { SendTypesType } from '../util/handleMessageSend'; import { getStoriesBlocked } from '../util/stories'; import { isNotNil } from '../util/isNotNil'; import { chunk } from '../util/iterables'; -import { isOlderThan } from '../util/timestamp'; import { inspectUnknownFieldTags } from '../util/inspectProtobufs'; import { incrementMessageCounter } from '../util/incrementMessageCounter'; import { filterAndClean } from '../types/BodyRange'; @@ -2389,17 +2388,6 @@ export default class MessageReceiver return; } - // Timing check - if (isOlderThan(envelope.serverTimestamp, durations.DAY * 2)) { - log.info( - 'MessageReceiver.handleEditMessage: cannot edit message older than 48h', - logId, - envelope.serverTimestamp - ); - this.removeFromCache(envelope); - return; - } - const message = this.processDecrypted(envelope, msg.dataMessage); const groupId = this.getProcessedGroupId(message); const isBlocked = groupId ? this.isGroupBlocked(groupId) : false; diff --git a/ts/util/deleteForEveryone.ts b/ts/util/deleteForEveryone.ts index e4d5242a9fdc..796b18080c58 100644 --- a/ts/util/deleteForEveryone.ts +++ b/ts/util/deleteForEveryone.ts @@ -4,10 +4,10 @@ import type { DeleteAttributesType } from '../messageModifiers/Deletes'; import type { MessageModel } from '../models/messages'; import * as log from '../logging/log'; -import { DAY } from './durations'; import { isMe } from './whatTypeOfConversation'; import { getContactId } from '../messages/helpers'; import { isStory } from '../state/selectors/message'; +import { isTooOldToModifyMessage } from './isTooOldToModifyMessage'; export async function deleteForEveryone( message: MessageModel, @@ -33,7 +33,7 @@ export async function deleteForEveryone( return; } - if (isDeletionTooOld(message, doe)) { + if (isTooOldToModifyMessage(doe.serverTimestamp, message.attributes)) { log.warn('Received late DOE. Dropping.', { fromId: doe.fromId, targetSentTimestamp: doe.targetSentTimestamp, @@ -58,13 +58,3 @@ function isDeletionByMe( doe.fromId === ourConversationId ); } - -function isDeletionTooOld( - message: Readonly, - doe: Pick -): boolean { - const messageTimestamp = - message.get('serverTimestamp') || message.get('sent_at') || 0; - const delta = Math.abs(doe.serverTimestamp - messageTimestamp); - return delta > DAY * 2; -} diff --git a/ts/util/handleEditMessage.ts b/ts/util/handleEditMessage.ts index 474defa7528b..bee99aa80c58 100644 --- a/ts/util/handleEditMessage.ts +++ b/ts/util/handleEditMessage.ts @@ -10,7 +10,6 @@ import type { } from '../model-types.d'; import type { LinkPreviewType } from '../types/message/LinkPreviews'; import * as Edits from '../messageModifiers/Edits'; -import * as durations from './durations'; import * as log from '../logging/log'; import { ReadStatus } from '../messages/MessageReadStatus'; import dataInterface from '../sql/Client'; @@ -20,8 +19,8 @@ import { isAciString } from '../types/ServiceId'; import { getMessageIdForLogging } from './idForLogging'; import { hasErrors } from '../state/selectors/message'; import { isIncoming, isOutgoing } from '../messages/helpers'; -import { isOlderThan } from './timestamp'; import { isDirectConversation } from './whatTypeOfConversation'; +import { isTooOldToModifyMessage } from './isTooOldToModifyMessage'; import { queueAttachmentDownloads } from './queueAttachmentDownloads'; import { modifyTargetMessage } from './modifyTargetMessage'; @@ -84,7 +83,7 @@ export async function handleEditMessage( if ( serverTimestamp && !isNoteToSelf && - isOlderThan(serverTimestamp, durations.DAY * 2) + isTooOldToModifyMessage(serverTimestamp, mainMessage) ) { log.warn(`${idLog}: cannot edit message older than 48h`, serverTimestamp); return; diff --git a/ts/util/isTooOldToModifyMessage.ts b/ts/util/isTooOldToModifyMessage.ts new file mode 100644 index 000000000000..5e7db06f0f22 --- /dev/null +++ b/ts/util/isTooOldToModifyMessage.ts @@ -0,0 +1,14 @@ +// Copyright 2023 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import type { MessageAttributesType } from '../model-types.d'; +import { DAY } from './durations'; + +export function isTooOldToModifyMessage( + serverTimestamp: number, + message: MessageAttributesType +): boolean { + const messageTimestamp = message.serverTimestamp || message.sent_at || 0; + const delta = Math.abs(serverTimestamp - messageTimestamp); + return delta > DAY * 2; +}