|
|
|
|
@ -29,7 +29,7 @@ import { RoutingManager } from './RoutingManager'; |
|
|
|
|
import { Analytics } from './Analytics'; |
|
|
|
|
import { settings } from '../../../settings/server'; |
|
|
|
|
import { callbacks } from '../../../../lib/callbacks'; |
|
|
|
|
import { Users, Messages, Subscriptions, LivechatDepartment } from '../../../models/server'; |
|
|
|
|
import { Users, Messages, Subscriptions } from '../../../models/server'; |
|
|
|
|
import { Logger } from '../../../logger/server'; |
|
|
|
|
import { hasRoleAsync } from '../../../authorization/server/functions/hasRole'; |
|
|
|
|
import { canAccessRoomAsync, roomAccessAttributes } from '../../../authorization/server'; |
|
|
|
|
@ -126,7 +126,7 @@ export const Livechat = { |
|
|
|
|
return onlineForDep; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const dep = LivechatDepartment.findOneById(department); |
|
|
|
|
const dep = await LivechatDepartmentRaw.findOneById(department); |
|
|
|
|
if (!dep?.fallbackForwardDepartment) { |
|
|
|
|
return onlineForDep; |
|
|
|
|
} |
|
|
|
|
@ -146,9 +146,9 @@ export const Livechat = { |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
async getRequiredDepartment(onlineRequired = true) { |
|
|
|
|
const departments = LivechatDepartment.findEnabledWithAgents(); |
|
|
|
|
const departments = await LivechatDepartmentRaw.findEnabledWithAgents(); |
|
|
|
|
|
|
|
|
|
for await (const dept of departments.fetch()) { |
|
|
|
|
for await (const dept of departments) { |
|
|
|
|
if (!dept.showOnRegistration) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
@ -177,7 +177,7 @@ export const Livechat = { |
|
|
|
|
room = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (guest.department && !LivechatDepartment.findOneById(guest.department)) { |
|
|
|
|
if (guest.department && !(await LivechatDepartmentRaw.findOneById(guest.department))) { |
|
|
|
|
await LivechatVisitors.removeDepartmentById(guest._id); |
|
|
|
|
guest = await LivechatVisitors.findOneById(guest._id); |
|
|
|
|
} |
|
|
|
|
@ -315,7 +315,7 @@ export const Livechat = { |
|
|
|
|
|
|
|
|
|
if (department) { |
|
|
|
|
Livechat.logger.debug(`Attempt to find a department with id/name ${department}`); |
|
|
|
|
const dep = LivechatDepartment.findOneByIdOrName(department); |
|
|
|
|
const dep = await LivechatDepartmentRaw.findOneByIdOrName(department); |
|
|
|
|
if (!dep) { |
|
|
|
|
Livechat.logger.debug('Invalid department provided'); |
|
|
|
|
throw new Meteor.Error('error-invalid-department', 'The provided department is invalid', { |
|
|
|
|
@ -383,7 +383,7 @@ export const Livechat = { |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const dep = LivechatDepartment.findOneById(department); |
|
|
|
|
const dep = await LivechatDepartmentRaw.findOneById(department); |
|
|
|
|
if (!dep) { |
|
|
|
|
throw new Meteor.Error('invalid-department', 'Provided department does not exists', { |
|
|
|
|
method: 'setDepartmentForGuest', |
|
|
|
|
@ -713,8 +713,8 @@ export const Livechat = { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (transferData.departmentId) { |
|
|
|
|
transferData.department = LivechatDepartment.findOneById(transferData.departmentId, { |
|
|
|
|
fields: { name: 1 }, |
|
|
|
|
transferData.department = await LivechatDepartmentRaw.findOneById(transferData.departmentId, { |
|
|
|
|
projection: { name: 1 }, |
|
|
|
|
}); |
|
|
|
|
Livechat.logger.debug(`Transfering room ${room._id} to department ${transferData.department?._id}`); |
|
|
|
|
} |
|
|
|
|
@ -1009,7 +1009,7 @@ export const Livechat = { |
|
|
|
|
]), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const department = LivechatDepartment.findOneById(_id); |
|
|
|
|
const department = await LivechatDepartmentRaw.findOneById(_id); |
|
|
|
|
if (!department) { |
|
|
|
|
throw new Meteor.Error('error-department-not-found', 'Department not found', { |
|
|
|
|
method: 'livechat:saveDepartmentAgents', |
|
|
|
|
@ -1032,7 +1032,7 @@ export const Livechat = { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Users.setLivechatData(_id, agentData); |
|
|
|
|
await LivechatDepartment.saveDepartmentsByAgent(user, agentDepartments); |
|
|
|
|
await LivechatDepartmentRaw.saveDepartmentsByAgent(user, agentDepartments); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
}, |
|
|
|
|
@ -1051,17 +1051,17 @@ export const Livechat = { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const department = LivechatDepartment.findOneById(_id, { projection: { _id: 1 } }); |
|
|
|
|
const department = await LivechatDepartmentRaw.findOneById(_id, { projection: { _id: 1 } }); |
|
|
|
|
|
|
|
|
|
if (!department) { |
|
|
|
|
throw new Meteor.Error('department-not-found', 'Department not found', { |
|
|
|
|
method: 'livechat:removeDepartment', |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
const ret = LivechatDepartment.removeById(_id); |
|
|
|
|
const ret = (await LivechatDepartmentRaw.removeById(_id)).deletedCount; |
|
|
|
|
const agentsIds = (await LivechatDepartmentAgents.findByDepartmentId(_id).toArray()).map((agent) => agent.agentId); |
|
|
|
|
await LivechatDepartmentAgents.removeByDepartmentId(_id); |
|
|
|
|
LivechatDepartment.unsetFallbackDepartmentByDepartmentId(_id); |
|
|
|
|
await LivechatDepartmentRaw.unsetFallbackDepartmentByDepartmentId(_id); |
|
|
|
|
if (ret) { |
|
|
|
|
Meteor.defer(() => { |
|
|
|
|
callbacks.run('livechat.afterRemoveDepartment', { department, agentsIds }); |
|
|
|
|
@ -1181,7 +1181,7 @@ export const Livechat = { |
|
|
|
|
await LivechatRooms.updateVisitorStatus(token, status); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
sendOfflineMessage(data = {}) { |
|
|
|
|
async sendOfflineMessage(data = {}) { |
|
|
|
|
if (!settings.get('Livechat_display_offline_form')) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
@ -1220,7 +1220,7 @@ export const Livechat = { |
|
|
|
|
|
|
|
|
|
let emailTo = settings.get('Livechat_offline_email'); |
|
|
|
|
if (department && department !== '') { |
|
|
|
|
const dep = LivechatDepartment.findOneByIdOrName(department); |
|
|
|
|
const dep = await LivechatDepartmentRaw.findOneByIdOrName(department); |
|
|
|
|
emailTo = dep.email || emailTo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|