[IMPROVE] Allow transfer Livechats to online agents only (#13008)

* Improvement in the filter of the list of agents online, which will allow the transfer of Livechat only to agents online.
pull/13011/head
Renato Becker 7 years ago committed by Diego Sampaio
parent cfb5f3e4fe
commit 4b42295fc7
  1. 8
      packages/rocketchat-livechat/client/views/app/tabbar/visitorForward.js
  2. 12
      packages/rocketchat-livechat/server/lib/Livechat.js
  3. 18
      packages/rocketchat-livechat/server/models/Users.js

@ -19,7 +19,13 @@ Template.visitorForward.helpers({
return LivechatDepartment.find({ enabled: true });
},
agents() {
return AgentUsers.find({ _id: { $ne: Meteor.userId() } }, { sort: { name: 1, username: 1 } });
const query = {
_id: { $ne: Meteor.userId() },
status: { $ne: 'offline' },
statusLivechat: 'available',
};
return AgentUsers.find(query, { sort: { name: 1, username: 1 } });
},
agentName() {
return this.name || this.username;

@ -439,11 +439,13 @@ RocketChat.Livechat = {
let agent;
if (transferData.userId) {
const user = RocketChat.models.Users.findOneById(transferData.userId);
agent = {
agentId: user._id,
username: user.username,
};
const user = RocketChat.models.Users.findOneOnlineAgentById(transferData.userId);
if (!user) {
return false;
}
const { _id: agentId, username } = user;
agent = Object.assign({}, { agentId, username });
} else if (RocketChat.settings.get('Livechat_Routing_Method') !== 'Guest_Pool') {
agent = RocketChat.Livechat.getNextAgent(transferData.departmentId);
} else {

@ -51,6 +51,24 @@ RocketChat.models.Users.findOneOnlineAgentByUsername = function(username) {
return this.findOne(query);
};
/**
* Find an online agent by its user Id
* @return
*/
RocketChat.models.Users.findOneOnlineAgentById = function(_id) {
const query = {
_id,
status: {
$exists: true,
$ne: 'offline',
},
statusLivechat: 'available',
roles: 'livechat-agent',
};
return this.findOne(query);
};
/**
* Gets all agents
* @return

Loading…
Cancel
Save