[IMPROVE] Standarize queue behavior for managers and agents when subscribing (#24837)

* Standarize queue behavior for managers and agents when subscribing to department/public queues

* Fix import

* Remove task from comment
pull/24884/head
Kevin Aleman 4 years ago committed by Diego Sampaio
parent 52516c98ff
commit 129b09dd67
No known key found for this signature in database
GPG Key ID: E060152B30502562
  1. 11
      app/livechat/client/lib/stream/queueManager.js
  2. 26
      app/livechat/imports/server/rest/inquiries.js
  3. 7
      app/livechat/server/api/lib/inquiries.js
  4. 2
      package-lock.json

@ -45,7 +45,7 @@ const updateCollection = (inquiry) => {
};
const getInquiriesFromAPI = async () => {
const { inquiries } = await APIClient.v1.get('livechat/inquiries.queued?sort={"ts": 1}');
const { inquiries } = await APIClient.v1.get('livechat/inquiries.queuedForUser?sort={"ts": 1}');
return inquiries;
};
@ -59,7 +59,7 @@ const appendListenerToDepartment = (departmentId) => {
inquiryDataStream.on(`department/${departmentId}`, updateCollection);
return () => removeListenerOfDepartment(departmentId);
};
const addListenerForeachDepartment = async (departments = []) => {
const addListenerForeachDepartment = (departments = []) => {
const cleanupFunctions = departments.map((department) => appendListenerToDepartment(department));
return () => cleanupFunctions.forEach((cleanup) => cleanup());
};
@ -87,14 +87,17 @@ const subscribe = async (userId) => {
const agentDepartments = (await getAgentsDepartments(userId)).map((department) => department.departmentId);
const cleanUp = agentDepartments.length ? await addListenerForeachDepartment(agentDepartments) : addGlobalListener();
// Register to all depts + public queue always to match the inquiry list returned by backend
const cleanDepartmentListeners = addListenerForeachDepartment(agentDepartments);
const globalCleanup = addGlobalListener();
updateInquiries(await getInquiriesFromAPI());
return () => {
LivechatInquiry.remove({});
removeGlobalListener();
cleanUp && cleanUp();
cleanDepartmentListeners && cleanDepartmentListeners();
globalCleanup && globalCleanup();
departments.clear();
};
};

@ -5,6 +5,7 @@ import { API } from '../../../../api/server';
import { hasPermission } from '../../../../authorization';
import { Users, LivechatDepartment, LivechatInquiry } from '../../../../models';
import { findInquiries, findOneInquiryByRoomId } from '../../../server/api/lib/inquiries';
import { LivechatInquiryStatus } from '../../../../../definition/IInquiry';
API.v1.addRoute(
'livechat/inquiries.list',
@ -101,6 +102,31 @@ API.v1.addRoute(
},
);
API.v1.addRoute(
'livechat/inquiries.queuedForUser',
{ authRequired: true },
{
async get() {
const { offset, count } = this.getPaginationItems();
const { sort } = this.parseJsonQuery();
const { department } = this.requestParams();
return API.v1.success(
await findInquiries({
userId: this.userId,
filterDepartment: department,
status: LivechatInquiryStatus.QUEUED,
pagination: {
offset,
count,
sort,
},
}),
);
},
},
);
API.v1.addRoute(
'livechat/inquiries.getOne',
{ authRequired: true },

@ -1,6 +1,5 @@
import { hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission';
import { LivechatDepartmentAgents, LivechatDepartment, LivechatInquiry } from '../../../../models/server/raw';
import { hasAnyRoleAsync } from '../../../../authorization/server/functions/hasRole';
const agentDepartments = async (userId) => {
const agentDepartments = (await LivechatDepartmentAgents.findByAgentId(userId).toArray()).map(({ departmentId }) => departmentId);
@ -8,10 +7,6 @@ const agentDepartments = async (userId) => {
};
const applyDepartmentRestrictions = async (userId, filterDepartment) => {
if (await hasAnyRoleAsync(userId, ['livechat-manager'])) {
return filterDepartment;
}
const allowedDepartments = await agentDepartments(userId);
if (allowedDepartments && Array.isArray(allowedDepartments) && allowedDepartments.length > 0) {
if (!filterDepartment) {
@ -48,6 +43,8 @@ export async function findInquiries({ userId, department: filterDepartment, stat
$and: [{ defaultAgent: { $exists: true } }, { 'defaultAgent.agentId': userId }],
},
{ ...(department && { department }) },
// Add _always_ the "public queue" to returned list of inquiries, even if agent already has departments
{ department: { $exists: false } },
],
};

2
package-lock.json generated

@ -24382,7 +24382,7 @@
"dev": true
},
"lamejs": {
"version": "git+https://github.com/zhuker/lamejs.git#564612b5b57336238a5920ba4c301b49f7cb2bab",
"version": "git+https://github.com/zhuker/lamejs.git#582bbba6a12f981b984d8fb9e1874499fed85675",
"from": "git+https://github.com/zhuker/lamejs.git",
"requires": {
"use-strict": "1.0.1"

Loading…
Cancel
Save