Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Mar 15, 2022
11 changes: 11 additions & 0 deletions app/definitions/IRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
4 changes: 4 additions & 0 deletions app/definitions/rest/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'];
Expand Down
4 changes: 4 additions & 0 deletions app/definitions/rest/v1/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion app/lib/rocketchat/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,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
Expand Down
7 changes: 4 additions & 3 deletions app/lib/rocketchat/services/restApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,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> =>
Expand Down
3 changes: 2 additions & 1 deletion app/views/RoomMembersView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down