The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/livechat/server/lib/conditionalLockAgent.ts

35 lines
802 B

import { Users } from '@rocket.chat/models';
import { settings } from '../../../settings/server';
type LockResult = {
acquired: boolean;
required: boolean;
unlock: () => Promise<void>;
};
export async function conditionalLockAgent(agentId: string): Promise<LockResult> {
// Lock and chats limits enforcement are only required when waiting_queue is enabled
const shouldLock = settings.get<boolean>('Livechat_waiting_queue');
if (!shouldLock) {
return {
acquired: false,
required: false,
unlock: async () => {
// no-op
},
};
}
const lockTime = new Date();
const lockAcquired = await Users.acquireAgentLock(agentId, lockTime);
return {
acquired: !!lockAcquired,
required: true,
unlock: async () => {
await Users.releaseAgentLock(agentId, lockTime);
},
};
}