Fix closing livechat inquiry

Closes #8399
pull/9164/head
Diego Sampaio 8 years ago
parent 1ba24fe371
commit 4be01c439d
No known key found for this signature in database
GPG Key ID: E060152B30502562
  1. 27
      packages/rocketchat-livechat/server/lib/Livechat.js
  2. 6
      packages/rocketchat-livechat/server/methods/closeRoom.js
  3. 19
      packages/rocketchat-livechat/server/models/LivechatInquiry.js

@ -203,14 +203,18 @@ RocketChat.Livechat = {
closeRoom({ user, room, comment }) {
const now = new Date();
RocketChat.models.Rooms.closeByRoomId(room._id, {
const closeData = {
user: {
_id: user._id,
username: user.username
},
closedAt: now,
chatDuration: (now.getTime() - room.ts) / 1000
});
};
RocketChat.models.Rooms.closeByRoomId(room._id, closeData);
RocketChat.models.LivechatInquiry.closeByRoomId(room._id, closeData);
const message = {
t: 'livechat-close',
@ -373,7 +377,7 @@ RocketChat.Livechat = {
getLivechatRoomGuestInfo(room) {
const visitor = RocketChat.models.Users.findOneById(room.v._id);
const agent = RocketChat.models.Users.findOneById(room.servedBy._id);
const agent = RocketChat.models.Users.findOneById(room.servedBy && room.servedBy._id);
const ua = new UAParser();
ua.setUA(visitor.userAgent);
@ -398,14 +402,21 @@ RocketChat.Livechat = {
os: ua.getOS().name && (`${ ua.getOS().name } ${ ua.getOS().version }`),
browser: ua.getBrowser().name && (`${ ua.getBrowser().name } ${ ua.getBrowser().version }`),
customFields: visitor.livechatData
},
agent: {
}
};
if (agent) {
postData.agent = {
_id: agent._id,
username: agent.username,
name: agent.name,
email: null
};
if (agent.emails && agent.emails.length > 0) {
postData.agent.email = agent.emails[0].address;
}
};
}
if (room.crmData) {
postData.crmData = room.crmData;
@ -418,10 +429,6 @@ RocketChat.Livechat = {
postData.visitor.phone = visitor.phone[0].phoneNumber;
}
if (agent.emails && agent.emails.length > 0) {
postData.agent.email = agent.emails[0].address;
}
return postData;
},

@ -6,9 +6,13 @@ Meteor.methods({
const room = RocketChat.models.Rooms.findOneById(roomId);
if (!room || room.t !== 'l') {
throw new Meteor.Error('room-not-found', 'Room not found', { method: 'livechat:closeRoom' });
}
const user = Meteor.user();
if (room.usernames.indexOf(user.username) === -1 && !RocketChat.authz.hasPermission(Meteor.userId(), 'close-others-livechat-room')) {
if ((!room.usernames || room.usernames.indexOf(user.username) === -1) && !RocketChat.authz.hasPermission(Meteor.userId(), 'close-others-livechat-room')) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'livechat:closeRoom' });
}

@ -26,6 +26,25 @@ class LivechatInquiry extends RocketChat.models._Base {
});
}
/*
* mark the inquiry as closed
*/
closeByRoomId(roomId, closeInfo) {
return this.update({
rid: roomId
}, {
$set: {
status: 'closed',
closedBy: {
_id: closeInfo.user._id,
username: closeInfo.user.username
},
closedAt: closeInfo.closedAt,
chatDuration: closeInfo.chatDuration
}
});
}
/*
* mark inquiry as open
*/

Loading…
Cancel
Save