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

View File

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

View File

@ -327,7 +327,7 @@ const RocketChat = {
...(filter && { filter }) ...(filter && { filter })
}; };
// RC 3.16.0 // 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; return result?.members;
} }
// RC 0.42.0 // RC 0.42.0

View File

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

View File

@ -433,7 +433,8 @@ class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMember
fetchRoomMembersRoles = async () => { fetchRoomMembersRoles = async () => {
try { try {
const { room } = this.state; 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) { if (result?.success) {
this.roomRoles = result.roles; this.roomRoles = result.roles;
} }