Skip to content

Commit

Permalink
Simplified livechat room names using 'fname' field
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Mar 6, 2018
1 parent 41e7cbd commit 70f8833
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 27 deletions.
5 changes: 2 additions & 3 deletions packages/rocketchat-lib/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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
}
};

Expand Down
6 changes: 1 addition & 5 deletions packages/rocketchat-livechat/roomType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},

Expand Down
8 changes: 3 additions & 5 deletions packages/rocketchat-livechat/server/lib/QueueMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -57,7 +54,8 @@ RocketChat.QueueMethods = {
t: 'l',
desktopNotifications: 'all',
mobilePushNotifications: 'all',
emailNotifications: 'all'
emailNotifications: 'all',
roles: ['owner']
};

RocketChat.models.Rooms.insert(room);
Expand Down
4 changes: 0 additions & 4 deletions packages/rocketchat-livechat/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-livechat/server/models/indexes.js
Original file line number Diff line number Diff line change
@@ -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 });
});
9 changes: 1 addition & 8 deletions packages/rocketchat-ui-sidenav/client/chatRoomItem.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 70f8833

Please sign in to comment.