From 07845340dc800d981fcc4ff20415498dece20b1b Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Tue, 3 Sep 2024 21:58:39 -0500 Subject: [PATCH] Prevent interaction with non-Signal messages restored from backup Co-authored-by: Scott Nonnenberg --- ts/state/selectors/message.ts | 15 ++++++++++++++- ts/util/canEditMessage.ts | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ts/state/selectors/message.ts b/ts/state/selectors/message.ts index 02711416e103..a375c958829c 100644 --- a/ts/state/selectors/message.ts +++ b/ts/state/selectors/message.ts @@ -1892,6 +1892,7 @@ function canReplyOrReact( | 'deletedForEveryone' | 'payment' | 'sendStateByConversationId' + | 'sms' | 'type' >, ourConversationId: string | undefined, @@ -1930,6 +1931,10 @@ function canReplyOrReact( return false; } + if (message.sms) { + return false; + } + if (isOutgoing(message)) { return ( isMessageJustForMe(sendStateByConversationId ?? {}, ourConversationId) || @@ -1964,6 +1969,7 @@ export function canReply( | 'conversationId' | 'deletedForEveryone' | 'sendStateByConversationId' + | 'sms' | 'type' >, ourConversationId: string | undefined, @@ -1985,6 +1991,7 @@ export function canReact( | 'conversationId' | 'deletedForEveryone' | 'sendStateByConversationId' + | 'sms' | 'type' >, ourConversationId: string | undefined, @@ -2003,11 +2010,17 @@ export function canCopy( export function canDeleteForEveryone( message: Pick< MessageWithUIFieldsType, - 'type' | 'deletedForEveryone' | 'sent_at' | 'sendStateByConversationId' + | 'type' + | 'deletedForEveryone' + | 'sent_at' + | 'sendStateByConversationId' + | 'sms' >, isMe: boolean ): boolean { return ( + // Is this an SMS restored from backup? + !message.sms && // Is this a message I sent? isOutgoing(message) && // Has the message already been deleted? diff --git a/ts/util/canEditMessage.ts b/ts/util/canEditMessage.ts index 47137f9fd222..b6ecd5e2de84 100644 --- a/ts/util/canEditMessage.ts +++ b/ts/util/canEditMessage.ts @@ -11,6 +11,10 @@ export const MESSAGE_MAX_EDIT_COUNT = 10; export function canEditMessage( message: ReadonlyMessageAttributesType ): boolean { + if (message.sms) { + return false; + } + const result = !message.deletedForEveryone && isOutgoing(message) &&