Skip to content

Commit

Permalink
Merge branch 'develop' into new-action-to-publish-releases
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Jun 13, 2023
2 parents 9d5053b + d34ce15 commit 34cf790
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
18 changes: 8 additions & 10 deletions apps/meteor/ee/app/livechat-enterprise/server/lib/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@rocket.chat/models';
import { api } from '@rocket.chat/core-services';
import type { Document } from 'mongodb';
import type { ILivechatInquiryRecord, IOmnichannelRoom, IOmnichannelServiceLevelAgreements } from '@rocket.chat/core-typings';
import type { IOmnichannelRoom, IOmnichannelServiceLevelAgreements, InquiryWithAgentInfo } from '@rocket.chat/core-typings';

import { memoizeDebounce } from './debounceByParams';
import { settings } from '../../../../../app/settings/server';
Expand All @@ -31,12 +31,6 @@ type QueueInfo = {
statistics: Document;
numberMostRecentChats: number;
};

type InquiryWithExtraData = Pick<ILivechatInquiryRecord, '_id' | 'rid' | 'name' | 'ts' | 'status' | 'department'> & {
position: number;
defaultAgent?: { username: string; agentId: string };
};

export const getMaxNumberSimultaneousChat = async ({ agentId, departmentId }: { agentId?: string; departmentId?: string }) => {
if (departmentId) {
const department = await LivechatDepartmentRaw.findOneById(departmentId);
Expand Down Expand Up @@ -106,10 +100,14 @@ const normalizeQueueInfo = async ({
return { spot, message, estimatedWaitTimeSeconds };
};

export const dispatchInquiryPosition = async (inquiry: InquiryWithExtraData, queueInfo?: QueueInfo) => {
export const dispatchInquiryPosition = async (inquiry: Omit<InquiryWithAgentInfo, 'v'>, queueInfo?: QueueInfo) => {
const { position, department } = inquiry;
// Avoid broadcasting if no position was determined
if (position === undefined) {
return;
}
const data = await normalizeQueueInfo({ position, queueInfo, department });
const propagateInquiryPosition = (inquiry: InquiryWithExtraData) => {
const propagateInquiryPosition = (inquiry: Omit<InquiryWithAgentInfo, 'v'>) => {
void api.broadcast('omnichannel.room', inquiry.rid, {
type: 'queueData',
data,
Expand Down Expand Up @@ -146,7 +144,7 @@ const dispatchWaitingQueueStatus = async (department?: string) => {
// but we don't need to notify _each_ change that takes place, just their final position
export const debouncedDispatchWaitingQueueStatus = memoizeDebounce(dispatchWaitingQueueStatus, 1200);

export const processWaitingQueue = async (department: string | undefined, inquiry: InquiryWithExtraData) => {
export const processWaitingQueue = async (department: string | undefined, inquiry: InquiryWithAgentInfo) => {
const queue = department || 'Public';
helperLogger.debug(`Processing items on queue ${queue}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
IOmnichannelRoom,
IOmnichannelServiceLevelAgreements,
LivechatDepartmentDTO,
InquiryWithAgentInfo,
} from '@rocket.chat/core-typings';

import { hasLicense } from '../../../license/server/license';
Expand Down Expand Up @@ -386,7 +387,7 @@ const queueWorker: QueueWorker = {
return;
}

const result = await processWaitingQueue(queue, nextInquiry);
const result = await processWaitingQueue(queue, nextInquiry as InquiryWithAgentInfo);

if (!result) {
await LivechatInquiry.unlock(nextInquiry._id);
Expand Down
5 changes: 5 additions & 0 deletions packages/core-typings/src/IInquiry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ export interface ILivechatInquiryRecord extends IRocketChatRecord {
slaId?: string;
estimatedWaitingTimeQueue: IOmnichannelServiceLevelAgreements['dueTimeInMinutes'];
}

export type InquiryWithAgentInfo = Pick<ILivechatInquiryRecord, '_id' | 'rid' | 'name' | 'ts' | 'status' | 'department' | 'v'> & {
position?: number;
defaultAgent?: { username: string; agentId: string };
};

0 comments on commit 34cf790

Please sign in to comment.