Skip to content

Commit

Permalink
Fix visitor ending livechat if multiples still open (#6419)
Browse files Browse the repository at this point in the history
Close #6416
  • Loading branch information
sampaiodiego authored and rodrigok committed Mar 23, 2017
1 parent 914e260 commit a32eb12
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/app/client/views/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-livechat/server/methods/closeByVisitor.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-livechat/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit a32eb12

Please sign in to comment.