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/packages/rocketchat-livechat/server/methods/getInitialData.js

56 lines
1.2 KiB

Meteor.methods({
'livechat:getInitialData'(visitorToken) {
var info = {
enabled: null,
title: null,
color: null,
registrationForm: null,
room: null,
triggers: [],
departments: []
};
const room = RocketChat.models.Rooms.findOpenByVisitorToken(visitorToken, {
fields: {
name: 1,
t: 1,
cl: 1,
u: 1,
usernames: 1,
v: 1
}
}).fetch();
if (room && room.length > 0) {
info.room = room[0];
}
RocketChat.models.Settings.findNotHiddenPublic([
'Livechat_title',
'Livechat_title_color',
'Livechat_enabled',
'Livechat_registration_form'
]).forEach((setting) => {
if (setting._id === 'Livechat_title') {
info.title = setting.value;
} else if (setting._id === 'Livechat_title_color') {
info.color = setting.value;
} else if (setting._id === 'Livechat_enabled') {
info.enabled = setting.value;
} else if (setting._id === 'Livechat_registration_form') {
info.registrationForm = setting.value;
}
});
RocketChat.models.LivechatTrigger.find().forEach((trigger) => {
info.triggers.push(trigger);
});
RocketChat.models.LivechatDepartment.findEnabledWithAgents().forEach((department) => {
info.departments.push(department);
});
return info;
}
});