From fe8379826543a5421480c6cbc31dd43b60bc740e Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Mon, 26 Mar 2018 15:34:18 -0300 Subject: [PATCH 1/4] Fix desktop notifications when agent has not focussed the browser. --- .../rocketchat-lib/server/lib/sendNotificationsOnMessage.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index dab8e6de7fa0..c135a19c9b6b 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -164,9 +164,8 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { const pushUsernames = {}; - const user = RocketChat.models.Users.findOneById(message.u._id); - - // might be a livechat visitor + const user = (room.t !== 'l') ? RocketChat.models.Users.findOneById(message.u._id) : room.v; + if (!user) { return message; } From cabcddbb4fc052ba431de70aab2f124dd702ad69 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Mon, 26 Mar 2018 15:43:04 -0300 Subject: [PATCH 2/4] Fix trailing spaces. --- .../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 c135a19c9b6b..16c425a8a6dd 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -165,7 +165,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { const pushUsernames = {}; const user = (room.t !== 'l') ? RocketChat.models.Users.findOneById(message.u._id) : room.v; - + if (!user) { return message; } From 3e7e3fbf4f018a941efdbd6e5228bee3639deeb7 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Tue, 3 Apr 2018 16:40:31 -0300 Subject: [PATCH 3/4] Fix undefined room name in push and e-mail notifications when the agent goes offline. --- packages/rocketchat-lib/server/lib/roomTypes.js | 3 +++ packages/rocketchat-lib/server/lib/sendEmailOnMessage.js | 2 +- .../rocketchat-lib/server/lib/sendNotificationsOnMessage.js | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-lib/server/lib/roomTypes.js b/packages/rocketchat-lib/server/lib/roomTypes.js index 68aec9b5ef6f..e6ee83c8bf70 100644 --- a/packages/rocketchat-lib/server/lib/roomTypes.js +++ b/packages/rocketchat-lib/server/lib/roomTypes.js @@ -31,6 +31,9 @@ RocketChat.roomTypes = new class roomTypesServer extends RoomTypesCommon { return this.roomTypes[roomType] && this.roomTypes[roomType].roomFind; } + getRoomName(roomType, roomData) { + return this.roomTypes[roomType] && this.roomTypes[roomType].roomName && this.roomTypes[roomType].roomName(roomData); + } /** * Run the publish for a room type diff --git a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js index 779b1c57b888..49aacd0ec2f6 100644 --- a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js @@ -4,7 +4,7 @@ import s from 'underscore.string'; function getEmailContent({ messageContent, message, user, room }) { const lng = user && user.language || RocketChat.settings.get('language') || 'en'; - const roomName = `#${ RocketChat.settings.get('UI_Allow_room_names_with_special_chars') ? room.fname || room.name : room.name }`; + const roomName = `#${ (RocketChat.settings.get('UI_Allow_room_names_with_special_chars') && room.fname) ? room.fname : RocketChat.roomTypes.getRoomName(room.t, room) }`; const userName = RocketChat.settings.get('UI_Use_Real_Name') ? message.u.name || message.u.username : message.u.username; diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index 16c425a8a6dd..aae84c4e8589 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -265,7 +265,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { let push_room = ''; if (RocketChat.settings.get('Push_show_username_room')) { push_username = user.username; - push_room = `#${ room.name }`; + push_room = `#${ RocketChat.roomTypes.getRoomName(room.t, room) }`; } if (room.t == null || room.t === 'd') { From c325b94777997646416cb93a7d76b8e17d2036d4 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Thu, 26 Apr 2018 12:47:01 -0300 Subject: [PATCH 4/4] Changed use of the getRoomName method. --- packages/rocketchat-lib/server/lib/sendEmailOnMessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js index 359ba7c47aaa..54ed551adadc 100644 --- a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js @@ -4,7 +4,7 @@ import s from 'underscore.string'; function getEmailContent({ messageContent, message, user, room }) { const lng = user && user.language || RocketChat.settings.get('language') || 'en'; - const roomName = `#${ (RocketChat.settings.get('UI_Allow_room_names_with_special_chars') && room.fname) ? room.fname : RocketChat.roomTypes.getRoomName(room.t, room) }`; + const roomName = `#${ RocketChat.roomTypes.getRoomName(room.t, room) }`; const userName = RocketChat.settings.get('UI_Use_Real_Name') ? message.u.name || message.u.username : message.u.username;