Lets you edit note to self indefinitely

This commit is contained in:
Josh Perez 2023-06-22 14:35:41 -04:00 committed by GitHub
parent 9c869148ef
commit 8410f95368
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View file

@ -12,13 +12,27 @@ const MAX_EDIT_COUNT = 10;
const THREE_HOURS = 3 * HOUR;
export function canEditMessage(message: MessageAttributesType): boolean {
return (
const result =
canEditMessages() &&
!message.deletedForEveryone &&
isOutgoing(message) &&
isMoreRecentThan(message.sent_at, THREE_HOURS) &&
(message.editHistory?.length ?? 0) <= MAX_EDIT_COUNT &&
someSendStatus(message.sendStateByConversationId, isSent) &&
Boolean(message.body)
);
Boolean(message.body);
if (result) {
return true;
}
if (
message.conversationId ===
window.ConversationController.getOurConversationId()
) {
return (
canEditMessages() && !message.deletedForEveryone && Boolean(message.body)
);
}
return false;
}

View file

@ -9,6 +9,7 @@ import type {
QuotedMessageType,
} from '../model-types.d';
import type { LinkPreviewType } from '../types/message/LinkPreviews';
import * as durations from './durations';
import * as log from '../logging/log';
import { ReadStatus } from '../messages/MessageReadStatus';
import dataInterface from '../sql/Client';
@ -17,6 +18,7 @@ import { getAttachmentSignature, isVoiceMessage } from '../types/Attachment';
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 { queueAttachmentDownloads } from './queueAttachmentDownloads';
import { shouldReplyNotifyUser } from './shouldReplyNotifyUser';
@ -49,6 +51,19 @@ export async function handleEditMessage(
return;
}
const { serverTimestamp } = editAttributes.message;
const isNoteToSelf =
mainMessage.conversationId ===
window.ConversationController.getOurConversationId();
if (
serverTimestamp &&
!isNoteToSelf &&
isOlderThan(serverTimestamp, durations.DAY)
) {
log.warn(`${idLog}: cannot edit message older than 24h`, serverTimestamp);
return;
}
const mainMessageModel = window.MessageController.register(
mainMessage.id,
mainMessage