diff --git a/apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx b/apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx index 2f1c90bc1ff0..c43d415caf2c 100644 --- a/apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx +++ b/apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx @@ -296,9 +296,8 @@ export const useQuickActions = (): { }); const omnichannelRouteConfig = useOmnichannelRouteConfig(); - + const manualOnHoldAllowed = useSetting('Livechat_allow_manual_on_hold'); const hasManagerRole = useRole('livechat-manager'); - const roomOpen = room?.open && (room.u?._id === uid || hasManagerRole) && room?.lastMessage?.t !== 'livechat-close'; const canMoveQueue = !!omnichannelRouteConfig?.returnQueue && room?.u !== undefined; const canForwardGuest = usePermission('transfer-livechat-guest'); @@ -309,8 +308,8 @@ export const useQuickActions = (): { const canCloseOthersRoom = usePermission('close-others-livechat-room'); const restrictedOnHold = useSetting('Livechat_allow_manual_on_hold_upon_agent_engagement_only'); const canRoomBePlacedOnHold = !room.onHold && room.u; - const canAgentPlaceOnHold = !room.lastMessage.token; - const canPlaceChatOnHold = canRoomBePlacedOnHold && (!restrictedOnHold || canAgentPlaceOnHold); + const canAgentPlaceOnHold = !room.lastMessage?.token; + const canPlaceChatOnHold = manualOnHoldAllowed && canRoomBePlacedOnHold && (!restrictedOnHold || canAgentPlaceOnHold); const hasPermissionButtons = (id: string): boolean => { switch (id) { diff --git a/apps/meteor/ee/app/livechat-enterprise/server/api/rooms.ts b/apps/meteor/ee/app/livechat-enterprise/server/api/rooms.ts index e6c9311ee82d..57de254acf3c 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/api/rooms.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/api/rooms.ts @@ -15,10 +15,10 @@ API.v1.addRoute( async post() { const { roomId } = this.bodyParams; - type Room = Pick; + type Room = Pick; const room = await LivechatRooms.findOneById(roomId, { - projection: { _id: 1, t: 1, open: 1, onHold: 1, lastMessage: 1, servedBy: 1 }, + projection: { _id: 1, t: 1, open: 1, onHold: 1, u: 1, lastMessage: 1, servedBy: 1 }, }); if (!room) { throw new Error('error-invalid-room'); diff --git a/apps/meteor/ee/app/livechat-enterprise/server/services/omnichannel.internalService.ts b/apps/meteor/ee/app/livechat-enterprise/server/services/omnichannel.internalService.ts index 7c7b0e4261a8..b5ccdeae7700 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/services/omnichannel.internalService.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/services/omnichannel.internalService.ts @@ -8,8 +8,8 @@ import { LivechatRooms, Subscriptions, LivechatInquiry } from '@rocket.chat/mode import { dispatchAgentDelegated } from '../../../../../app/livechat/server/lib/Helper'; import { queueInquiry } from '../../../../../app/livechat/server/lib/QueueManager'; import { RoutingManager } from '../../../../../app/livechat/server/lib/RoutingManager'; +import { settings } from '../../../../../app/settings/server'; import { callbacks } from '../../../../../lib/callbacks'; -import { settings } from '../../../settings/server'; export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelEEService { protected name = 'omnichannel-ee'; @@ -33,11 +33,8 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE const { _id: roomId } = room; const restrictedOnHold = settings.get('Livechat_allow_manual_on_hold_upon_agent_engagement_only'); const canRoomBePlacedOnHold = !room.onHold; - const canAgentPlaceOnHold = !room.lastMessage.token; + const canAgentPlaceOnHold = !room.lastMessage?.token; const canPlaceChatOnHold = canRoomBePlacedOnHold && (!restrictedOnHold || canAgentPlaceOnHold); - if (!canPlaceChatOnHold) { - throw new Error('error-contact-sent-last-message-so-cannot-place-on-hold'); - } if (!room || !isOmnichannelRoom(room)) { throw new Error('error-invalid-room'); @@ -48,7 +45,9 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE if (room.onHold) { throw new Error('error-room-is-already-on-hold'); } - + if (!canPlaceChatOnHold) { + throw new Error('error-contact-sent-last-message-so-cannot-place-on-hold'); + } if (!room.servedBy) { throw new Error('error-unserved-rooms-cannot-be-placed-onhold'); } @@ -60,8 +59,6 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE ]); await callbacks.run('livechat:afterOnHold', room); - - this.logger.debug(`Room ${room._id} set on hold successfully`); } async resumeRoomOnHold( @@ -111,8 +108,6 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE ]); await callbacks.run('livechat:afterOnHoldChatResumed', room); - - this.logger.debug(`Room ${room._id} resumed successfully`); } private async attemptToAssignRoomToServingAgentElseQueueIt({ @@ -140,7 +135,7 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE return; } catch (e) { - this.logger.debug(`Agent ${servingAgent._id} is not available to take the inquiry ${inquiry._id}`, e); + this.logger.error(`Agent ${servingAgent._id} is not available to take the inquiry ${inquiry._id}`, e); if (clientAction) { // if the action was triggered by the client, we should throw the error // so the client can handle it and show the error message to the user @@ -148,20 +143,15 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE } } - this.logger.debug(`Attempting to queue inquiry ${inquiry._id}`); - await this.removeCurrentAgentFromRoom({ room, inquiry }); const { _id: inquiryId } = inquiry; const newInquiry = await LivechatInquiry.findOneById(inquiryId); if (!newInquiry) { - this.logger.error(`No inquiry found for id ${inquiryId}`); throw new Error('error-invalid-inquiry'); } await queueInquiry(newInquiry); - - this.logger.debug('Room queued successfully'); } private async removeCurrentAgentFromRoom({ @@ -184,7 +174,5 @@ export class OmnichannelEE extends ServiceClassInternal implements IOmnichannelE ]); await dispatchAgentDelegated(roomId); - - this.logger.debug(`Current agent removed from room ${room._id} successfully`); } }