From db5c7d94aa5cddeb8053ab086d6a6d068a07aeaf Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Mon, 14 Mar 2022 21:11:34 -0300 Subject: [PATCH] Chore: Migrate REST API - getRoomRoles to Typescript and fix getRoomMembers (#3868) * Chore: Migrate REST API - getRoomRoles to Typescript and fix getRoomMembers * change GetRoomRoles local --- app/definitions/IRole.ts | 11 +++++++++++ app/definitions/rest/v1/channels.ts | 4 ++++ app/definitions/rest/v1/groups.ts | 4 ++++ app/lib/rocketchat/rocketchat.js | 2 +- app/lib/rocketchat/services/restApi.ts | 7 ++++--- app/views/RoomMembersView/index.tsx | 3 ++- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/definitions/IRole.ts b/app/definitions/IRole.ts index 332dab65d..d4a87c2e0 100644 --- a/app/definitions/IRole.ts +++ b/app/definitions/IRole.ts @@ -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[]; +} diff --git a/app/definitions/rest/v1/channels.ts b/app/definitions/rest/v1/channels.ts index 6e2462a2c..d3b0a966e 100644 --- a/app/definitions/rest/v1/channels.ts +++ b/app/definitions/rest/v1/channels.ts @@ -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 = { @@ -96,6 +97,9 @@ export type ChannelsEndpoints = { 'channels.removeLeader': { POST: (params: { roomId: string; userId: string }) => {}; }; + 'channels.roles': { + GET: (params: { roomId: string }) => { roles: IGetRoomRoles[] }; + }; 'channels.messages': { GET: (params: { roomId: IServerRoom['_id']; diff --git a/app/definitions/rest/v1/groups.ts b/app/definitions/rest/v1/groups.ts index dd032e455..ff329f2f0 100644 --- a/app/definitions/rest/v1/groups.ts +++ b/app/definitions/rest/v1/groups.ts @@ -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 = { @@ -72,6 +73,9 @@ export type GroupsEndpoints = { 'groups.leave': { POST: (params: { roomId: string }) => {}; }; + 'groups.roles': { + GET: (params: { roomId: string }) => { roles: IGetRoomRoles[] }; + }; 'groups.messages': { GET: (params: { roomId: IServerRoom['_id']; diff --git a/app/lib/rocketchat/rocketchat.js b/app/lib/rocketchat/rocketchat.js index 3fa218886..451d9ea6b 100644 --- a/app/lib/rocketchat/rocketchat.js +++ b/app/lib/rocketchat/rocketchat.js @@ -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 diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 2ee8ee085..e48415987 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -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 => diff --git a/app/views/RoomMembersView/index.tsx b/app/views/RoomMembersView/index.tsx index c967515f0..4212e7856 100644 --- a/app/views/RoomMembersView/index.tsx +++ b/app/views/RoomMembersView/index.tsx @@ -433,7 +433,8 @@ class RoomMembersView extends React.Component { 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; }