From c5bf74d145d270a58725826d7ff2ac1d9bd1ee86 Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Thu, 21 Apr 2022 17:30:29 +0530 Subject: [PATCH] Refactor based on Kevins suggestions to call baseClosing data from in main func --- .../server/services/voipService.ts | 16 +++++------- .../services/omnichannel-voip/service.ts | 25 +++++++++++-------- .../core-typings/src/IMessage/IMessage.ts | 2 ++ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/apps/meteor/ee/app/livechat-enterprise/server/services/voipService.ts b/apps/meteor/ee/app/livechat-enterprise/server/services/voipService.ts index a93a024eb3b69..e633a1f7d552b 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/services/voipService.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/services/voipService.ts @@ -1,20 +1,16 @@ -import { ILivechatVisitor, ILivechatAgent, IVoipRoom, IRoomClosingInfo } from '@rocket.chat/core-typings'; +import { IRoomClosingInfo, IOmniRoomClosingMessage } from '@rocket.chat/core-typings'; import { OmnichannelVoipService } from '../../../../../server/services/omnichannel-voip/service'; import { overwriteClassOnLicense } from '../../../license/server'; -const { getBaseRoomClosingData } = OmnichannelVoipService.prototype; - overwriteClassOnLicense('livechat-enterprise', OmnichannelVoipService, { - async getRoomClosingData( + getRoomClosingData( _originalFn: any, - closerParam: ILivechatVisitor | ILivechatAgent, - room: IVoipRoom, - options: { comment?: string; tags?: string[] }, + closeInfo: IRoomClosingInfo, + closeSystemMsgData: IOmniRoomClosingMessage, sysMessageId: 'voip-call-wrapup' | 'voip-call-ended-unexpectedly', - ): Promise<{ closeInfo: IRoomClosingInfo; closeSystemMsgData: any }> { - const { closeInfo, closeSystemMsgData } = await getBaseRoomClosingData(closerParam, room, options, sysMessageId); - + options: { comment?: string; tags?: string[] }, + ): { closeInfo: IRoomClosingInfo; closeSystemMsgData: IOmniRoomClosingMessage } { const { comment, tags } = options; if (comment) { closeSystemMsgData.msg = comment; diff --git a/apps/meteor/server/services/omnichannel-voip/service.ts b/apps/meteor/server/services/omnichannel-voip/service.ts index 64c590456a6d2..dc97383902e3d 100644 --- a/apps/meteor/server/services/omnichannel-voip/service.ts +++ b/apps/meteor/server/services/omnichannel-voip/service.ts @@ -7,6 +7,7 @@ import type { IRoomCreationResponse, IUser, ILivechatAgent, + IOmniRoomClosingMessage, } from '@rocket.chat/core-typings'; import { ILivechatVisitor, @@ -280,8 +281,10 @@ export class OmnichannelVoipService extends ServiceClassInternal implements IOmn return false; } - const { closeInfo, closeSystemMsgData } = await this.getRoomClosingData(closerParam, room, options, sysMessageId); - this.logger.debug(`Closing room ${room._id} by ${closerParam._id}`); + let { closeInfo, closeSystemMsgData } = await this.getBaseRoomClosingData(closerParam, room, options, sysMessageId); + const finalClosingData = this.getRoomClosingData(closeInfo, closeSystemMsgData, sysMessageId, options); + closeInfo = finalClosingData.closeInfo; + closeSystemMsgData = finalClosingData.closeSystemMsgData; await sendMessage(user, closeSystemMsgData, room); @@ -297,13 +300,13 @@ export class OmnichannelVoipService extends ServiceClassInternal implements IOmn return true; } - async getRoomClosingData( - closerParam: ILivechatVisitor | ILivechatAgent, - room: IVoipRoom, - options: { comment?: string; tags?: string[] }, - sysMessageId: 'voip-call-wrapup' | 'voip-call-ended-unexpectedly', - ): Promise<{ closeInfo: IRoomClosingInfo; closeSystemMsgData: any }> { - return this.getBaseRoomClosingData(closerParam, room, options, sysMessageId); + getRoomClosingData( + closeInfo: IRoomClosingInfo, + closeSystemMsgData: any, + _sysMessageId: 'voip-call-wrapup' | 'voip-call-ended-unexpectedly', + _options: { comment?: string; tags?: string[] }, + ): { closeInfo: IRoomClosingInfo; closeSystemMsgData: IOmniRoomClosingMessage } { + return { closeInfo, closeSystemMsgData }; } async getBaseRoomClosingData( @@ -311,7 +314,7 @@ export class OmnichannelVoipService extends ServiceClassInternal implements IOmn room: IVoipRoom, _options: { comment?: string; tags?: string[] }, sysMessageId: 'voip-call-wrapup' | 'voip-call-ended-unexpectedly', - ): Promise<{ closeInfo: IRoomClosingInfo; closeSystemMsgData: any }> { + ): Promise<{ closeInfo: IRoomClosingInfo; closeSystemMsgData: IOmniRoomClosingMessage }> { const now = new Date(); const closer = isILivechatVisitor(closerParam) ? 'visitor' : 'user'; const callTotalHoldTime = await calculateOnHoldTimeForRoom(room, now); @@ -327,7 +330,7 @@ export class OmnichannelVoipService extends ServiceClassInternal implements IOmn }, }; - const message = { + const message: IOmniRoomClosingMessage = { t: sysMessageId, groupable: false, }; diff --git a/packages/core-typings/src/IMessage/IMessage.ts b/packages/core-typings/src/IMessage/IMessage.ts index 8744f9fa6262e..5c6354526f96a 100644 --- a/packages/core-typings/src/IMessage/IMessage.ts +++ b/packages/core-typings/src/IMessage/IMessage.ts @@ -259,3 +259,5 @@ export const isIMessageInbox = (message: IMessage): message is IMessageInbox => "email" in message; export const isVoipMessage = (message: IMessage): message is IVoipMessage => "voipData" in message; + +export type IOmniRoomClosingMessage = Pick & Partial>