Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move room display name logic to roomType definition #6585

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/rocketchat-lib/client/lib/roomTypes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions packages/rocketchat-lib/startup/defaultRoomTypes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* globals openRoom */

RocketChat.roomTypes.add(null, 0, {
template: 'starredRooms',
icon: 'icon-star'
Expand All @@ -25,7 +24,7 @@ RocketChat.roomTypes.add('c', 10, {
},

roomName(roomData) {
return { name: roomData.name };
return roomData.name;
},

condition() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -99,7 +113,7 @@ RocketChat.roomTypes.add('p', 30, {
},

roomName(roomData) {
return { name: roomData.name };
return roomData.name;
},

condition() {
Expand Down
8 changes: 3 additions & 5 deletions packages/rocketchat-ui/client/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down