Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions app/livechat/server/lib/RoutingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ export const RoutingManager = {
throw new Meteor.Error('error-creating-subscription', 'Error creating subscription');
}

LivechatRooms.changeAgentByRoomId(rid, agent);
Rooms.incUsersCountById(rid);
Rooms.incUsersCountAndChangeAgentByRoomId(rid, agent);

const user = Users.findOneById(agent.agentId);
const room = LivechatRooms.findOneById(rid);
Expand Down
22 changes: 0 additions & 22 deletions app/models/server/models/LivechatRooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,28 +699,6 @@ export class LivechatRooms extends Base {
return this.find(query);
}

changeAgentByRoomId(roomId, newAgent) {
const query = {
_id: roomId,
t: 'l',
};
const update = {
$set: {
servedBy: {
_id: newAgent.agentId,
username: newAgent.username,
ts: new Date(),
},
},
};

if (newAgent.ts) {
update.$set.servedBy.ts = newAgent.ts;
}

this.update(query, update);
}

changeDepartmentIdByRoomId(roomId, departmentId) {
const query = {
_id: roomId,
Expand Down
22 changes: 22 additions & 0 deletions app/models/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,28 @@ export class Rooms extends Base {
return this.update(query, update);
}

// Note: regarding omnichannel property - "servedBy" - over here
// For some reason, the update statement with only "servedBy" is not working properly if the update is performed from "LivechatRooms" collection.
// hence, I had to move it over here
incUsersCountAndChangeAgentByRoomId(_id, newAgent, inc = 1) {
const query = { _id };

const update = {
$inc: {
usersCount: inc,
},
$set: {
servedBy: {
_id: newAgent.agentId,
username: newAgent.username,
ts: newAgent.ts || new Date(),
},
},
};

return this.update(query, update);
}

incUsersCountByIds(ids, inc = 1) {
const query = {
_id: {
Expand Down