Skip to content

Commit

Permalink
move on-hold timer calculation logic behind EE license
Browse files Browse the repository at this point in the history
  • Loading branch information
murtaza98 committed May 30, 2022
1 parent 0116fda commit 2a5b228
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IVoipRoom } from '@rocket.chat/core-typings';

import { PbxEvent } from '../../../app/models/server/raw';
import { PbxEvent } from '../../../../../../app/models/server/raw';

export const calculateOnHoldTimeForRoom = async (room: IVoipRoom, closedAt: Date): Promise<number> => {
if (!room.callUniqueId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { IRoomClosingInfo } from '@rocket.chat/core-typings';
import { IRoomClosingInfo, IVoipRoom } from '@rocket.chat/core-typings';

import { IOmniRoomClosingMessage } from '../../../../../server/services/omnichannel-voip/internalTypes';
import { OmnichannelVoipService } from '../../../../../server/services/omnichannel-voip/service';
import { overwriteClassOnLicense } from '../../../license/server';
import { calculateOnHoldTimeForRoom } from '../lib/voip/helper';

overwriteClassOnLicense('livechat-enterprise', OmnichannelVoipService, {
getRoomClosingData(
_originalFn: any,
closeInfo: IRoomClosingInfo,
closeSystemMsgData: IOmniRoomClosingMessage,
room: IVoipRoom,
sysMessageId: 'voip-call-wrapup' | 'voip-call-ended-unexpectedly',
options?: { comment?: string; tags?: string[] },
): { closeInfo: IRoomClosingInfo; closeSystemMsgData: IOmniRoomClosingMessage } {
Expand All @@ -24,6 +26,10 @@ overwriteClassOnLicense('livechat-enterprise', OmnichannelVoipService, {
closeSystemMsgData.t = 'voip-call-ended';
}

const now = new Date();
const callTotalHoldTime = Promise.await(calculateOnHoldTimeForRoom(room, now));
closeInfo.callTotalHoldTime = callTotalHoldTime;

return { closeInfo, closeSystemMsgData };
},
});
8 changes: 3 additions & 5 deletions apps/meteor/server/services/omnichannel-voip/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { PbxEventsRaw } from '../../../app/models/server/raw/PbxEvents';
import { sendMessage } from '../../../app/lib/server/functions/sendMessage';
import { FindVoipRoomsParams, IOmniRoomClosingMessage } from './internalTypes';
import { api } from '../../sdk/api';
import { calculateOnHoldTimeForRoom } from './helper';

export class OmnichannelVoipService extends ServiceClassInternal implements IOmnichannelVoipService {
protected name = 'omnichannel-voip';
Expand Down Expand Up @@ -280,7 +279,7 @@ export class OmnichannelVoipService extends ServiceClassInternal implements IOmn
}

let { closeInfo, closeSystemMsgData } = await this.getBaseRoomClosingData(closerParam, room, sysMessageId, options);
const finalClosingData = this.getRoomClosingData(closeInfo, closeSystemMsgData, sysMessageId, options);
const finalClosingData = this.getRoomClosingData(closeInfo, closeSystemMsgData, room, sysMessageId, options);
closeInfo = finalClosingData.closeInfo;
closeSystemMsgData = finalClosingData.closeSystemMsgData;

Expand All @@ -300,7 +299,8 @@ export class OmnichannelVoipService extends ServiceClassInternal implements IOmn

getRoomClosingData(
closeInfo: IRoomClosingInfo,
closeSystemMsgData: any,
closeSystemMsgData: IOmniRoomClosingMessage,
_room: IVoipRoom,
_sysMessageId: 'voip-call-wrapup' | 'voip-call-ended-unexpectedly',
_options?: { comment?: string; tags?: string[] },
): { closeInfo: IRoomClosingInfo; closeSystemMsgData: IOmniRoomClosingMessage } {
Expand All @@ -315,13 +315,11 @@ export class OmnichannelVoipService extends ServiceClassInternal implements IOmn
): Promise<{ closeInfo: IRoomClosingInfo; closeSystemMsgData: IOmniRoomClosingMessage }> {
const now = new Date();
const closer = isILivechatVisitor(closerParam) ? 'visitor' : 'user';
const callTotalHoldTime = await calculateOnHoldTimeForRoom(room, now);

const closeData: IRoomClosingInfo = {
closedAt: now,
callDuration: now.getTime() - room.ts.getTime(),
closer,
callTotalHoldTime,
closedBy: {
_id: closerParam._id,
username: closerParam.username,
Expand Down

0 comments on commit 2a5b228

Please sign in to comment.