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/utils.ts

62 lines
1.9 KiB

import { ILivechatAgentStatus } from '@rocket.chat/core-typings';
import type { ILivechatAgent, IUser } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';
import type { Filter } from 'mongodb';
import { RoutingManager } from './RoutingManager';
import type { AKeyOf } from './localTypes';
import { callbacks } from '../../../../server/lib/callbacks';
import { notifyOnUserChange } from '../../../lib/server/lib/notifyListener';
import { businessHourManager } from '../business-hour';
export function showConnecting() {
return RoutingManager.getConfig()?.showConnecting || false;
}
export async function setUserStatusLivechat(userId: string, status: ILivechatAgentStatus) {
const user = await Users.setLivechatStatus(userId, status);
// TODO: shouldnt this callback run if the modified count is > 0 too?
callbacks.runAsync('livechat.setUserStatusLivechat', { userId, status });
if (user.modifiedCount > 0) {
void notifyOnUserChange({
id: userId,
clientAction: 'updated',
diff: {
statusLivechat: status,
livechatStatusSystemModified: false,
},
});
}
return user;
}
export async function setUserStatusLivechatIf(
userId: string,
status: ILivechatAgentStatus,
condition?: Filter<IUser>,
fields?: AKeyOf<ILivechatAgent>,
) {
const result = await Users.setLivechatStatusIf(userId, status, condition, fields);
if (result.modifiedCount > 0) {
void notifyOnUserChange({
id: userId,
clientAction: 'updated',
diff: { ...fields, statusLivechat: status },
});
}
// TODO: shouldnt this callback run if the modified count is > 0 too?
callbacks.runAsync('livechat.setUserStatusLivechat', { userId, status });
return result;
}
export async function allowAgentChangeServiceStatus(statusLivechat: ILivechatAgentStatus, agentId: string) {
if (statusLivechat !== ILivechatAgentStatus.AVAILABLE) {
return true;
}
return businessHourManager.allowAgentChangeServiceStatus(agentId);
}