diff --git a/packages/rocketchat-lib/client/lib/roomTypes.coffee b/packages/rocketchat-lib/client/lib/roomTypes.coffee index 424636cd38a2..afe19195bf91 100644 --- a/packages/rocketchat-lib/client/lib/roomTypes.coffee +++ b/packages/rocketchat-lib/client/lib/roomTypes.coffee @@ -16,6 +16,9 @@ RocketChat.roomTypes = new class roomTypesClient extends roomTypesCommon getRoomName: (roomType, roomData) -> return @roomTypes[roomType]?.roomName roomData + getSecondaryRoomName: (roomType, roomData) -> + return @roomTypes[roomType]?.secondaryRoomName?(roomData) + getIdentifiers: (except) -> except = [].concat except list = _.reject @roomTypesOrder, (t) -> return except.indexOf(t.identifier) isnt -1 diff --git a/packages/rocketchat-lib/startup/defaultRoomTypes.js b/packages/rocketchat-lib/startup/defaultRoomTypes.js index 400c31fc6924..a647e19a3c7a 100644 --- a/packages/rocketchat-lib/startup/defaultRoomTypes.js +++ b/packages/rocketchat-lib/startup/defaultRoomTypes.js @@ -1,5 +1,4 @@ /* globals openRoom */ - RocketChat.roomTypes.add(null, 0, { template: 'starredRooms', icon: 'icon-star' @@ -25,7 +24,7 @@ RocketChat.roomTypes.add('c', 10, { }, roomName(roomData) { - return { name: roomData.name }; + return roomData.name; }, condition() { @@ -64,7 +63,22 @@ RocketChat.roomTypes.add('d', 20, { }, roomName(roomData) { - return ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1, fname: 1 } }); + const subscription = ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1, fname: 1 } }); + if (!subscription) { + return ''; + } + if (RocketChat.settings.get('UI_Use_Real_Name') && subscription.fname) { + return subscription.fname; + } + + return subscription.name; + }, + + secondaryRoomName(roomData) { + if (RocketChat.settings.get('UI_Use_Real_Name')) { + const subscription = ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1 } }); + return subscription && subscription.name; + } }, condition() { @@ -99,7 +113,7 @@ RocketChat.roomTypes.add('p', 30, { }, roomName(roomData) { - return { name: roomData.name }; + return roomData.name; }, condition() { diff --git a/packages/rocketchat-ui/client/views/app/room.coffee b/packages/rocketchat-ui/client/views/app/room.coffee index 9dbaa39dfdb1..08ff9aab5055 100644 --- a/packages/rocketchat-ui/client/views/app/room.coffee +++ b/packages/rocketchat-ui/client/views/app/room.coffee @@ -83,15 +83,13 @@ Template.room.helpers roomData = Session.get('roomData' + this._id) return '' unless roomData - room = RocketChat.roomTypes.getRoomName roomData?.t, roomData - return room.fname if RocketChat.settings.get('UI_Use_Real_Name') and room.fname - return room.name + return RocketChat.roomTypes.getRoomName roomData.t, roomData secondaryName: -> roomData = Session.get('roomData' + this._id) - return '' unless roomData and RocketChat.settings.get('UI_Use_Real_Name') and roomData.t is 'd' + return '' unless roomData - return RocketChat.roomTypes.getRoomName(roomData.t, roomData).name + return RocketChat.roomTypes.getSecondaryRoomName roomData.t, roomData roomTopic: -> roomData = Session.get('roomData' + this._id)