Skip to content

Commit

Permalink
Fixed for API
Browse files Browse the repository at this point in the history
  • Loading branch information
knrt10 committed Mar 17, 2019
1 parent 2992a94 commit 446704b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
4 changes: 4 additions & 0 deletions app/livechat/server/api/v1/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ API.v1.addRoute('livechat/message', {
throw new Meteor.Error('invalid-room');
}

if (room && !room.open) {
throw new Meteor.Error('chat-closed');
}

const _id = this.bodyParams._id || Random.id();

const sendMessage = {
Expand Down
14 changes: 1 addition & 13 deletions app/livechat/server/methods/sendMessageLivechat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { LivechatVisitors, Rooms } from '../../../models';
import { LivechatVisitors } from '../../../models';
import { Livechat } from '../lib/Livechat';

Meteor.methods({
Expand All @@ -24,22 +24,10 @@ Meteor.methods({
},
});

const fields = {
t: 1,
closedAt: 1,
open: 1,
};

if (!guest) {
throw new Meteor.Error('invalid-token');
}

// Check if conversation is closed or not.
const closed = Rooms.findOneLivechatById(rid, fields);
if (closed && closed.closedAt) {
throw new Meteor.Error('chat-closed');
}

return Livechat.sendMessage({
guest,
message: {
Expand Down
15 changes: 0 additions & 15 deletions app/models/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,6 @@ export class Rooms extends Base {
return this.find(query, options);
}

findOneLivechatById(_id, fields) {
const options = {};

if (fields) {
options.fields = fields;
}

const query = {
t: 'l',
_id,
};

return this.findOne(query, options);
}

findLivechatByIdAndVisitorToken(_id, visitorToken, fields) {
const options = {};

Expand Down

0 comments on commit 446704b

Please sign in to comment.