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';
|
|
|
|
import { HOUR } from './durations';
|
|
|
|
import { canEditMessages } from './canEditMessages';
|
|
|
|
import { isMoreRecentThan } from './timestamp';
|
|
|
|
import { isOutgoing } from '../messages/helpers';
|
|
|
|
import { isSent, someSendStatus } from '../messages/MessageSendState';
|
|
|
|
|
|
|
|
const MAX_EDIT_COUNT = 10;
|
|
|
|
const THREE_HOURS = 3 * HOUR;
|
|
|
|
|
|
|
|
export function canEditMessage(message: MessageAttributesType): boolean {
|
2023-06-22 18:35:41 +00:00
|
|
|
const result =
|
2023-05-12 00:27:19 +00:00
|
|
|
canEditMessages() &&
|
|
|
|
!message.deletedForEveryone &&
|
|
|
|
isOutgoing(message) &&
|
|
|
|
isMoreRecentThan(message.sent_at, THREE_HOURS) &&
|
|
|
|
(message.editHistory?.length ?? 0) <= MAX_EDIT_COUNT &&
|
|
|
|
someSendStatus(message.sendStateByConversationId, isSent) &&
|
2023-06-22 18:35:41 +00:00
|
|
|
Boolean(message.body);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
message.conversationId ===
|
|
|
|
window.ConversationController.getOurConversationId()
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
canEditMessages() && !message.deletedForEveryone && Boolean(message.body)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2023-05-12 00:27:19 +00:00
|
|
|
}
|