-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Omnichannel MAC limitations (#30463)
- Loading branch information
Showing
47 changed files
with
451 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@rocket.chat/meteor": patch | ||
"@rocket.chat/core-services": patch | ||
"@rocket.chat/core-typings": patch | ||
"@rocket.chat/rest-typings": patch | ||
"@rocket.chat/ddp-client": patch | ||
--- | ||
|
||
feat: Improve UI when MAC limits are reached | ||
feat: Limit endpoints on MAC limit reached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Omnichannel } from '@rocket.chat/core-services'; | ||
import type { IOmnichannelRoom } from '@rocket.chat/core-typings'; | ||
import { isEditedMessage } from '@rocket.chat/core-typings'; | ||
|
||
import { callbacks } from '../../../../lib/callbacks'; | ||
|
||
callbacks.add('beforeSaveMessage', async (message, room) => { | ||
if (!room || room.t !== 'l') { | ||
return message; | ||
} | ||
|
||
if (isEditedMessage(message)) { | ||
return message; | ||
} | ||
|
||
if (message.token) { | ||
return message; | ||
} | ||
|
||
if (message.t) { | ||
return message; | ||
} | ||
|
||
const canSendMessage = await Omnichannel.isWithinMACLimit(room as IOmnichannelRoom); | ||
if (!canSendMessage) { | ||
throw new Error('error-mac-limit-reached'); | ||
} | ||
|
||
return message; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useOmnichannel } from './useOmnichannel'; | ||
|
||
export const useIsOverMacLimit = (): boolean => { | ||
const { isOverMacLimit } = useOmnichannel(); | ||
return isOverMacLimit; | ||
}; |
23 changes: 23 additions & 0 deletions
23
apps/meteor/client/hooks/omnichannel/useIsRoomOverMacLimit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { IRoom } from '@rocket.chat/core-typings'; | ||
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(); | ||
|
||
if (!isOmnichannelRoom(room) && !isVoipRoom(room)) { | ||
return false; | ||
} | ||
|
||
if (!room.open) { | ||
return false; | ||
} | ||
|
||
const { v: { activity = [] } = {} } = room as IOmnichannelGenericRoom; | ||
|
||
const currentPeriod = getPeriod(new Date()); | ||
return isOverMacLimit && !activity.includes(currentPeriod); | ||
}; |
Oops, something went wrong.