Chore: Migrate REST API - getRoomMembers to Typescript (#3899)
This commit is contained in:
parent
4cfadbc97b
commit
f98f2a46d9
|
@ -4,6 +4,7 @@ import type { IServerRoom } from '../../IRoom';
|
||||||
import type { IUser } from '../../IUser';
|
import type { IUser } from '../../IUser';
|
||||||
import { IGetRoomRoles } from '../../IRole';
|
import { IGetRoomRoles } from '../../IRole';
|
||||||
import { IServerAttachment } from '../../IAttachment';
|
import { IServerAttachment } from '../../IAttachment';
|
||||||
|
import { PaginatedRequest } from '../helpers/PaginatedRequest';
|
||||||
|
|
||||||
export type ChannelsEndpoints = {
|
export type ChannelsEndpoints = {
|
||||||
'channels.files': {
|
'channels.files': {
|
||||||
|
@ -15,12 +16,15 @@ export type ChannelsEndpoints = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
'channels.members': {
|
'channels.members': {
|
||||||
GET: (params: { roomId: IServerRoom['_id']; offset?: number; count?: number; filter?: string; status?: string[] }) => {
|
GET: (params: {
|
||||||
count: number;
|
roomId: IServerRoom['_id'];
|
||||||
offset: number;
|
offset?: number;
|
||||||
|
count?: number;
|
||||||
|
filter?: boolean;
|
||||||
|
status?: string[];
|
||||||
|
}) => PaginatedRequest<{
|
||||||
members: IUser[];
|
members: IUser[];
|
||||||
total: number;
|
}>;
|
||||||
};
|
|
||||||
};
|
};
|
||||||
'channels.history': {
|
'channels.history': {
|
||||||
GET: (params: { roomId: string; count: number; latest?: string }) => {
|
GET: (params: { roomId: string; count: number; latest?: string }) => {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import type { IServerRoom } from '../../IRoom';
|
||||||
import type { IUser } from '../../IUser';
|
import type { IUser } from '../../IUser';
|
||||||
import { IGetRoomRoles } from '../../IRole';
|
import { IGetRoomRoles } from '../../IRole';
|
||||||
import { IServerAttachment } from '../../IAttachment';
|
import { IServerAttachment } from '../../IAttachment';
|
||||||
|
import { PaginatedRequest } from '../helpers/PaginatedRequest';
|
||||||
|
|
||||||
export type GroupsEndpoints = {
|
export type GroupsEndpoints = {
|
||||||
'groups.files': {
|
'groups.files': {
|
||||||
|
@ -15,12 +16,15 @@ export type GroupsEndpoints = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
'groups.members': {
|
'groups.members': {
|
||||||
GET: (params: { roomId: IServerRoom['_id']; offset?: number; count?: number; filter?: string; status?: string[] }) => {
|
GET: (params: {
|
||||||
count: number;
|
roomId: IServerRoom['_id'];
|
||||||
offset: number;
|
offset?: number;
|
||||||
|
count?: number;
|
||||||
|
filter?: string;
|
||||||
|
status?: string[];
|
||||||
|
}) => PaginatedRequest<{
|
||||||
members: IUser[];
|
members: IUser[];
|
||||||
total: number;
|
}>;
|
||||||
};
|
|
||||||
};
|
};
|
||||||
'groups.history': {
|
'groups.history': {
|
||||||
GET: (params: { roomId: string; count: number; latest?: string }) => {
|
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 { IServerRoom, RoomID, RoomType } from '../../IRoom';
|
||||||
import type { IUser } from '../../IUser';
|
import type { IUser } from '../../IUser';
|
||||||
import { IServerAttachment } from '../../IAttachment';
|
import { IServerAttachment } from '../../IAttachment';
|
||||||
|
import { PaginatedRequest } from '../helpers/PaginatedRequest';
|
||||||
|
|
||||||
export type ImEndpoints = {
|
export type ImEndpoints = {
|
||||||
'im.create': {
|
'im.create': {
|
||||||
|
@ -34,12 +35,15 @@ export type ImEndpoints = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
'im.members': {
|
'im.members': {
|
||||||
GET: (params: { roomId: IServerRoom['_id']; offset?: number; count?: number; filter?: string; status?: string[] }) => {
|
GET: (params: {
|
||||||
count: number;
|
roomId: IServerRoom['_id'];
|
||||||
offset: number;
|
offset?: number;
|
||||||
|
count?: number;
|
||||||
|
filter?: string;
|
||||||
|
status?: string[];
|
||||||
|
}) => PaginatedRequest<{
|
||||||
members: IUser[];
|
members: IUser[];
|
||||||
total: number;
|
}>;
|
||||||
};
|
|
||||||
};
|
};
|
||||||
'im.history': {
|
'im.history': {
|
||||||
GET: (params: { roomId: string; count: number; latest?: string }) => {
|
GET: (params: { roomId: string; count: number; latest?: string }) => {
|
||||||
|
|
|
@ -309,24 +309,6 @@ const RocketChat = {
|
||||||
return sdk.onStreamData(...args);
|
return sdk.onStreamData(...args);
|
||||||
},
|
},
|
||||||
toggleFavorite,
|
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) {
|
methodCallWrapper(method, ...params) {
|
||||||
return sdk.methodCallWrapper(method, ...params);
|
return sdk.methodCallWrapper(method, ...params);
|
||||||
},
|
},
|
||||||
|
|
|
@ -817,3 +817,43 @@ export const sendEmailCode = () => {
|
||||||
// RC 3.1.0
|
// RC 3.1.0
|
||||||
return sdk.post('users.2fa.sendEmailCode', { emailOrUsername: username });
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue