From 3a069323a488c7e4497b7b6e0f958212cff66756 Mon Sep 17 00:00:00 2001 From: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com> Date: Mon, 10 Apr 2023 15:19:48 -0700 Subject: [PATCH] Hide message contents in notifications for message requests --- _locales/en/messages.json | 4 ++++ ts/models/messages.ts | 12 ++++++++++ ts/test-electron/models/conversations_test.ts | 7 ++++-- ts/test-electron/models/messages_test.ts | 24 ++++++++++++++++--- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e88fedb02052..913bebb8000d 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -4475,6 +4475,10 @@ "messageformat": "Draft:", "description": "Prefix shown in italic in conversation view when a draft is saved" }, + "icu:message--getNotificationText--messageRequest": { + "messageformat": "Message Request", + "description": "Shown in notifications and in the left pane when a message request is received." + }, "message--getNotificationText--gif": { "message": "GIF", "description": "(deleted 03/29/2023) Shown in notifications and in the left pane when a GIF is received." diff --git a/ts/models/messages.ts b/ts/models/messages.ts index a84bce0e2d5e..0604eb3c4f37 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -185,6 +185,7 @@ import * as Edits from '../messageModifiers/Edits'; import { handleEditMessage } from '../util/handleEditMessage'; import { getQuoteBodyText } from '../util/getQuoteBodyText'; import { shouldReplyNotifyUser } from '../util/shouldReplyNotifyUser'; +import { isConversationAccepted } from '../util/isConversationAccepted'; import type { RawBodyRange } from '../types/BodyRange'; import { BodyRange, applyRangesForText } from '../types/BodyRange'; @@ -831,6 +832,17 @@ export class MessageModel extends window.Backbone.Model { const { text, emoji } = this.getNotificationData(); const { attributes } = this; + const conversation = this.getConversation(); + + strictAssert( + conversation != null, + 'Conversation not found in ConversationController' + ); + + if (!isConversationAccepted(conversation.attributes)) { + return window.i18n('icu:message--getNotificationText--messageRequest'); + } + if (attributes.storyReaction) { if (attributes.type === 'outgoing') { const name = this.getConversation()?.get('profileName'); diff --git a/ts/test-electron/models/conversations_test.ts b/ts/test-electron/models/conversations_test.ts index 59fb8a8ae604..23b87b618987 100644 --- a/ts/test-electron/models/conversations_test.ts +++ b/ts/test-electron/models/conversations_test.ts @@ -47,8 +47,11 @@ describe('Conversations', () => { password: 'password', }); await window.ConversationController.load(); - - await window.Signal.Data.saveConversation(conversation.attributes); + await window.ConversationController.getOrCreateAndWait( + conversation.attributes.e164 ?? null, + conversation.attributes.type, + conversation.attributes + ); // Creating a fake message const now = Date.now(); diff --git a/ts/test-electron/models/messages_test.ts b/ts/test-electron/models/messages_test.ts index c228dbd89a79..81273d6bb42b 100644 --- a/ts/test-electron/models/messages_test.ts +++ b/ts/test-electron/models/messages_test.ts @@ -588,9 +588,15 @@ describe('Message', () => { }); describe('getNotificationText', () => { - it("returns a notification's text", () => { + it("returns a notification's text", async () => { assert.strictEqual( createMessage({ + conversationId: ( + await window.ConversationController.getOrCreateAndWait( + UUID.generate().toString(), + 'private' + ) + ).id, type: 'incoming', source, body: 'hello world', @@ -599,7 +605,7 @@ describe('Message', () => { ); }); - it("shows a notification's emoji on non-Linux", function test() { + it("shows a notification's emoji on non-Linux", async function test() { this.sandbox.replace(window.Signal, 'OS', { ...window.Signal.OS, isLinux() { @@ -609,6 +615,12 @@ describe('Message', () => { assert.strictEqual( createMessage({ + conversationId: ( + await window.ConversationController.getOrCreateAndWait( + UUID.generate().toString(), + 'private' + ) + ).id, type: 'incoming', source, attachments: [ @@ -621,7 +633,7 @@ describe('Message', () => { ); }); - it('hides emoji on Linux', function test() { + it('hides emoji on Linux', async function test() { this.sandbox.replace(window.Signal, 'OS', { ...window.Signal.OS, isLinux() { @@ -631,6 +643,12 @@ describe('Message', () => { assert.strictEqual( createMessage({ + conversationId: ( + await window.ConversationController.getOrCreateAndWait( + UUID.generate().toString(), + 'private' + ) + ).id, type: 'incoming', source, attachments: [