From 70f8833d4f122a3dd14c9252aa9728721cf487ce Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 6 Mar 2018 19:18:29 -0300 Subject: [PATCH] Simplified livechat room names using 'fname' field --- packages/rocketchat-lib/server/models/Subscriptions.js | 5 ++--- packages/rocketchat-livechat/roomType.js | 6 +----- packages/rocketchat-livechat/server/lib/Livechat.js | 2 +- packages/rocketchat-livechat/server/lib/QueueMethods.js | 8 +++----- packages/rocketchat-livechat/server/models/Rooms.js | 4 ---- packages/rocketchat-livechat/server/models/indexes.js | 1 - packages/rocketchat-ui-sidenav/client/chatRoomItem.js | 9 +-------- 7 files changed, 8 insertions(+), 27 deletions(-) diff --git a/packages/rocketchat-lib/server/models/Subscriptions.js b/packages/rocketchat-lib/server/models/Subscriptions.js index 726a0b4299c2..534c045fa837 100644 --- a/packages/rocketchat-lib/server/models/Subscriptions.js +++ b/packages/rocketchat-lib/server/models/Subscriptions.js @@ -8,7 +8,6 @@ class ModelSubscriptions extends RocketChat.models._Base { this.tryEnsureIndex({ 'rid': 1, 'alert': 1, 'u._id': 1 }); this.tryEnsureIndex({ 'rid': 1, 'roles': 1 }); this.tryEnsureIndex({ 'u._id': 1, 'name': 1, 't': 1 }); - this.tryEnsureIndex({ 'u._id': 1, 'name': 1, 't': 1, 'code': 1 }, { unique: 1 }); this.tryEnsureIndex({ 'open': 1 }); this.tryEnsureIndex({ 'alert': 1 }); this.tryEnsureIndex({ 'unread': 1 }); @@ -341,13 +340,13 @@ class ModelSubscriptions extends RocketChat.models._Base { return this.update(query, update, { multi: true }); } - updateNameByRoomId(roomId, name) { + updateDisplayNameByRoomId(roomId, fname) { const query = {rid: roomId}; const update = { $set: { - name + fname } }; diff --git a/packages/rocketchat-livechat/roomType.js b/packages/rocketchat-livechat/roomType.js index 94bfe76897c0..a33231c19acf 100644 --- a/packages/rocketchat-livechat/roomType.js +++ b/packages/rocketchat-livechat/roomType.js @@ -40,11 +40,7 @@ class LivechatRoomType extends RoomTypeConfig { } roomName(roomData) { - if (!roomData.name) { - return roomData.label; - } else { - return roomData.name; - } + return roomData.name || roomData.fname || roomData.label; } condition() { diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index 99079cb7f6b9..56468c23d2f3 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -293,7 +293,7 @@ RocketChat.Livechat = { }); if (!_.isEmpty(guestData.name)) { - return RocketChat.models.Rooms.setLabelByRoomId(roomData._id, guestData.name) && RocketChat.models.Subscriptions.updateNameByRoomId(roomData._id, guestData.name); + return RocketChat.models.Rooms.setNameById(roomData._id, roomData.name, guestData.name) && RocketChat.models.Subscriptions.updateDisplayNameByRoomId(roomData._id, guestData.name); } }, diff --git a/packages/rocketchat-livechat/server/lib/QueueMethods.js b/packages/rocketchat-livechat/server/lib/QueueMethods.js index 0b5d204fbe97..0e03384d48c4 100644 --- a/packages/rocketchat-livechat/server/lib/QueueMethods.js +++ b/packages/rocketchat-livechat/server/lib/QueueMethods.js @@ -20,9 +20,6 @@ RocketChat.QueueMethods = { _id: message.rid, msgs: 1, lm: new Date(), - code: roomCode, - label: guest.name || guest.username, - name: (roomInfo && roomInfo.name) || guest.name || guest.username, fname: (roomInfo && roomInfo.fname) || guest.name || guest.username, // usernames: [agent.username, guest.username], t: 'l', @@ -43,7 +40,7 @@ RocketChat.QueueMethods = { }, roomInfo); const subscriptionData = { rid: message.rid, - name: guest.name || guest.username, + fname: guest.name || guest.username, alert: true, open: true, unread: 1, @@ -57,7 +54,8 @@ RocketChat.QueueMethods = { t: 'l', desktopNotifications: 'all', mobilePushNotifications: 'all', - emailNotifications: 'all' + emailNotifications: 'all', + roles: ['owner'] }; RocketChat.models.Rooms.insert(room); diff --git a/packages/rocketchat-livechat/server/models/Rooms.js b/packages/rocketchat-livechat/server/models/Rooms.js index 43c438c8540c..a6aa56f7749a 100644 --- a/packages/rocketchat-livechat/server/models/Rooms.js +++ b/packages/rocketchat-livechat/server/models/Rooms.js @@ -177,10 +177,6 @@ RocketChat.models.Rooms.closeByRoomId = function(roomId, closeInfo) { }); }; -RocketChat.models.Rooms.setLabelByRoomId = function(roomId, label) { - return this.update({ _id: roomId }, { $set: { label } }); -}; - RocketChat.models.Rooms.findOpenByAgent = function(userId) { const query = { open: true, diff --git a/packages/rocketchat-livechat/server/models/indexes.js b/packages/rocketchat-livechat/server/models/indexes.js index 6dbd49633926..1cd8fe3daf9f 100644 --- a/packages/rocketchat-livechat/server/models/indexes.js +++ b/packages/rocketchat-livechat/server/models/indexes.js @@ -1,5 +1,4 @@ Meteor.startup(function() { - RocketChat.models.Rooms.tryEnsureIndex({ code: 1 }); RocketChat.models.Rooms.tryEnsureIndex({ open: 1 }, { sparse: 1 }); RocketChat.models.Users.tryEnsureIndex({ 'visitorEmails.address': 1 }); }); diff --git a/packages/rocketchat-ui-sidenav/client/chatRoomItem.js b/packages/rocketchat-ui-sidenav/client/chatRoomItem.js index 50f22bdc25e2..3aa77d6005cd 100644 --- a/packages/rocketchat-ui-sidenav/client/chatRoomItem.js +++ b/packages/rocketchat-ui-sidenav/client/chatRoomItem.js @@ -1,12 +1,5 @@ Template.chatRoomItem.helpers({ roomData() { - let {name} = this; - const realNameForDirectMessages = RocketChat.settings.get('UI_Use_Real_Name') && this.t === 'd'; - const realNameForChannel = RocketChat.settings.get('UI_Allow_room_names_with_special_chars') && this.t !== 'd'; - if ((realNameForDirectMessages || realNameForChannel) && this.fname) { - name = this.fname; - } - let unread = false; if (((FlowRouter.getParam('_id') !== this.rid) || !document.hasFocus()) && (this.unread > 0)) { unread = this.unread; @@ -30,7 +23,7 @@ Template.chatRoomItem.helpers({ avatar, username : this.name, route: RocketChat.roomTypes.getRouteLink(this.t, this), - name, + name: RocketChat.roomTypes.getRoomName(this.t, this), unread, active, archivedClass,