From dfae580ffa0dc6e34536403e0a4082d2cca67ebd Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 15 Nov 2018 11:13:55 +1100 Subject: [PATCH] Added notification when receiving a friend request and when a friend request was accepted. --- js/models/conversations.js | 30 ++++++++++++++++++++++-------- js/models/messages.js | 1 + 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 34384145a..ee8382a99 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -487,6 +487,20 @@ } await this.updatePendingFriendRequests(); + + this.getNotificationIcon().then(iconUrl => { + window.log.info('Add notification for friend request updated', { + conversationId: this.idForLogging(), + }); + Whisper.Notifications.add({ + conversationId: this.id, + iconUrl, + isExpiringMessage: false, + message: `Accepted your friend request`, + messageSentAt: Date.now(), + title: this.getTitle(), + }); + }); }, async onFriendRequestTimedOut() { this.updateTextInputState(); @@ -755,14 +769,14 @@ const id = await window.Signal.Data.saveMessage(message, { Message: Whisper.Message, }); + + const whisperMessage = new Whisper.Message({ + ...message, + id, + }); - this.trigger( - 'newmessage', - new Whisper.Message({ - ...message, - id, - }) - ); + this.trigger('newmessage', whisperMessage); + this.notify(whisperMessage); }, async addVerifiedChange(verifiedChangeId, verified, providedOptions) { const options = providedOptions || {}; @@ -2027,7 +2041,7 @@ }, notify(message) { - if (!message.isIncoming()) { + if (!(message.isIncoming() || message.isFriendRequest())) { return Promise.resolve(); } const conversationId = this.id; diff --git a/js/models/messages.js b/js/models/messages.js index a12e78cb0..bce16382f 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -192,6 +192,7 @@ getNotificationText() { const description = this.getDescription(); if (description) { + if (this.isFriendRequest()) return `Friend Request: ${description}`; return description; } if (this.get('attachments').length > 0) {