From fb91394d4ffdaca75f22bd814da242391fcb3cb8 Mon Sep 17 00:00:00 2001 From: Samar Sunkaria Date: Fri, 13 Apr 2018 22:12:15 +0530 Subject: [PATCH 1/3] Improved notification formatting --- .../server/lib/sendNotificationsOnMessage.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index dab8e6de7fa03..a2fc891df732e 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -63,13 +63,24 @@ function notifyDesktopUser(userId, user, message, room, duration) { if (UI_Use_Real_Name) { message.msg = replaceMentionedUsernamesWithFullNames(message.msg, message.mentions); } - let title = UI_Use_Real_Name ? user.name : `@${ user.username }`; - if (room.t !== 'd' && room.name) { - title += ` @ #${ room.name }`; + + let title = '' + let text = '' + if (room.t == 'd') { + title = UI_Use_Real_Name ? user.name : `@${ user.username }`; + text = message.msg; + } else if (room.name) { + title = `#${ room.name }`; + text = `@${ user.username }: ${ message.msg }`; + } + + if (title == '' || text == '') { + return } + RocketChat.Notifications.notifyUser(userId, 'notification', { title, - text: message.msg, + text, duration, payload: { _id: message._id, From b2775390073bee70da0c672a7bd2fe5c24fd1e30 Mon Sep 17 00:00:00 2001 From: Samar Sunkaria Date: Fri, 13 Apr 2018 22:26:12 +0530 Subject: [PATCH 2/3] Fixed lint issues --- .../server/lib/sendNotificationsOnMessage.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index a2fc891df732e..7a0f596d77f97 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -64,9 +64,9 @@ function notifyDesktopUser(userId, user, message, room, duration) { message.msg = replaceMentionedUsernamesWithFullNames(message.msg, message.mentions); } - let title = '' - let text = '' - if (room.t == 'd') { + let title = ''; + let text = ''; + if (room.t === 'd') { title = UI_Use_Real_Name ? user.name : `@${ user.username }`; text = message.msg; } else if (room.name) { @@ -74,8 +74,8 @@ function notifyDesktopUser(userId, user, message, room, duration) { text = `@${ user.username }: ${ message.msg }`; } - if (title == '' || text == '') { - return + if (title === '' || text === '') { + return; } RocketChat.Notifications.notifyUser(userId, 'notification', { From ee0d5a9f86bc37bb935b9a5ec2d7ea5fe9d622ba Mon Sep 17 00:00:00 2001 From: Samar Sunkaria Date: Sat, 14 Apr 2018 01:06:12 +0530 Subject: [PATCH 3/3] Changed body format --- .../rocketchat-lib/server/lib/sendNotificationsOnMessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index 7a0f596d77f97..84b3dfb7b1c84 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -71,7 +71,7 @@ function notifyDesktopUser(userId, user, message, room, duration) { text = message.msg; } else if (room.name) { title = `#${ room.name }`; - text = `@${ user.username }: ${ message.msg }`; + text = `${ user.username }: ${ message.msg }`; } if (title === '' || text === '') {