Hide message contents in notifications for message requests

This commit is contained in:
Jamie Kyle 2023-04-10 15:19:48 -07:00 committed by GitHub
parent 822b162136
commit 3a069323a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 5 deletions

View file

@ -4475,6 +4475,10 @@
"messageformat": "Draft:", "messageformat": "Draft:",
"description": "Prefix shown in italic in conversation view when a draft is saved" "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--getNotificationText--gif": {
"message": "GIF", "message": "GIF",
"description": "(deleted 03/29/2023) Shown in notifications and in the left pane when a GIF is received." "description": "(deleted 03/29/2023) Shown in notifications and in the left pane when a GIF is received."

View file

@ -185,6 +185,7 @@ import * as Edits from '../messageModifiers/Edits';
import { handleEditMessage } from '../util/handleEditMessage'; import { handleEditMessage } from '../util/handleEditMessage';
import { getQuoteBodyText } from '../util/getQuoteBodyText'; import { getQuoteBodyText } from '../util/getQuoteBodyText';
import { shouldReplyNotifyUser } from '../util/shouldReplyNotifyUser'; import { shouldReplyNotifyUser } from '../util/shouldReplyNotifyUser';
import { isConversationAccepted } from '../util/isConversationAccepted';
import type { RawBodyRange } from '../types/BodyRange'; import type { RawBodyRange } from '../types/BodyRange';
import { BodyRange, applyRangesForText } from '../types/BodyRange'; import { BodyRange, applyRangesForText } from '../types/BodyRange';
@ -831,6 +832,17 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
const { text, emoji } = this.getNotificationData(); const { text, emoji } = this.getNotificationData();
const { attributes } = this; 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.storyReaction) {
if (attributes.type === 'outgoing') { if (attributes.type === 'outgoing') {
const name = this.getConversation()?.get('profileName'); const name = this.getConversation()?.get('profileName');

View file

@ -47,8 +47,11 @@ describe('Conversations', () => {
password: 'password', password: 'password',
}); });
await window.ConversationController.load(); await window.ConversationController.load();
await window.ConversationController.getOrCreateAndWait(
await window.Signal.Data.saveConversation(conversation.attributes); conversation.attributes.e164 ?? null,
conversation.attributes.type,
conversation.attributes
);
// Creating a fake message // Creating a fake message
const now = Date.now(); const now = Date.now();

View file

@ -588,9 +588,15 @@ describe('Message', () => {
}); });
describe('getNotificationText', () => { describe('getNotificationText', () => {
it("returns a notification's text", () => { it("returns a notification's text", async () => {
assert.strictEqual( assert.strictEqual(
createMessage({ createMessage({
conversationId: (
await window.ConversationController.getOrCreateAndWait(
UUID.generate().toString(),
'private'
)
).id,
type: 'incoming', type: 'incoming',
source, source,
body: 'hello world', 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', { this.sandbox.replace(window.Signal, 'OS', {
...window.Signal.OS, ...window.Signal.OS,
isLinux() { isLinux() {
@ -609,6 +615,12 @@ describe('Message', () => {
assert.strictEqual( assert.strictEqual(
createMessage({ createMessage({
conversationId: (
await window.ConversationController.getOrCreateAndWait(
UUID.generate().toString(),
'private'
)
).id,
type: 'incoming', type: 'incoming',
source, source,
attachments: [ 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', { this.sandbox.replace(window.Signal, 'OS', {
...window.Signal.OS, ...window.Signal.OS,
isLinux() { isLinux() {
@ -631,6 +643,12 @@ describe('Message', () => {
assert.strictEqual( assert.strictEqual(
createMessage({ createMessage({
conversationId: (
await window.ConversationController.getOrCreateAndWait(
UUID.generate().toString(),
'private'
)
).id,
type: 'incoming', type: 'incoming',
source, source,
attachments: [ attachments: [