Skip to content
Snippets Groups Projects
Commit 859c52a8 authored by Diego Sampaio's avatar Diego Sampaio
Browse files

always use a department if there is only one active

parent 89290120
No related branches found
No related tags found
No related merge requests found
......@@ -93,7 +93,7 @@ class @ChatMessages
showError error.reason
if not Meteor.userId()
Meteor.call 'registerGuest', visitor.getToken(), (error, result) ->
Meteor.call 'livechat:registerGuest', { token: visitor.getToken() }, (error, result) ->
if error?
return showError error.reason
......
......@@ -6,7 +6,7 @@ Template.register.helpers({
return "";
},
hasDepartments() {
return Department.find().count() > 0;
return Department.find().count() > 1;
},
departments() {
return Department.find();
......@@ -22,11 +22,19 @@ Template.register.events({
if (!($name.val().trim() && $email.val().trim())) {
return instance.showError(TAPi18n.__('Please_fill_name_and_email'));
} else {
var departmentId = instance.$('select[name=department]').val();
if (!departmentId) {
var department = Department.findOne();
if (department) {
departmentId = department._id;
}
}
var guest = {
token: visitor.getToken(),
name: $name.val(),
email: $email.val(),
department: instance.$('select[name=department]').val()
department: departmentId
};
Meteor.call('livechat:registerGuest', guest, function(error, result) {
if (error != null) {
......
Meteor.methods({
'livechat:registerGuest': function({ token, name, email, department }) {
'livechat:registerGuest': function({ token, name, email, department } = {}) {
var pass, qt, user, userData, userExists, userId, inc = 0;
check(token, String);
......
......@@ -14,6 +14,15 @@ Meteor.methods({
room = RocketChat.models.Rooms.findOneById(message.rid);
if (room == null) {
// if no department selected verify if there is only one active and use it
if (!guest.department) {
var departments = RocketChat.models.LivechatDepartment.findEnabledWithAgents();
if (departments.count() === 1) {
guest.department = departments.fetch()[0]._id;
}
}
agent = getNextAgent(guest.department);
if (!agent) {
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment