|
|
|
@ -50,8 +50,8 @@ class LivechatDepartment extends RocketChat.models._Base { |
|
|
|
|
agentId: agent.agentId, |
|
|
|
|
departmentId: _id, |
|
|
|
|
username: agent.username, |
|
|
|
|
count: agent.count, |
|
|
|
|
order: agent.order |
|
|
|
|
count: parseInt(agent.count), |
|
|
|
|
order: parseInt(agent.order) |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -63,62 +63,6 @@ class LivechatDepartment extends RocketChat.models._Base { |
|
|
|
|
query = { _id: _id }; |
|
|
|
|
return this.remove(query); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getNextAgent(departmentId) { |
|
|
|
|
|
|
|
|
|
var department = this.findOne({ _id: departmentId }, { fields: { agents: 1 } }) |
|
|
|
|
|
|
|
|
|
if (!department || !department.agents || department.agents.length === 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var onlineUsers = RocketChat.models.Users.findOnlineUserFromList(_.pluck(department.agents, 'username')); |
|
|
|
|
|
|
|
|
|
var onlineUsernames = _.pluck(onlineUsers.fetch(), 'username'); |
|
|
|
|
|
|
|
|
|
console.log('onlineUsernames ->',onlineUsernames); |
|
|
|
|
|
|
|
|
|
var query = { |
|
|
|
|
_id: departmentId, |
|
|
|
|
"agents.username": { |
|
|
|
|
$in: onlineUsernames |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var sort = { |
|
|
|
|
livechatCount: 1, |
|
|
|
|
// sort: 1,
|
|
|
|
|
username: 1 |
|
|
|
|
}; |
|
|
|
|
var update = { |
|
|
|
|
$inc: { |
|
|
|
|
"agents.$.livechatCount": 1 |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// var query = {
|
|
|
|
|
// status: 'online'
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// query['roles.' + Roles.GLOBAL_GROUP] = 'livechat-agent';
|
|
|
|
|
|
|
|
|
|
var collectionObj = this.model.rawCollection(); |
|
|
|
|
var findAndModify = Meteor.wrapAsync(collectionObj.findAndModify, collectionObj); |
|
|
|
|
|
|
|
|
|
// var sort = {
|
|
|
|
|
// livechatCount: 1,
|
|
|
|
|
// username: 1
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// var update = {
|
|
|
|
|
// $inc: {
|
|
|
|
|
// livechatCount: 1
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
return findAndModify(query, sort, update); |
|
|
|
|
// return RocketChat.models.Users.getNextAgent(department.agents);
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RocketChat.models.LivechatDepartment = new LivechatDepartment(); |
|
|
|
|