From a12ed61cc1d09ebee1acffceca253eddbd3caba6 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 10 Jan 2019 11:45:07 +1100 Subject: [PATCH] Fix notification display after friend request is accepted. --- js/models/conversations.js | 1 + js/notifications.js | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index aa1412608..01f7e81f1 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -2165,6 +2165,7 @@ message: i18n(message, conversation.getTitle()), messageSentAt: Date.now(), title: i18n(title), + isFriendRequest: true, }); }, diff --git a/js/notifications.js b/js/notifications.js index 1fb70b76a..4a3d0bb59 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -86,12 +86,15 @@ let message; let iconUrl; + // The number of notifications excluding friend request + const messagesNotificationCount = this.models.filter(n => !n.get('isFriendRequest')).length; + // NOTE: i18n has more complex rules for pluralization than just // distinguishing between zero (0) and other (non-zero), // e.g. Russian: // http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html - const newMessageCountLabel = `${numNotifications} ${ - numNotifications === 1 ? i18n('newMessage') : i18n('newMessages') + const newMessageCountLabel = `${messagesNotificationCount} ${ + messagesNotificationCount === 1 ? i18n('newMessage') : i18n('newMessages') }`; const last = this.last().toJSON(); @@ -105,7 +108,7 @@ title = newMessageCountLabel; // eslint-disable-next-line prefer-destructuring iconUrl = last.iconUrl; - if (numNotifications === 1) { + if (last.isFriendRequest || messagesNotificationCount === 1) { message = `${i18n('notificationFrom')} ${lastMessageTitle}`; } else { message = `${i18n( @@ -115,7 +118,7 @@ break; } case SettingNames.MESSAGE: - if (numNotifications === 1) { + if (last.isFriendRequest || messagesNotificationCount === 1) { // eslint-disable-next-line prefer-destructuring title = last.title; // eslint-disable-next-line prefer-destructuring