[IMPROVE] Return open room if available for visitors (#22742)

* Try to find an open room for the visitor before requesting a new one

* Update endpoint to use provided department to create the room if not found

* Check if visitor has an open room before creating a new one.

Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com>
pull/22766/head^2
Kevin Aleman 5 years ago committed by GitHub
parent 9b01f97618
commit f7c9bec004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      app/livechat/server/api/v1/room.js

@ -22,14 +22,20 @@ API.v1.addRoute('livechat/room', {
const extraCheckParams = onCheckRoomParams(defaultCheckParams);
try {
check(this.queryParams, extraCheckParams);
check(this.queryParams, extraCheckParams);
const { token, rid: roomId, agentId, ...extraParams } = this.queryParams;
const { token, rid: roomId, agentId, ...extraParams } = this.queryParams;
const guest = findGuest(token);
if (!guest) {
throw new Meteor.Error('invalid-token');
const guest = findGuest(token);
if (!guest) {
throw new Meteor.Error('invalid-token');
}
let room;
if (!roomId) {
room = LivechatRooms.findOneOpenByVisitorToken(token, {});
if (room) {
return API.v1.success({ room, newRoom: false });
}
let agent;
@ -39,13 +45,17 @@ API.v1.addRoute('livechat/room', {
agent = { agentId, username };
}
const rid = roomId || Random.id();
const room = Promise.await(getRoom({ guest, rid, agent, extraParams }));
const rid = Random.id();
room = Promise.await(getRoom({ guest, rid, agent, extraParams }));
return API.v1.success(room);
} catch (e) {
return API.v1.failure(e);
}
room = LivechatRooms.findOneOpenByRoomIdAndVisitorToken(roomId, token, {});
if (!room) {
throw new Meteor.Error('invalid-room');
}
return API.v1.success({ room, newRoom: false });
},
});

Loading…
Cancel
Save