-
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.
chore: remove references to EE code from livechat business hour featu…
…re (#32006)
- Loading branch information
1 parent
66b070e
commit e90954e
Showing
7 changed files
with
84 additions
and
59 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
25 changes: 25 additions & 0 deletions
25
apps/meteor/app/livechat/server/business-hour/closeBusinessHour.ts
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,25 @@ | ||
import type { ILivechatBusinessHour, IUser } from '@rocket.chat/core-typings'; | ||
import { Users } from '@rocket.chat/models'; | ||
import { makeFunction } from '@rocket.chat/patch-injection'; | ||
|
||
import { businessHourLogger } from '../lib/logger'; | ||
import { getAgentIdsForBusinessHour } from './getAgentIdsForBusinessHour'; | ||
|
||
export const closeBusinessHourByAgentIds = async ( | ||
businessHourId: ILivechatBusinessHour['_id'], | ||
agentIds: IUser['_id'][], | ||
): Promise<void> => { | ||
businessHourLogger.debug({ | ||
msg: 'Closing business hour', | ||
businessHour: businessHourId, | ||
totalAgents: agentIds.length, | ||
top10AgentIds: agentIds.slice(0, 10), | ||
}); | ||
await Users.removeBusinessHourByAgentIds(agentIds, businessHourId); | ||
await Users.updateLivechatStatusBasedOnBusinessHours(); | ||
}; | ||
|
||
export const closeBusinessHour = makeFunction(async (businessHour: Pick<ILivechatBusinessHour, '_id' | 'type'>): Promise<void> => { | ||
const agentIds = await getAgentIdsForBusinessHour(); | ||
return closeBusinessHourByAgentIds(businessHour._id, agentIds); | ||
}); |
45 changes: 45 additions & 0 deletions
45
apps/meteor/app/livechat/server/business-hour/getAgentIdsForBusinessHour.ts
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,45 @@ | ||
import type { IUser } from '@rocket.chat/core-typings'; | ||
import { LivechatDepartment, LivechatDepartmentAgents, Users } from '@rocket.chat/models'; | ||
|
||
const getAllAgentIdsWithoutDepartment = async (): Promise<string[]> => { | ||
// Fetch departments with agents excluding archived ones (disabled ones still can be tied to business hours) | ||
// Then find the agents that are not in any of those departments | ||
|
||
const departmentIds = (await LivechatDepartment.findNotArchived({ projection: { _id: 1 } }).toArray()).map(({ _id }) => _id); | ||
|
||
const agentIdsWithDepartment = await LivechatDepartmentAgents.findAllAgentsConnectedToListOfDepartments(departmentIds); | ||
|
||
const agentIdsWithoutDepartment = ( | ||
await Users.findUsersInRolesWithQuery( | ||
'livechat-agent', | ||
{ | ||
_id: { $nin: agentIdsWithDepartment }, | ||
}, | ||
{ projection: { _id: 1 } }, | ||
).toArray() | ||
).map((user) => user._id); | ||
|
||
return agentIdsWithoutDepartment; | ||
}; | ||
|
||
const getAllAgentIdsWithDepartmentNotConnectedToBusinessHour = async (): Promise<string[]> => { | ||
const activeDepartmentsWithoutBusinessHour = ( | ||
await LivechatDepartment.findActiveDepartmentsWithoutBusinessHour({ | ||
projection: { _id: 1 }, | ||
}).toArray() | ||
).map((dept) => dept._id); | ||
|
||
const agentIdsWithDepartmentNotConnectedToBusinessHour = await LivechatDepartmentAgents.findAllAgentsConnectedToListOfDepartments( | ||
activeDepartmentsWithoutBusinessHour, | ||
); | ||
return agentIdsWithDepartmentNotConnectedToBusinessHour; | ||
}; | ||
|
||
export const getAgentIdsForBusinessHour = async (): Promise<IUser['_id'][]> => { | ||
const [withoutDepartment, withDepartmentNotConnectedToBusinessHour] = await Promise.all([ | ||
getAllAgentIdsWithoutDepartment(), | ||
getAllAgentIdsWithDepartmentNotConnectedToBusinessHour(), | ||
]); | ||
|
||
return [...new Set([...withoutDepartment, ...withDepartmentNotConnectedToBusinessHour])]; | ||
}; |
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,7 @@ | ||
import { closeBusinessHour, closeBusinessHourByAgentIds } from '../../../app/livechat/server/business-hour/closeBusinessHour'; | ||
import { getAgentIdsToHandle } from '../../app/livechat-enterprise/server/business-hour/Helper'; | ||
|
||
closeBusinessHour.patch(async (_next, businessHour) => { | ||
const agentIds = await getAgentIdsToHandle(businessHour); | ||
return closeBusinessHourByAgentIds(businessHour._id, agentIds); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import './closeBusinessHour'; | ||
import './getInstanceList'; | ||
import './isDepartmentCreationAvailable'; |