2023-05-12 00:27:19 +00:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { MessageAttributesType } from '../model-types.d';
|
2023-08-25 13:50:04 +00:00
|
|
|
import { DAY } from './durations';
|
2023-05-12 00:27:19 +00:00
|
|
|
import { isMoreRecentThan } from './timestamp';
|
|
|
|
import { isOutgoing } from '../messages/helpers';
|
|
|
|
|
2023-11-08 01:55:48 +00:00
|
|
|
export const MESSAGE_MAX_EDIT_COUNT = 10;
|
2023-05-12 00:27:19 +00:00
|
|
|
|
|
|
|
export function canEditMessage(message: MessageAttributesType): boolean {
|
2023-06-22 18:35:41 +00:00
|
|
|
const result =
|
2023-05-12 00:27:19 +00:00
|
|
|
!message.deletedForEveryone &&
|
|
|
|
isOutgoing(message) &&
|
2023-08-25 13:50:04 +00:00
|
|
|
isMoreRecentThan(message.sent_at, DAY) &&
|
2023-06-22 18:35:41 +00:00
|
|
|
Boolean(message.body);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
message.conversationId ===
|
|
|
|
window.ConversationController.getOurConversationId()
|
|
|
|
) {
|
2023-12-07 23:59:54 +00:00
|
|
|
return !message.deletedForEveryone && Boolean(message.body);
|
2023-06-22 18:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2023-05-12 00:27:19 +00:00
|
|
|
}
|
2023-11-08 01:55:48 +00:00
|
|
|
|
|
|
|
export function isWithinMaxEdits(message: MessageAttributesType): boolean {
|
|
|
|
return (message.editHistory?.length ?? 0) <= MESSAGE_MAX_EDIT_COUNT;
|
|
|
|
}
|