DRY up the message receive timing validation
This commit is contained in:
parent
7ea945c157
commit
944a70abe7
4 changed files with 18 additions and 27 deletions
|
@ -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;
|
||||
|
|
|
@ -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<MessageModel>,
|
||||
doe: Pick<DeleteAttributesType, 'serverTimestamp'>
|
||||
): boolean {
|
||||
const messageTimestamp =
|
||||
message.get('serverTimestamp') || message.get('sent_at') || 0;
|
||||
const delta = Math.abs(doe.serverTimestamp - messageTimestamp);
|
||||
return delta > DAY * 2;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
14
ts/util/isTooOldToModifyMessage.ts
Normal file
14
ts/util/isTooOldToModifyMessage.ts
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue