Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Always show all rooms when requesting chat history, even unserved ones #31904

Merged
merged 8 commits into from
Mar 18, 2024
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
4 changes: 2 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 && { open: { $exists: open } }),
...(served !== undefined && served && { servedBy: { $exists: served } }),
...(source && {
$or: [{ 'source.type': new RegExp(escapeRegExp(source), 'i') }, { 'source.alias': new RegExp(escapeRegExp(source), 'i') }],
}),
Expand Down
83 changes: 83 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,88 @@ 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 () => {
KevLehman marked this conversation as resolved.
Show resolved Hide 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;
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
});
});

it('should return open rooms when closedChatsOnly is false', async () => {
KevLehman marked this conversation as resolved.
Show resolved Hide 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`))
KevLehman marked this conversation as resolved.
Show resolved Hide 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);
KevLehman marked this conversation as resolved.
Show resolved Hide 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');
});
});
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
});

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