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

[FIX] Allow inviting other agents to the same LiveChat room #9903

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2fb6d12
Fix livechat routes to allow inviting other agents to the same chat.
renatobecker Feb 26, 2018
41e7cbd
Fix indentation tabs.
renatobecker Feb 26, 2018
70f8833
Simplified livechat room names using 'fname' field
sampaiodiego Mar 6, 2018
a7f5dcf
Fix:
renatobecker Mar 8, 2018
2aa57c6
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker Mar 13, 2018
2f0c984
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 18, 2018
812d9be
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 18, 2018
e236808
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 21, 2018
4969872
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 21, 2018
4655798
Merge branch 'fix-invite-agents-to-livechat-rooms' of github.com:Rock…
renatobecker May 21, 2018
78561c4
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 22, 2018
4cdcf31
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 22, 2018
ee00b4f
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 22, 2018
7ea7954
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 23, 2018
d3aed15
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 24, 2018
78bc2ea
package version updated.
renatobecker May 24, 2018
897eca4
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 30, 2018
76a1267
Merge branch 'develop' into fix-invite-agents-to-livechat-rooms
renatobecker May 30, 2018
9bcefa5
Merge branch 'fix-invite-agents-to-livechat-rooms' of github.com:Rock…
renatobecker May 30, 2018
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
9 changes: 6 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -6,7 +6,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 });

Expand Down Expand Up @@ -354,13 +353,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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
msgStream.on(roomId, { token: this.getToken() }, (msg) => {
if (msg.t === 'command') {
Commands[msg.msg] && Commands[msg.msg]();
} else if (msg.t !== 'livechat_video_call') {
} else if ( (msg.t !== 'livechat_video_call') && (msg.t !== 'au') ) {
ChatMessage.upsert({ _id: msg._id }, msg);

if (msg.t === 'livechat-close') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Template.livechatCurrentChats.helpers({

Template.livechatCurrentChats.events({
'click .row-link'() {
FlowRouter.go('live', { code: this.code });
FlowRouter.go('live', { id: this._id });
},
'click .load-more'(event, instance) {
instance.limit.set(instance.limit.get() + 20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h2>{{_ "Past_Chats"}}</h2>
<div class="visitor-scroll">
<ul>
{{#each previousChats}}
<li><a href="{{pathFor "live" code=code}}">{{title}}</a></li>
<li><a href="{{pathFor "live" id=_id}}">{{title}}</a></li>
{{/each}}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Template.livechat.helpers({

return ChatSubscription.find(query, { sort: {
't': 1,
'name': 1
'fname': 1
}});
},

Expand Down
14 changes: 5 additions & 9 deletions packages/rocketchat-livechat/roomType.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ class LivechatRoomRoute extends RoomTypeRouteConfig {
constructor() {
super({
name: 'live',
path: '/live/:code(\\d+)'
path: '/live/:id'
});
}

action(params) {
openRoom('l', params.code);
openRoom('l', params.id);
}

link(sub) {
return {
code: sub.code
id: sub.rid
};
}
}
Expand All @@ -36,15 +36,11 @@ class LivechatRoomType extends RoomTypeConfig {
}

findRoom(identifier) {
return ChatRoom.findOne({code: parseInt(identifier)});
return ChatRoom.findOne({_id: identifier});
}

roomName(roomData) {
if (!roomData.name) {
return roomData.label;
} else {
return roomData.name;
}
return roomData.name || roomData.fname || roomData.label;
}

condition() {
Expand Down
4 changes: 1 addition & 3 deletions packages/rocketchat-livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,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 Expand Up @@ -351,7 +351,6 @@ RocketChat.Livechat = {
unread: 1,
userMentions: 1,
groupMentions: 0,
code: room.code,
u: {
_id: agent.agentId,
username: agent.username
Expand Down Expand Up @@ -412,7 +411,6 @@ RocketChat.Livechat = {
_id: room._id,
label: room.label,
topic: room.topic,
code: room.code,
createdAt: room.ts,
lastMessageAt: room.lm,
tags: room.tags,
Expand Down
16 changes: 7 additions & 9 deletions packages/rocketchat-livechat/server/lib/QueueMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ RocketChat.QueueMethods = {
}
}

const roomCode = RocketChat.models.Rooms.getNextLivechatRoomCode();
RocketChat.models.Rooms.updateLivechatRoomCount();

const room = _.extend({
_id: message.rid,
msgs: 1,
lm: new Date(),
code: roomCode,
label: guest.name || guest.username,
fname: (roomInfo && roomInfo.fname) || guest.name || guest.username,
// usernames: [agent.username, guest.username],
t: 'l',
ts: new Date(),
Expand All @@ -41,21 +40,21 @@ RocketChat.QueueMethods = {
}, roomInfo);
const subscriptionData = {
rid: message.rid,
name: guest.name || guest.username,
fname: guest.name || guest.username,
alert: true,
open: true,
unread: 1,
userMentions: 1,
groupMentions: 0,
code: roomCode,
u: {
_id: agent.agentId,
username: agent.username
},
t: 'l',
desktopNotifications: 'all',
mobilePushNotifications: 'all',
emailNotifications: 'all'
emailNotifications: 'all',
roles: ['owner']
};

RocketChat.models.Rooms.insert(room);
Expand Down Expand Up @@ -88,7 +87,7 @@ RocketChat.QueueMethods = {
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');
}

const roomCode = RocketChat.models.Rooms.getNextLivechatRoomCode();
RocketChat.models.Rooms.updateLivechatRoomCount();

const agentIds = [];

Expand All @@ -105,7 +104,6 @@ RocketChat.QueueMethods = {
message: message.msg,
name: guest.name || guest.username,
ts: new Date(),
code: roomCode,
department: guest.department,
agents: agentIds,
status: 'open',
Expand All @@ -121,8 +119,8 @@ RocketChat.QueueMethods = {
_id: message.rid,
msgs: 1,
lm: new Date(),
code: roomCode,
label: guest.name || guest.username,
fname: guest.name || guest.username,
// usernames: [guest.username],
t: 'l',
ts: new Date(),
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-livechat/server/methods/takeInquiry.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Meteor.methods({
unread: 1,
userMentions: 1,
groupMentions: 0,
code: inquiry.code,
u: {
_id: agent.agentId,
username: agent.username
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-livechat/server/methods/webhookTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Meteor.methods({
_id: 'fasd6f5a4sd6f8a4sdf',
label: 'title',
topic: 'asiodojf',
code: 123123,
createdAt: new Date(),
lastMessageAt: new Date(),
tags: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class LivechatInquiry extends RocketChat.models._Base {
this.tryEnsureIndex({ 'name': 1 }); // name of the inquiry (client name for now)
this.tryEnsureIndex({ 'message': 1 }); // message sent by the client
this.tryEnsureIndex({ 'ts': 1 }); // timestamp
this.tryEnsureIndex({ 'code': 1 }); // (for routing)
this.tryEnsureIndex({ 'agents': 1}); // Id's of the agents who can see the inquiry (handle departments)
this.tryEnsureIndex({ 'status': 1}); // 'open', 'taken'
}
Expand Down
16 changes: 3 additions & 13 deletions packages/rocketchat-livechat/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,16 @@ RocketChat.models.Rooms.findLivechat = function(filter = {}, offset = 0, limit =
return this.find(query, { sort: { ts: - 1 }, offset, limit });
};

RocketChat.models.Rooms.findLivechatByCode = function(code, fields) {
code = parseInt(code);

RocketChat.models.Rooms.findLivechatById = function(_id, fields) {
const options = {};

if (fields) {
options.fields = fields;
}

// if (this.useCache) {
// return this.cache.findByIndex('t,code', ['l', code], options).fetch();
// }

const query = {
t: 'l',
code
_id
};

return this.findOne(query, options);
Expand All @@ -73,7 +67,7 @@ RocketChat.models.Rooms.findLivechatByCode = function(code, fields) {
* Get the next visitor name
* @return {string} The next visitor name
*/
RocketChat.models.Rooms.getNextLivechatRoomCode = function() {
RocketChat.models.Rooms.updateLivechatRoomCount = function() {
const settingsRaw = RocketChat.models.Settings.model.rawCollection();
const findAndModify = Meteor.wrapAsync(settingsRaw.findAndModify, settingsRaw);

Expand Down Expand Up @@ -162,10 +156,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 });
});
4 changes: 2 additions & 2 deletions packages/rocketchat-livechat/server/startup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Meteor.startup(() => {
RocketChat.roomTypes.setRoomFind('l', (code) => {
return RocketChat.models.Rooms.findLivechatByCode(code);
RocketChat.roomTypes.setRoomFind('l', (_id) => {
return RocketChat.models.Rooms.findLivechatById(_id);
});

RocketChat.authz.addRoomAccessValidator(function(room, user) {
Expand Down
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
7 changes: 7 additions & 0 deletions server/startup/migrations/v123.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RocketChat.Migrations.add({
version: 123,
up() {
RocketChat.models.Subscriptions.tryDropIndex('u._id_1_name_1_t_1_code_1');
console.log('Fixing ChatSubscription u._id_1_name_1_t_1_code_1');
}
});