Skip to content

Commit 5f4b7b0

Browse files
committed
add subscription information to im.members
1 parent 13d1707 commit 5f4b7b0

File tree

2 files changed

+19
-3
lines changed
  • apps/meteor/app/api/server/v1
  • packages/rest-typings/src/v1/dm

2 files changed

+19
-3
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,23 @@ API.v1.addRoute(
416416

417417
const [members, total] = await Promise.all([cursor.toArray(), totalCount]);
418418

419+
// find subscriptions of those users
420+
const subs = await Subscriptions.findByRoomIdAndUserIds(
421+
room._id,
422+
members.map((member) => member._id),
423+
{ projection: { u: 1, status: 1, ts: 1, roles: 1 } },
424+
).toArray();
425+
426+
const membersWithSubscriptionInfo = members.map((member) => {
427+
const subscription = subs.find((sub) => sub.u._id === member._id);
428+
return {
429+
...member,
430+
subscription,
431+
};
432+
});
433+
419434
return API.v1.success({
420-
members,
435+
members: membersWithSubscriptionInfo,
421436
count: members.length,
422437
offset,
423438
total,

packages/rest-typings/src/v1/dm/im.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IMessage, IRoom, IUser, IUploadWithUser } from '@rocket.chat/core-typings';
1+
import type { IMessage, IRoom, IUser, IUploadWithUser, ISubscription } from '@rocket.chat/core-typings';
22

33
import type { DmCloseProps } from './DmCloseProps';
44
import type { DmCreateProps } from './DmCreateProps';
@@ -49,7 +49,8 @@ export type ImEndpoints = {
4949

5050
'/v1/im.members': {
5151
GET: (params: DmMemberProps) => PaginatedResult<{
52-
members: Pick<IUser, '_id' | 'status' | 'name' | 'username' | 'utcOffset'>[];
52+
members: Pick<IUser, '_id' | 'status' | 'name' | 'username' | 'utcOffset'> &
53+
{ subscription: Pick<ISubscription, '_id' | 'status' | 'ts' | 'roles'> }[];
5354
}>;
5455
};
5556
'/v1/im.messages': {

0 commit comments

Comments
 (0)