signal-desktop/ts/util/canEditMessage.ts

32 lines
892 B
TypeScript
Raw Normal View History

// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ReadonlyMessageAttributesType } from '../model-types.d';
import { DAY } from './durations';
import { isMoreRecentThan } from './timestamp';
import { isOutgoing } from '../messages/helpers';
2024-10-11 16:30:10 +00:00
import { isMessageNoteToSelf } from './isMessageNoteToSelf';
export const MESSAGE_MAX_EDIT_COUNT = 10;
export function canEditMessage(
message: ReadonlyMessageAttributesType
): boolean {
2024-10-11 16:30:10 +00:00
return (
!message.sms &&
!message.deletedForEveryone &&
isOutgoing(message) &&
2024-10-11 16:30:10 +00:00
(isMoreRecentThan(message.sent_at, DAY) || isMessageNoteToSelf(message)) &&
Boolean(message.body)
);
}
export function isWithinMaxEdits(
message: ReadonlyMessageAttributesType
): boolean {
2024-10-11 16:30:10 +00:00
return (
isMessageNoteToSelf(message) ||
(message.editHistory?.length ?? 0) <= MESSAGE_MAX_EDIT_COUNT
);
}