Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Oct 20, 2023
1 parent e8f30cb commit 64cc881
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions apps/meteor/app/livechat/server/api/lib/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,26 @@ async function findUsers({
pagination: { offset: number; count: number; sort: any };
}): Promise<{ users: ILivechatAgent[]; count: number; offset: number; total: number }> {
const query: FilterOperators<ILivechatAgent> = {};
const orConditions: FilterOperators<ILivechatAgent>['$or'] = [];
if (text) {
const filterReg = new RegExp(escapeRegExp(text), 'i');
Object.assign(query, {
$or: [{ username: filterReg }, { name: filterReg }, { 'emails.address': filterReg }],
});
orConditions.push({ $or: [{ username: filterReg }, { name: filterReg }, { 'emails.address': filterReg }] });
}

if (onlyAvailable) {
Object.assign(query, {
statusLivechat: 'available',
});
query.statusLivechat = 'available';
}

if (excludeId) {
Object.assign(query, {
_id: { $ne: excludeId },
});
query._id = { $ne: excludeId };
}

if (!showIdleAgents) {
const oldOr = query.$or;

const newOr = [{ status: { $exists: true, $ne: 'offline' }, roles: { $ne: 'bot' } }, { roles: 'bot' }];
orConditions.push({ $or: [{ status: { $exists: true, $ne: 'offline' }, roles: { $ne: 'bot' } }, { roles: 'bot' }] });
}

if (oldOr) {
delete query.$or;
Object.assign(query, {
$and: [
{
$or: oldOr,
},
{
$or: newOr,
},
],
});
} else {
Object.assign(query, {
$or: newOr,
});
}
if (orConditions.length) {
query.$and = orConditions;
}

const [
Expand Down

0 comments on commit 64cc881

Please sign in to comment.