Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW][EE] Omnichannel Priorities & SLAs #27083

Merged
merged 129 commits into from Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
23d4fe9
Create SLAs collection and modify current calls
KevLehman Oct 17, 2022
cb1d8c6
[BREAK] Deprecate and remove queueOrder prop (#27088)
KevLehman Oct 18, 2022
80fcc59
[NEW] Add sorting mechanism setting (#27087)
KevLehman Oct 18, 2022
48b0b18
Rename "Estimated due time" to "Estimated wait time" (#27138)
MartinSchoeler Oct 26, 2022
24edeab
[BREAK] Migrate current priorities endpoints to SLAs (#27104)
cauefcr Nov 9, 2022
c4d0327
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Nov 10, 2022
13da302
Fix issues after code merge
KevLehman Nov 10, 2022
dcbe808
fix wrong function call
KevLehman Nov 10, 2022
ba9c011
Minor changes to api names and test
KevLehman Nov 11, 2022
faa65fe
[NEW] Endpoints and model functions to reset priorities (#27237)
cauefcr Nov 15, 2022
b09b30e
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Nov 15, 2022
2b8f2a0
[IMPROVE] Rename priorities to SLA's (#27236)
aleksandernsilva Nov 15, 2022
23f0165
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Nov 17, 2022
91d485d
[NEW] Priorities view including list, edit and reset (#27292)
aleksandernsilva Nov 23, 2022
3528b57
Fix improper model usage
KevLehman Nov 24, 2022
9a73057
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Nov 28, 2022
64ba4d8
[NEW] Priority Icon component (#27362)
aleksandernsilva Nov 29, 2022
506b74f
[NEW] Endpoints for room prioritizing (#27263)
cauefcr Nov 29, 2022
f4cd275
Regression: Don't allow empty spaces on priority name (#27407)
MartinSchoeler Nov 29, 2022
bba0bbc
Regression: VideoConf default info modal not showing meeting URL as a…
pierre-lehnen-rc Nov 28, 2022
99568db
Chore: Update badge tokens (#27363)
juliajforesti Nov 28, 2022
9f52d7e
[FIX] `channels.convertToTeam` endpoint doesn't work when only the `c…
matheusbsilva137 Nov 28, 2022
6c9094a
Chore: Update dark theme tokens (#27386)
juliajforesti Nov 28, 2022
1d7d553
[FIX] Thread messages being included in the room history even though …
dougfabris Nov 28, 2022
0564f73
Regression: Old threads not opening (#27384)
yash-rajpal Nov 29, 2022
cab6af8
Regression: Update VideoConfListItem Color Tokens (#27402)
dougfabris Nov 29, 2022
f1d199e
[FIX] Quoting Issue (#27369)
henit-chobisa Nov 29, 2022
947430f
i18n: Language update from LingoHub 🤖 on 2022-11-29Z (#27410)
lingohub[bot] Nov 30, 2022
448b44c
Regression: Fix issues with ContactHistoryItem (#27406)
MartinSchoeler Nov 30, 2022
49f4a84
Regression: Login and Registration UI Tweaks (#27411)
dougfabris Nov 30, 2022
85da50b
Chore: Update tokens (#27408)
juliajforesti Nov 30, 2022
234bd17
Regression: Bad words Filtering not working on new Message Parser (#2…
xareyli Dec 1, 2022
5c1897d
[FIX] Fix Piwik and add extra setting to allow workarounds (#27416)
ggazzo Dec 1, 2022
fb0d373
Regression: Admin menu apps option not working (#27422)
rique223 Dec 1, 2022
fb05d9a
Regression: message-box-editing-color (#27420)
juliajforesti Dec 1, 2022
d8f0830
Regression: fix sidebar status
ggazzo Dec 2, 2022
7da5095
Chore: bumping apps engine version (#27414)
AllanPazRibeiro Dec 2, 2022
74fc928
[FIX] Livechat: Allow resolving external image and media blocks (#27387)
cauefcr Dec 2, 2022
f99daad
update lock
KevLehman Dec 2, 2022
71282aa
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Dec 2, 2022
a947da6
[FIX] Adjusted priority form to revalidate after reset (#27458)
aleksandernsilva Dec 6, 2022
32e7650
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Dec 6, 2022
3efcafe
Fix lint
KevLehman Dec 6, 2022
4216c54
[BREAK] update LivechatPriority data representation at disk, adds ind…
cauefcr Dec 8, 2022
c245e0a
Chore: SLA policies e2e tests (#27364)
aleksandernsilva Dec 8, 2022
a87777f
Chore: Deprecate meteor methods used by SLAs and replace with APIs
murtaza98 Dec 8, 2022
c5a0f4d
Chore: Add missing indexes to SLA collection (#27483)
KevLehman Dec 8, 2022
b3a237d
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Dec 8, 2022
9986eee
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Dec 8, 2022
9634d9d
[IMPROVE] Add validation on BE to ensure that priority name is unique…
murtaza98 Dec 9, 2022
68c1664
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Dec 12, 2022
c261f1f
[FIX] Changed remove SLA message to mention SLA instead of Priority (…
aleksandernsilva Dec 13, 2022
62bf23f
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Dec 13, 2022
dba1be2
[NEW] Sort livechat inquiries by chosen setting (#27313)
cauefcr Dec 26, 2022
5ed6af9
[IMPROVE] Added ability to reset individual priority (#27520)
aleksandernsilva Dec 26, 2022
050b1ab
Merge branch 'develop' into feature/omnichannel-priorities
murtaza98 Dec 26, 2022
9d9d5c0
Merge branch 'feature/omnichannel-priorities' of ssh://github.com/Roc…
murtaza98 Dec 26, 2022
573b34f
[FIX] Added form error validation for duplicated priority name (#27506)
aleksandernsilva Jan 4, 2023
c61b010
Merge branch 'develop' into feature/omnichannel-priorities
murtaza98 Jan 12, 2023
c37a2a6
adapt to new useEndpoint() format
murtaza98 Jan 12, 2023
55a3219
[FIX] Incorrect sorting policy for conflicts withing priorities and S…
murtaza98 Jan 16, 2023
5fd87bd
[FIX] Changed sorting mechanism select option from "Service level agr…
aleksandernsilva Jan 17, 2023
7e1f329
[IMPROVE] Added priority field to edit room contextual bar (#27638)
aleksandernsilva Jan 18, 2023
93eac34
[IMPROVE] Added priority sorting and visual indicator on the sidebar …
aleksandernsilva Jan 30, 2023
c55d179
[NEW] Added priorities fetch to Omnichannel context
aleksandernsilva Jan 30, 2023
d9e3d09
[IMPROVE] Adding staleTime config to priorities fetch
aleksandernsilva Jan 30, 2023
896f8c6
Chore: Replaced usePrioritiesData with useOmnichannelPriorities
aleksandernsilva Jan 30, 2023
7ec9154
[IMPROVE] Added enabled prop to priorities data
aleksandernsilva Jan 30, 2023
78573a5
[IMPROVE] Added unprioritized and tooltip to PriorityIcon
aleksandernsilva Jan 30, 2023
f4144c9
Merge branch 'develop' into feature/omnichannel-priorities
murtaza98 Jan 31, 2023
c6c4c9f
Merge branch 'feature/omnichannel-priorities' into new/omnichannel-co…
aleksandernsilva Jan 31, 2023
5f0efa3
[FIX] Adjusting all conditional queries to use isInitialLoading inste…
aleksandernsilva Feb 1, 2023
565b937
[IMPROVE] Added PriorityIcon to PrioritiesSelect (#27894)
aleksandernsilva Feb 3, 2023
db5a924
[NEW] Add new priority column to current chats table (#27893)
aleksandernsilva Feb 3, 2023
bf5694b
Merge branch 'develop' into feature/omnichannel-priorities
aleksandernsilva Feb 7, 2023
fe4e1aa
[NEW] Add system message upon Priority and SLA change (#27919)
murtaza98 Feb 7, 2023
1235397
[FIX] Invalidates rooms.info query using room data stream
aleksandernsilva Feb 7, 2023
5642703
Chore: Implemented e2e tests for priorities (#27788)
aleksandernsilva Feb 7, 2023
bd2c4e8
[NEW] Added priorities sidebar menu (#27895)
aleksandernsilva Feb 7, 2023
609b351
Merge branch 'develop' into feature/omnichannel-priorities
murtaza98 Feb 9, 2023
8430651
Merge branch 'feature/omnichannel-priorities' into new/omnichannel-co…
aleksandernsilva Feb 9, 2023
de51b96
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 9, 2023
c1b553a
Merge branch 'feature/omnichannel-priorities' into new/omnichannel-co…
aleksandernsilva Feb 9, 2023
e7d4d93
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 10, 2023
62283ef
[IMPROVE] Changed RoomMenu maxHeight to accommodate priorities (#27983)
aleksandernsilva Feb 10, 2023
77097c7
damn imports
KevLehman Feb 10, 2023
933d865
Merge branch 'feature/omnichannel-priorities' into new/omnichannel-co…
KevLehman Feb 10, 2023
82a6c66
[NEW] Create stream for priority updates (#27291)
KevLehman Feb 10, 2023
ee5126c
Merge branch 'feature/omnichannel-priorities' into new/omnichannel-co…
murtaza98 Feb 10, 2023
a91de98
[IMPROVE] Invalidates priorities query after a priorities change
aleksandernsilva Feb 10, 2023
93909af
[FIX] Migration for priorities (#27988)
KevLehman Feb 10, 2023
9b5af85
[NEW] Added omnichannel sorting disclaimer to SortModeList menu (#27913)
aleksandernsilva Feb 10, 2023
936a4a9
[FIX] Changed from useMutableCallback to useCallback
aleksandernsilva Feb 10, 2023
160fcd3
Merge branch 'feature/omnichannel-priorities' into new/omnichannel-co…
aleksandernsilva Feb 10, 2023
01272eb
[FIX] Adjusted priority icon positioning and added spacing (#27910)
aleksandernsilva Feb 10, 2023
df15901
[FIX] Changed from useMutableCallback to useCallback
aleksandernsilva Feb 10, 2023
d81539f
Merge branch 'feature/omnichannel-priorities' into new/omnichannel-co…
aleksandernsilva Feb 10, 2023
dedd38e
[NEW] Added priorities fetch to Omnichannel context (#27888)
aleksandernsilva Feb 10, 2023
84791fa
Merge branch 'feature/omnichannel-priorities' of github.com:RocketCha…
KevLehman Feb 11, 2023
e660ec2
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 11, 2023
65bece0
[FIX] Priority on current chats not being updated as it should
aleksandernsilva Feb 13, 2023
514b7cd
Chore: Code cleanup
aleksandernsilva Feb 13, 2023
6523fbc
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 13, 2023
af0a196
Merge branch 'develop' into feature/omnichannel-priorities
aleksandernsilva Feb 13, 2023
d101728
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 13, 2023
222fcc4
Merge remote-tracking branch 'origin/develop' into feature/omnichanne…
sampaiodiego Feb 13, 2023
4d44bc8
go brr
KevLehman Feb 14, 2023
3ca749c
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 14, 2023
b26e6d6
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 14, 2023
b312c20
?
KevLehman Feb 14, 2023
2498440
??
KevLehman Feb 14, 2023
ac67447
fix room priority not set
murtaza98 Feb 14, 2023
31e3922
Merge branch 'develop' into feature/omnichannel-priorities
murtaza98 Feb 14, 2023
da5061b
fix lint
murtaza98 Feb 14, 2023
6b1be44
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 14, 2023
8571617
Merge branch 'feature/omnichannel-priorities' of github.com:RocketCha…
sampaiodiego Feb 14, 2023
de68e2f
Merge remote-tracking branch 'origin/develop' into feature/omnichanne…
sampaiodiego Feb 14, 2023
f0fbcfd
returns
KevLehman Feb 14, 2023
66c2e64
smol fix
KevLehman Feb 14, 2023
473b3c1
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 14, 2023
cc41ae1
Merge branch 'feature/omnichannel-priorities' of github.com:RocketCha…
sampaiodiego Feb 14, 2023
2e6fcfb
Merge remote-tracking branch 'origin/develop' into feature/omnichanne…
sampaiodiego Feb 14, 2023
7350992
remove "dom" lib from tsconfig.base.server.json
sampaiodiego Feb 14, 2023
a6675a2
Merge branch 'develop' into feature/omnichannel-priorities
KevLehman Feb 14, 2023
64c7145
remove type casting
sampaiodiego Feb 14, 2023
0d64ebc
Merge branch 'develop' into feature/omnichannel-priorities
sampaiodiego Feb 14, 2023
7860773
Merge branch 'develop' into feature/omnichannel-priorities
sampaiodiego Feb 14, 2023
5d2e0a0
use list reporter for e2e tests
sampaiodiego Feb 15, 2023
5bb4d6c
allow EE test to run for 50 minutes
sampaiodiego Feb 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -117,7 +117,7 @@ export const upsertPermissions = async (): Promise<void> => {
_id: 'on-hold-others-livechat-room',
roles: ['livechat-manager', 'livechat-monitor', 'admin'],
},
{ _id: 'save-others-livechat-room-info', roles: ['livechat-manager', 'livechat-monitor'] },
{ _id: 'save-others-livechat-room-info', roles: ['livechat-manager', 'livechat-monitor', 'admin'] },
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
{
_id: 'remove-closed-livechat-rooms',
roles: ['livechat-manager', 'livechat-monitor', 'admin'],
Expand Down
Expand Up @@ -45,7 +45,7 @@ const updateCollection = (inquiry) => {
};

const getInquiriesFromAPI = async () => {
const { inquiries } = await APIClient.get('/v1/livechat/inquiries.queuedForUser', { sort: JSON.stringify({ ts: 1 }) });
const { inquiries } = await APIClient.get('/v1/livechat/inquiries.queuedForUser');
return inquiries;
};

Expand Down
30 changes: 30 additions & 0 deletions apps/meteor/app/livechat/lib/inquiries.ts
@@ -0,0 +1,30 @@
import { OmnichannelSortingMechanismSettingType } from '@rocket.chat/core-typings';

type SortOrder = 1 | -1;

type ReturnType =
| {
priorityWeight: SortOrder;
ts: SortOrder;
}
| {
estimatedWaitingTimeQueue: SortOrder;
ts: SortOrder;
}
| {
ts: SortOrder;
};

export const getOmniChatSortQuery = (
sortByMechanism: OmnichannelSortingMechanismSettingType = OmnichannelSortingMechanismSettingType.Timestamp,
): ReturnType => {
switch (sortByMechanism) {
case OmnichannelSortingMechanismSettingType.Priority:
return { priorityWeight: 1, ts: 1 };
case OmnichannelSortingMechanismSettingType.SLAs:
return { estimatedWaitingTimeQueue: 1, ts: 1 };
case OmnichannelSortingMechanismSettingType.Timestamp:
default:
return { ts: 1 };
}
};
16 changes: 10 additions & 6 deletions apps/meteor/app/livechat/server/api/lib/inquiries.ts
@@ -1,6 +1,11 @@
import type { ILivechatInquiryRecord, IRoom, IUser, LivechatInquiryStatus } from '@rocket.chat/core-typings';
import { LivechatInquiryStatus } from '@rocket.chat/core-typings';
import type { ILivechatInquiryRecord, IRoom, IUser } from '@rocket.chat/core-typings';
import { LivechatDepartmentAgents, LivechatDepartment, LivechatInquiry } from '@rocket.chat/models';
import type { PaginatedResult } from '@rocket.chat/rest-typings';
import type { Filter } from 'mongodb';

import { getOmniChatSortQuery } from '../../../lib/inquiries';
import { getInquirySortMechanismSetting } from '../../lib/settings';

const agentDepartments = async (userId: IUser['_id']): Promise<string[]> => {
const agentDepartments = (await LivechatDepartmentAgents.findByAgentId(userId).toArray()).map(({ departmentId }) => departmentId);
Expand All @@ -20,7 +25,6 @@ const applyDepartmentRestrictions = async (
if (!allowedDepartments.includes(filterDepartment)) {
throw new Error('error-not-authorized');
}

return filterDepartment;
}

Expand All @@ -39,15 +43,15 @@ export async function findInquiries({
pagination: { offset: number; count: number; sort: Record<string, number> };
}): Promise<PaginatedResult<{ inquiries: Array<ILivechatInquiryRecord> }>> {
const department = await applyDepartmentRestrictions(userId, filterDepartment);

const defaultSort = getOmniChatSortQuery(getInquirySortMechanismSetting());
const options = {
limit: count,
sort: sort || { ts: -1 },
skip: offset,
sort: { ...sort, ...defaultSort },
};

const filter = {
...(status && { status }),
const filter: Filter<ILivechatInquiryRecord> = {
...(status && status in LivechatInquiryStatus && { status }),
$or: [
{
$and: [{ defaultAgent: { $exists: true } }, { 'defaultAgent.agentId': userId }],
Expand Down
44 changes: 23 additions & 21 deletions apps/meteor/app/livechat/server/lib/Helper.js
Expand Up @@ -2,7 +2,8 @@ import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { Match, check } from 'meteor/check';
import { LivechatTransferEventType } from '@rocket.chat/apps-engine/definition/livechat';
import { OmnichannelSourceType } from '@rocket.chat/core-typings';
import { OmnichannelSourceType, DEFAULT_SLA_CONFIG } from '@rocket.chat/core-typings';
import { LivechatPriorityWeight } from '@rocket.chat/core-typings/src/ILivechatPriority';
import { api } from '@rocket.chat/core-services';

import { hasRole } from '../../../authorization';
Expand Down Expand Up @@ -85,6 +86,9 @@ export const createLivechatRoom = (rid, name, guest, roomInfo = {}, extraData =
alias: 'unknown',
},
queuedAt: newRoomAt,

priorityWeight: LivechatPriorityWeight.NOT_SPECIFIED,
estimatedWaitingTimeQueue: DEFAULT_SLA_CONFIG.ESTIMATED_WAITING_TIME_QUEUE,
},
extraRoomInfo,
);
Expand Down Expand Up @@ -128,27 +132,25 @@ export const createLivechatInquiry = ({ rid, name, guest, message, initialStatus

logger.debug(`Creating livechat inquiry for visitor ${_id}`);

const inquiry = Object.assign(
{
rid,
name,
ts,
department,
message: msg,
status: initialStatus || 'ready',
v: {
_id,
username,
token,
status,
},
t: 'l',
queueOrder: 1,
estimatedWaitingTimeQueue: 0,
estimatedServiceTimeAt: ts,
const inquiry = {
rid,
name,
ts,
department,
message: msg,
status: initialStatus || 'ready',
v: {
_id,
username,
token,
status,
},
extraInquiryInfo,
);
t: 'l',
priorityWeight: LivechatPriorityWeight.NOT_SPECIFIED,
estimatedWaitingTimeQueue: DEFAULT_SLA_CONFIG.ESTIMATED_WAITING_TIME_QUEUE,

...extraInquiryInfo,
};

const result = LivechatInquiry.insert(inquiry);
logger.debug(`Inquiry ${result} created for visitor ${_id}`);
Expand Down
6 changes: 6 additions & 0 deletions apps/meteor/app/livechat/server/lib/settings.ts
@@ -0,0 +1,6 @@
import { OmnichannelSortingMechanismSettingType } from '@rocket.chat/core-typings';

import { settings } from '../../../settings/server';

export const getInquirySortMechanismSetting = (): OmnichannelSortingMechanismSettingType =>
settings.get<OmnichannelSortingMechanismSettingType>('Omnichannel_sorting_mechanism') || OmnichannelSortingMechanismSettingType.Timestamp;
1 change: 1 addition & 0 deletions apps/meteor/app/livechat/server/methods/saveInfo.js
Expand Up @@ -41,6 +41,7 @@ Meteor.methods({
tags: Match.Optional([String]),
livechatData: Match.Optional(Object),
priorityId: Match.Optional(String),
slaId: Match.Optional(String),
}),
);

Expand Down
5 changes: 5 additions & 0 deletions apps/meteor/app/models/client/models/CachedChatRoom.ts
@@ -1,4 +1,5 @@
import type { IOmnichannelRoom, IRoom, IRoomWithRetentionPolicy } from '@rocket.chat/core-typings';
import { DEFAULT_SLA_CONFIG, LivechatPriorityWeight } from '@rocket.chat/core-typings';

import { ChatSubscription } from './ChatSubscription';
import { CachedCollection } from '../../../ui-cached-collection/client';
Expand Down Expand Up @@ -59,6 +60,10 @@ class CachedChatRoom extends CachedCollection<IRoom> {
waitingResponse: (room as IOmnichannelRoom | undefined)?.waitingResponse,
responseBy: (room as IOmnichannelRoom | undefined)?.responseBy,
priorityId: (room as IOmnichannelRoom | undefined)?.priorityId,
priorityWeight: (room as IOmnichannelRoom | undefined)?.priorityWeight || LivechatPriorityWeight.NOT_SPECIFIED,
estimatedWaitingTimeQueue:
(room as IOmnichannelRoom | undefined)?.estimatedWaitingTimeQueue || DEFAULT_SLA_CONFIG.ESTIMATED_WAITING_TIME_QUEUE,
slaId: (room as IOmnichannelRoom | undefined)?.slaId,
livechatData: (room as IOmnichannelRoom | undefined)?.livechatData,
departmentId: (room as IOmnichannelRoom | undefined)?.departmentId,
ts: room.ts,
Expand Down
@@ -1,4 +1,5 @@
import type { IOmnichannelRoom, IRoomWithRetentionPolicy } from '@rocket.chat/core-typings';
import { DEFAULT_SLA_CONFIG, LivechatPriorityWeight } from '@rocket.chat/core-typings';

import { CachedCollection } from '../../../ui-cached-collection/client';
import type { SubscriptionWithRoom } from '../../../../client/definitions/SubscriptionWithRoom';
Expand Down Expand Up @@ -61,6 +62,9 @@ class CachedChatSubscription extends CachedCollection<SubscriptionWithRoom> {
closedAt: 1,
responseBy: 1,
priorityId: 1,
priorityWeight: 1,
slaId: 1,
estimatedWaitingTimeQueue: 1,
livechatData: 1,
departmentId: 1,
source: 1,
Expand Down Expand Up @@ -110,6 +114,10 @@ class CachedChatSubscription extends CachedCollection<SubscriptionWithRoom> {
waitingResponse: (room as IOmnichannelRoom | undefined)?.waitingResponse,
responseBy: (room as IOmnichannelRoom | undefined)?.responseBy,
priorityId: (room as IOmnichannelRoom | undefined)?.priorityId,
slaId: (room as IOmnichannelRoom | undefined)?.slaId,
priorityWeight: (room as IOmnichannelRoom | undefined)?.priorityWeight || LivechatPriorityWeight.NOT_SPECIFIED,
estimatedWaitingTimeQueue:
(room as IOmnichannelRoom | undefined)?.estimatedWaitingTimeQueue || DEFAULT_SLA_CONFIG.ESTIMATED_WAITING_TIME_QUEUE,
livechatData: (room as IOmnichannelRoom | undefined)?.livechatData,
departmentId: (room as IOmnichannelRoom | undefined)?.departmentId,
ts: room?.ts ?? subscription.ts,
Expand Down
96 changes: 15 additions & 81 deletions apps/meteor/app/models/server/models/LivechatInquiry.ts
@@ -1,7 +1,7 @@
import type { ILivechatInquiryRecord } from '@rocket.chat/core-typings';
import type { FindOptions, FindCursor, UpdateResult } from 'mongodb';
import { LivechatInquiryStatus } from '@rocket.chat/core-typings';
import type { FindOptions, FindCursor, UpdateResult, DeleteResult } from 'mongodb';

import { readSecondaryPreferred } from '../../../../server/database/readSecondaryPreferred';
import { Base } from './_Base';

export class LivechatInquiry extends Base {
Expand All @@ -14,7 +14,12 @@ export class LivechatInquiry extends Base {
this.tryEnsureIndex({ ts: 1 }); // timestamp
this.tryEnsureIndex({ department: 1 });
this.tryEnsureIndex({ status: 1 }); // 'ready', 'queued', 'taken'
this.tryEnsureIndex({ queueOrder: 1, estimatedWaitingTimeQueue: 1, estimatedServiceTimeAt: 1 });
this.tryEnsureIndex({ priorityId: 1, priorityWeight: 1 }, { sparse: true });
this.tryEnsureIndex({ priorityWeight: 1, ts: 1 }, { partialFilterExpression: { status: { $eq: LivechatInquiryStatus.QUEUED } } }); // used for sorting inquiries when OmnichannelSortingMechanismSettingType.Priority is selected
this.tryEnsureIndex(
{ estimatedWaitingTimeQueue: 1, ts: 1 },
{ partialFilterExpression: { status: { $eq: LivechatInquiryStatus.QUEUED } } },
); // used for sorting inquiries when OmnichannelSortingMechanismSettingType.SLAs is selected
this.tryEnsureIndex({ 'v.token': 1, 'status': 1 }); // visitor token and status
this.tryEnsureIndex({ locked: 1, lockedAt: 1 }, { sparse: true }); // locked and lockedAt
}
Expand All @@ -27,22 +32,6 @@ export class LivechatInquiry extends Base {
return this.findOne({ rid }, options);
}

getNextInquiryQueued(department?: string): ILivechatInquiryRecord {
return this.findOne(
{
status: 'queued',
...(department && { department }),
},
{
sort: {
queueOrder: 1,
estimatedWaitingTimeQueue: 1,
estimatedServiceTimeAt: 1,
},
},
);
}

getQueuedInquiries(options?: FindOptions<ILivechatInquiryRecord>): FindCursor<ILivechatInquiryRecord> {
return this.find({ status: 'queued' }, options);
}
Expand Down Expand Up @@ -186,68 +175,6 @@ export class LivechatInquiry extends Base {
return this.findOne(query);
}

async getCurrentSortedQueueAsync({
_id,
department,
}: {
_id: string;
department: string;
}): Promise<Pick<ILivechatInquiryRecord, '_id' | 'rid' | 'name' | 'ts' | 'status' | 'department'> & { position: number }> {
const collectionObj = this.model.rawCollection();
const aggregate = [
{
$match: {
status: 'queued',
...(department && { department }),
},
},
{
$sort: {
ts: 1,
},
},
{
$group: {
_id: 1,
inquiry: {
$push: {
_id: '$_id',
rid: '$rid',
name: '$name',
ts: '$ts',
status: '$status',
department: '$department',
},
},
},
},
{
$unwind: {
path: '$inquiry',
includeArrayIndex: 'position',
},
},
{
$project: {
_id: '$inquiry._id',
rid: '$inquiry.rid',
name: '$inquiry.name',
ts: '$inquiry.ts',
status: '$inquiry.status',
department: '$inquiry.department',
position: 1,
},
},
] as any[];

// To get the current room position in the queue, we need to apply the next $match after the $project
if (_id) {
aggregate.push({ $match: { _id } });
}

return collectionObj.aggregate(aggregate, { readPreference: readSecondaryPreferred() }).toArray();
}

removeDefaultAgentById(inquiryId: string): UpdateResult {
return this.update(
{
Expand All @@ -259,6 +186,13 @@ export class LivechatInquiry extends Base {
);
}

/*
* remove the inquiry by roomId
*/
removeByRoomId(rid: string): DeleteResult {
return this.remove({ rid });
}

removeByVisitorToken(token: string): void {
const query = {
'v.token': token,
Expand Down
9 changes: 9 additions & 0 deletions apps/meteor/app/models/server/models/LivechatRooms.js
Expand Up @@ -109,6 +109,15 @@ export class LivechatRooms extends Base {
unsetData.tags = 1;
}

if (extra.priorityId === '') {
unsetData.priorityId = 1;
delete setData.priorityId;
}
if (extra.slaId === '') {
unsetData.slaId = 1;
delete setData.slaId;
}

if (livechatData) {
Object.keys(livechatData).forEach((key) => {
const value = s.trim(livechatData[key]);
Expand Down
14 changes: 14 additions & 0 deletions apps/meteor/client/components/InlineGroup/index.tsx
@@ -0,0 +1,14 @@
import { css } from '@rocket.chat/css-in-js';
import { Box } from '@rocket.chat/fuselage';
import type { FC } from 'react';
import React from 'react';

export const InlineGroup: FC<{ gap: number }> = ({ children, gap }) => {
const badgesContainer = css`
* + * {
margin-inline-start: ${gap}px;
}
`;

return <Box className={badgesContainer}>{children}</Box>;
};