Unverified Commit f98f2a46 authored by Alex Junior's avatar Alex Junior Committed by GitHub
Browse files

Chore: Migrate REST API - getRoomMembers to Typescript (#3899)

parent 4cfadbc9
......@@ -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 }) => {
......
......@@ -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 }) => {
......
......@@ -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 }) => {
......
......@@ -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);
},
......
......@@ -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;
}
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment