Chore: Migrate REST API - getRoomRoles to Typescript and fix getRoomMembers (#3868)

* Chore: Migrate REST API - getRoomRoles to Typescript and fix getRoomMembers

* change GetRoomRoles local
This commit is contained in:
Reinaldo Neto 2022-03-14 21:11:34 -03:00 committed by GitHub
parent d18d91dd74
commit db5c7d94aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 5 deletions

View File

@ -12,3 +12,14 @@ export interface IRole {
}
export type TRoleModel = IRole & Model;
// For rest/v1/ 'groups.roles' and 'channels.roles'
export interface IGetRoomRoles {
_id: string;
rid: string;
u: {
_id: string;
username: string;
};
roles: string[];
}

View File

@ -2,6 +2,7 @@ import { ITeam } from '../../ITeam';
import type { IMessageFromServer } from '../../IMessage';
import type { IServerRoom } from '../../IRoom';
import type { IUser } from '../../IUser';
import { IGetRoomRoles } from '../../IRole';
import { IServerAttachment } from '../../IAttachment';
export type ChannelsEndpoints = {
@ -95,6 +96,9 @@ export type ChannelsEndpoints = {
};
'channels.removeLeader': {
POST: (params: { roomId: string; userId: string }) => {};
};
'channels.roles': {
GET: (params: { roomId: string }) => { roles: IGetRoomRoles[] };
};
'channels.messages': {
GET: (params: {

View File

@ -2,6 +2,7 @@ import { ITeam } from '../../ITeam';
import type { IMessageFromServer } from '../../IMessage';
import type { IServerRoom } from '../../IRoom';
import type { IUser } from '../../IUser';
import { IGetRoomRoles } from '../../IRole';
import { IServerAttachment } from '../../IAttachment';
export type GroupsEndpoints = {
@ -71,6 +72,9 @@ export type GroupsEndpoints = {
};
'groups.leave': {
POST: (params: { roomId: string }) => {};
};
'groups.roles': {
GET: (params: { roomId: string }) => { roles: IGetRoomRoles[] };
};
'groups.messages': {
GET: (params: {

View File

@ -327,7 +327,7 @@ const RocketChat = {
...(filter && { filter })
};
// RC 3.16.0
const result = await this.sdk.get(`${this.roomTypeToApiType(roomType)}.members`, params);
const result = await sdk.get(`${this.roomTypeToApiType(roomType)}.members`, params);
return result?.members;
}
// RC 0.42.0

View File

@ -570,10 +570,11 @@ export const getSingleMessage = (msgId: string) =>
// RC 0.47.0
sdk.get('chat.getMessage', { msgId });
export const getRoomRoles = (roomId: string, type: SubscriptionType): any =>
export const getRoomRoles = (
roomId: string,
type: SubscriptionType.CHANNEL | SubscriptionType.GROUP | SubscriptionType.OMNICHANNEL
) =>
// RC 0.65.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get(`${roomTypeToApiType(type)}.roles`, { roomId });
export const getAvatarSuggestion = (): Promise<IAvatarSuggestion> =>

View File

@ -433,7 +433,8 @@ class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMember
fetchRoomMembersRoles = async () => {
try {
const { room } = this.state;
const result = await RocketChat.getRoomRoles(room.rid, room.t);
const type = room.t as SubscriptionType.CHANNEL | SubscriptionType.GROUP | SubscriptionType.OMNICHANNEL;
const result = await RocketChat.getRoomRoles(room.rid, type);
if (result?.success) {
this.roomRoles = result.roles;
}