Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spotty-students-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: Show always all rooms when requesting chat history, even unserved ones. A faulty condition caused an issue where chat history was only able to present either served or unserved chats at once, without a proper way to get both. Now, the Chat history feature will showcase all closed rooms for the requested visitor.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const useHistoryList = (
const { history, total } = await getHistory({
...(options.filter && { searchText: options.filter }),
closedChatsOnly: 'true',
servedChatsOnly: 'true',
servedChatsOnly: 'false',
offset: start,
count: end + start,
});
Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/server/models/raw/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,8 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
const match: Document = {
$match: {
'v._id': visitorId,
...(open !== undefined && { open: { $exists: open } }),
...(served !== undefined && { servedBy: { $exists: served } }),
...(open !== undefined && !open && { closedAt: { $exists: true } }),
Comment thread
KevLehman marked this conversation as resolved.
Resolved
...(served !== undefined && served && { servedBy: { $exists: served } }),
...(source && {
$or: [{ 'source.type': new RegExp(escapeRegExp(source), 'i') }, { 'source.alias': new RegExp(escapeRegExp(source), 'i') }],
}),
Expand Down Expand Up @@ -1196,6 +1196,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
params.push({ $limit: options.limit });
}

console.log(JSON.stringify(params, null, 2));
Comment thread
KevLehman marked this conversation as resolved.
Resolved
return this.col.aggregate(params, { readPreference: readSecondaryPreferred() });
}

Expand Down
104 changes: 104 additions & 0 deletions apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
createLivechatRoom,
createVisitor,
startANewLivechatRoomAndTakeIt,
closeOmnichannelRoom,
} from '../../../data/livechat/rooms';
import { getRandomVisitorToken } from '../../../data/livechat/users';
import { getLivechatVisitorByToken } from '../../../data/livechat/visitor';
Expand Down Expand Up @@ -590,6 +591,109 @@ describe('LIVECHAT - visitors', function () {
expect(res.body.history[0]).to.have.property('v');
});
});

it('should return only closed chats when closedChatsOnly is true', async () => {
const {
room: { _id: roomId },
visitor: { _id: visitorId },
} = await startANewLivechatRoomAndTakeIt();

await closeOmnichannelRoom(roomId);

await request
.get(api(`livechat/visitors.searchChats/room/${roomId}/visitor/${visitorId}?closedChatsOnly=true&servedChatsOnly=false`))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res: Response) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('history');
expect(res.body.history).to.be.an('array');
expect(res.body.history.find((chat: any) => chat._id === roomId)).to.be.an('object');
});
});

it('should return only served chats when servedChatsOnly is true', async () => {
Comment thread
KevLehman marked this conversation as resolved.
Resolved
const visitor = await createVisitor();
const room = await createLivechatRoom(visitor.token);

await request
.get(api(`livechat/visitors.searchChats/room/${room._id}/visitor/${visitor._id}?closedChatsOnly=false&servedChatsOnly=true`))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res: Response) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('history');
expect(res.body.history).to.be.an('array');
expect(res.body.history.find((chat: any) => chat._id === room._id)).to.be.undefined;
Comment thread
KevLehman marked this conversation as resolved.
Resolved
});
});

it('should return open rooms when closedChatsOnly is false', async () => {
Comment thread
KevLehman marked this conversation as resolved.
Resolved
const {
room: { _id: roomId },
visitor: { _id: visitorId, token },
} = await startANewLivechatRoomAndTakeIt();
await closeOmnichannelRoom(roomId);
const room2 = await createLivechatRoom(token);
await closeOmnichannelRoom(room2._id);

await request
.get(api(`livechat/visitors.searchChats/room/${roomId}/visitor/${visitorId}?closedChatsOnly=true&servedChatsOnly=false`))
Comment thread
KevLehman marked this conversation as resolved.
Resolved
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res: Response) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('history');
expect(res.body.history).to.be.an('array');
expect(res.body.history.find((chat: any) => chat._id === roomId)).to.be.an('object');
expect(res.body.history.find((chat: any) => chat._id === room2._id)).to.be.an('object');
});
});

it('should return all closed chats (even unserved ones) when closedChatsOnly is true & servedChatsOnly is false', async () => {
const visitor = await createVisitor();
const room = await createLivechatRoom(visitor.token);
await closeOmnichannelRoom(room._id);
const room2 = await createLivechatRoom(visitor.token);
Comment thread
KevLehman marked this conversation as resolved.
Resolved
await closeOmnichannelRoom(room2._id);

await request
.get(api(`livechat/visitors.searchChats/room/${room._id}/visitor/${visitor._id}?closedChatsOnly=true&servedChatsOnly=false`))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res: Response) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('history');
expect(res.body.history).to.be.an('array');
expect(res.body.history.find((chat: any) => chat._id === room._id)).to.be.an('object');
expect(res.body.history.find((chat: any) => chat._id === room2._id)).to.be.an('object');
});
});
Comment thread
KevLehman marked this conversation as resolved.
Resolved

it('should return all chats when both closed & served flags are false', async () => {
const visitor = await createVisitor();
const room = await createLivechatRoom(visitor.token);
await closeOmnichannelRoom(room._id);
const room2 = await createLivechatRoom(visitor.token);
await closeOmnichannelRoom(room2._id);
await createLivechatRoom(visitor.token);

const { body } = await request
.get(api(`livechat/visitors.searchChats/room/${room._id}/visitor/${visitor._id}?closedChatsOnly=false&servedChatsOnly=false`))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200);

expect(body).to.have.property('success', true);
expect(body.count).to.be.equal(3);
expect(body.history.filter((chat: any) => !!chat.closedAt).length === 2).to.be.true;
expect(body.history.filter((chat: any) => !chat.closedAt).length === 1).to.be.true;
Comment thread
KevLehman marked this conversation as resolved.
Resolved
expect(body.total).to.be.equal(3);
});
});

describe('livechat/visitor.status', () => {
Expand Down