Fix visitor ending livechat if multiples still open (#6419)

Close #6416
pull/6277/head
Diego Sampaio 9 years ago committed by Rodrigo Nascimento
parent 914e260d05
commit a32eb12593
  1. 2
      packages/rocketchat-livechat/app/client/views/options.js
  2. 4
      packages/rocketchat-livechat/server/methods/closeByVisitor.js
  3. 3
      packages/rocketchat-livechat/server/models/Rooms.js

@ -11,7 +11,7 @@ Template.options.events({
closeOnConfirm: false,
html: false
}, () => {
Meteor.call('livechat:closeByVisitor', (error) => {
Meteor.call('livechat:closeByVisitor', visitor.getRoom(), (error) => {
if (error) {
return console.log('Error ->', error);
}

@ -1,10 +1,10 @@
Meteor.methods({
'livechat:closeByVisitor'() {
'livechat:closeByVisitor'(roomId) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'livechat:closeByVisitor' });
}
const room = RocketChat.models.Rooms.findOneOpenByVisitorId(Meteor.userId());
const room = RocketChat.models.Rooms.findOneOpenByVisitorId(Meteor.userId(), roomId);
if (!room || !room.open) {
return false;

@ -115,8 +115,9 @@ RocketChat.models.Rooms.findByVisitorId = function(visitorId) {
return this.find(query);
};
RocketChat.models.Rooms.findOneOpenByVisitorId = function(visitorId) {
RocketChat.models.Rooms.findOneOpenByVisitorId = function(visitorId, roomId) {
const query = {
_id: roomId,
open: true,
'v._id': visitorId
};

Loading…
Cancel
Save