Skip to content

Commit 4ce0038

Browse files
authored
fix: brings back roomName on GET /groups.messages endpoint (#35546)
1 parent c0c91ce commit 4ce0038

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

.changeset/chatty-berries-compare.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rocket.chat/rest-typings': patch
3+
'@rocket.chat/meteor': patch
4+
---
5+
6+
Restores `roomName` property in the `GET /groups.messages` endpoint to fix unintended removal.

apps/meteor/app/api/server/v1/groups.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,13 @@ API.v1.addRoute(
764764
{ authRequired: true, validateParams: isGroupsMessagesProps },
765765
{
766766
async get() {
767-
const { roomId, mentionIds, starredIds, pinned } = this.queryParams;
767+
const { roomId, roomName, mentionIds, starredIds, pinned } = this.queryParams;
768768

769769
const findResult = await findPrivateGroupByIdOrName({
770-
params: { roomId },
770+
params: {
771+
...(roomId && { roomId }),
772+
...(roomName && { roomName }),
773+
},
771774
userId: this.userId,
772775
});
773776
const { offset, count } = await getPaginationItems(this.queryParams);

apps/meteor/tests/end-to-end/api/groups.ts

+37
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,43 @@ describe('[Groups]', () => {
633633
expect(res.body).to.have.property('total', 1);
634634
});
635635
});
636+
637+
it('should return all messages from a group using roomName parameter', async () => {
638+
await request
639+
.get(api('groups.messages'))
640+
.set(credentials)
641+
.query({ roomName: testGroup.name })
642+
.expect('Content-Type', 'application/json')
643+
.expect(200)
644+
.expect((res) => {
645+
expect(res.body).to.have.property('success', true);
646+
expect(res.body).to.have.property('messages').and.to.be.an('array');
647+
expect(res.body.messages).to.have.lengthOf(5);
648+
});
649+
});
650+
651+
it('should return error if both roomId and roomName are provided', async () => {
652+
const thirdGroup = (await createGroup({ name: `test-priority-${Date.now()}` })).body.group;
653+
const secondGroup = (await createGroup({ name: `test-priority-${Date.now()}` })).body.group;
654+
655+
try {
656+
await request
657+
.get(api('groups.messages'))
658+
.set(credentials)
659+
.query({
660+
roomId: thirdGroup._id,
661+
roomName: secondGroup.name,
662+
})
663+
.expect('Content-Type', 'application/json')
664+
.expect(400)
665+
.expect((res) => {
666+
expect(res.body).to.have.property('success', false);
667+
expect(res.body).to.have.property('errorType', 'invalid-params');
668+
});
669+
} finally {
670+
await Promise.all([deleteGroup({ roomName: secondGroup.name }), deleteGroup({ roomName: thirdGroup.name })]);
671+
}
672+
});
636673
});
637674

638675
describe('/groups.invite', async () => {

packages/rest-typings/src/v1/groups/GroupsMessagesProps.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ const ajv = new Ajv({
88
coerceTypes: true,
99
});
1010

11-
export type GroupsMessagesProps = PaginatedRequest<{
12-
roomId: IRoom['_id'];
13-
mentionIds?: string;
14-
starredIds?: string;
15-
pinned?: boolean;
16-
query?: Record<string, any>;
17-
}>;
11+
export type GroupsMessagesProps = PaginatedRequest<
12+
({ roomId: IRoom['_id'] } | { roomName: IRoom['name'] }) & {
13+
mentionIds?: string;
14+
starredIds?: string;
15+
pinned?: boolean;
16+
query?: Record<string, any>;
17+
}
18+
>;
1819

1920
const GroupsMessagesPropsSchema = withGroupBaseProperties({
2021
roomId: {
2122
type: 'string',
2223
},
24+
roomName: {
25+
type: 'string',
26+
},
2327
mentionIds: {
2428
type: 'string',
2529
},

0 commit comments

Comments
 (0)