Skip to content

Commit

Permalink
refactored useIsRoomOverMacLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Oct 25, 2023
1 parent 22165bf commit 95fc6ec
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions apps/meteor/client/hooks/omnichannel/useIsRoomOverMacLimit.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { type IOmnichannelGenericRoom } from '@rocket.chat/core-typings';
import { useMemo } from 'react';
import { isOmnichannelRoom, type IOmnichannelGenericRoom, isVoipRoom } from '@rocket.chat/core-typings';

import { useIsOverMacLimit } from './useIsOverMacLimit';

const getPeriod = (date: Date) => `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;

export const useIsRoomOverMacLimit = (room: IRoom) => {
const isOverMacLimit = useIsOverMacLimit();
const { v: { activity = [] } = {}, t: roomType, open } = room as IOmnichannelGenericRoom;

const isContactActive = useMemo(() => {
if (!['l', 'v'].includes(roomType) || !open) {
return true;
}
if (!isOmnichannelRoom(room) && !isVoipRoom(room)) {
return false;
}

const currentPeriod = getPeriod(new Date());
return !isOverMacLimit || activity.includes(currentPeriod);
}, [activity, isOverMacLimit, open, roomType]);
if (!room.open) {
return false;
}

return !isContactActive;
const { v: { activity = [] } = {} } = room as IOmnichannelGenericRoom;

const currentPeriod = getPeriod(new Date());
return isOverMacLimit && !activity.includes(currentPeriod);
};

0 comments on commit 95fc6ec

Please sign in to comment.