diff --git a/app/definitions/rest/v1/channels.ts b/app/definitions/rest/v1/channels.ts index 8bca5f1d6..42b3edac5 100644 --- a/app/definitions/rest/v1/channels.ts +++ b/app/definitions/rest/v1/channels.ts @@ -4,6 +4,7 @@ import type { IServerRoom } from '../../IRoom'; import type { IUser } from '../../IUser'; import { IGetRoomRoles } from '../../IRole'; import { IServerAttachment } from '../../IAttachment'; +import { PaginatedRequest } from '../helpers/PaginatedRequest'; export type ChannelsEndpoints = { 'channels.files': { @@ -15,12 +16,15 @@ export type ChannelsEndpoints = { }; }; 'channels.members': { - GET: (params: { roomId: IServerRoom['_id']; offset?: number; count?: number; filter?: string; status?: string[] }) => { - count: number; - offset: number; + GET: (params: { + roomId: IServerRoom['_id']; + offset?: number; + count?: number; + filter?: boolean; + status?: string[]; + }) => PaginatedRequest<{ members: IUser[]; - total: number; - }; + }>; }; 'channels.history': { GET: (params: { roomId: string; count: number; latest?: string }) => { diff --git a/app/definitions/rest/v1/groups.ts b/app/definitions/rest/v1/groups.ts index d22dabfc5..94a60959f 100644 --- a/app/definitions/rest/v1/groups.ts +++ b/app/definitions/rest/v1/groups.ts @@ -4,6 +4,7 @@ import type { IServerRoom } from '../../IRoom'; import type { IUser } from '../../IUser'; import { IGetRoomRoles } from '../../IRole'; import { IServerAttachment } from '../../IAttachment'; +import { PaginatedRequest } from '../helpers/PaginatedRequest'; export type GroupsEndpoints = { 'groups.files': { @@ -15,12 +16,15 @@ export type GroupsEndpoints = { }; }; 'groups.members': { - GET: (params: { roomId: IServerRoom['_id']; offset?: number; count?: number; filter?: string; status?: string[] }) => { - count: number; - offset: number; + GET: (params: { + roomId: IServerRoom['_id']; + offset?: number; + count?: number; + filter?: string; + status?: string[]; + }) => PaginatedRequest<{ members: IUser[]; - total: number; - }; + }>; }; 'groups.history': { GET: (params: { roomId: string; count: number; latest?: string }) => { diff --git a/app/definitions/rest/v1/im.ts b/app/definitions/rest/v1/im.ts index 2383fe503..2ad403c55 100644 --- a/app/definitions/rest/v1/im.ts +++ b/app/definitions/rest/v1/im.ts @@ -2,6 +2,7 @@ import type { IMessageFromServer } from '../../IMessage'; import type { IServerRoom, RoomID, RoomType } from '../../IRoom'; import type { IUser } from '../../IUser'; import { IServerAttachment } from '../../IAttachment'; +import { PaginatedRequest } from '../helpers/PaginatedRequest'; export type ImEndpoints = { 'im.create': { @@ -34,12 +35,15 @@ export type ImEndpoints = { }; }; 'im.members': { - GET: (params: { roomId: IServerRoom['_id']; offset?: number; count?: number; filter?: string; status?: string[] }) => { - count: number; - offset: number; + GET: (params: { + roomId: IServerRoom['_id']; + offset?: number; + count?: number; + filter?: string; + status?: string[]; + }) => PaginatedRequest<{ members: IUser[]; - total: number; - }; + }>; }; 'im.history': { GET: (params: { roomId: string; count: number; latest?: string }) => { diff --git a/app/lib/rocketchat/rocketchat.js b/app/lib/rocketchat/rocketchat.js index eb94a3f71..d4fecd1e3 100644 --- a/app/lib/rocketchat/rocketchat.js +++ b/app/lib/rocketchat/rocketchat.js @@ -309,24 +309,6 @@ const RocketChat = { return sdk.onStreamData(...args); }, toggleFavorite, - async getRoomMembers({ rid, allUsers, roomType, type, filter, skip = 0, limit = 10 }) { - const serverVersion = reduxStore.getState().server.version; - if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.16.0')) { - const params = { - roomId: rid, - offset: skip, - count: limit, - ...(type !== 'all' && { 'status[]': type }), - ...(filter && { filter }) - }; - // RC 3.16.0 - const result = await sdk.get(`${this.roomTypeToApiType(roomType)}.members`, params); - return result?.members; - } - // RC 0.42.0 - const result = await this.methodCallWrapper('getUsersOfRoom', rid, allUsers, { skip, limit }); - return result?.records; - }, methodCallWrapper(method, ...params) { return sdk.methodCallWrapper(method, ...params); }, diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 2e06f0c26..d01318989 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -817,3 +817,43 @@ export const sendEmailCode = () => { // RC 3.1.0 return sdk.post('users.2fa.sendEmailCode', { emailOrUsername: username }); }; + +export const getRoomMembers = async ({ + rid, + allUsers, + roomType, + type, + filter, + skip = 0, + limit = 10 +}: { + rid: string; + allUsers: boolean; + type: 'all' | 'online'; + roomType: SubscriptionType; + filter: boolean; + skip: number; + limit: number; +}) => { + const t = roomType as SubscriptionType.CHANNEL | SubscriptionType.GROUP | SubscriptionType.DIRECT; + const serverVersion = reduxStore.getState().server.version; + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.16.0')) { + const params = { + roomId: rid, + offset: skip, + count: limit, + ...(type !== 'all' && { 'status[]': type }), + ...(filter && { filter }) + }; + // RC 3.16.0 + const result = await sdk.get(`${roomTypeToApiType(t)}.members`, params); + if (result.success) { + return result?.members; + } + } + // RC 0.42.0 + const result = await sdk.methodCallWrapper('getUsersOfRoom', rid, allUsers, { skip, limit }); + if (result.success) { + return result?.records; + } +};