Chore: Migrate REST API - toggleArchiveRoom to Typescript (#3791)

* Chore: Migrate REST API - toggleArchiveRoom to Typescript

* minor tweak

* removed success param

* minor tweak
This commit is contained in:
Reinaldo Neto 2022-03-02 18:19:07 -03:00 committed by GitHub
parent 718ae48e83
commit af3a6c5da1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 13 deletions

View File

@ -29,6 +29,12 @@ export type ChannelsEndpoints = {
messages: IMessageFromServer[]; messages: IMessageFromServer[];
}; };
}; };
'channels.archive': {
POST: (params: { roomId: string }) => void;
};
'channels.unarchive': {
POST: (params: { roomId: string }) => void;
};
'channels.create': { 'channels.create': {
POST: (params: { POST: (params: {
name: string; name: string;

View File

@ -23,6 +23,12 @@ export type GroupsEndpoints = {
messages: IMessageFromServer[]; messages: IMessageFromServer[];
}; };
}; };
'groups.archive': {
POST: (params: { roomId: string }) => void;
};
'groups.unarchive': {
POST: (params: { roomId: string }) => void;
};
'groups.create': { 'groups.create': {
POST: (params: { POST: (params: {
name: string; name: string;

View File

@ -4,17 +4,25 @@ enum ETypes {
Groups = 'groups' Groups = 'groups'
} }
export const types = { export type RoomTypes = 'c' | 'd' | 'p' | 'l';
type ApiTypes<T> = T extends 'c'
? ETypes.Channels
: T extends 'd'
? ETypes.Im
: T extends 'p'
? ETypes.Groups
: T extends 'l'
? ETypes.Channels
: never;
export const types: { [K in RoomTypes]: ApiTypes<K> } = {
c: ETypes.Channels, c: ETypes.Channels,
d: ETypes.Im, d: ETypes.Im,
p: ETypes.Groups, p: ETypes.Groups,
l: ETypes.Channels l: ETypes.Channels
}; };
// TODO: refactor this const roomTypeToApiType = <T extends RoomTypes>(t: T) => types[t];
export type RoomTypes = keyof typeof types;
type ApiTypes = typeof types[RoomTypes];
const roomTypeToApiType = (t: RoomTypes): ApiTypes => types[t];
export default roomTypeToApiType; export default roomTypeToApiType;

View File

@ -568,17 +568,14 @@ export const ignoreUser = ({ rid, userId, ignore }: { rid: string; userId: strin
// @ts-ignore // @ts-ignore
sdk.get('chat.ignoreUser', { rid, userId, ignore }); sdk.get('chat.ignoreUser', { rid, userId, ignore });
export const toggleArchiveRoom = (roomId: string, t: SubscriptionType, archive: boolean): any => { export const toggleArchiveRoom = (roomId: string, t: SubscriptionType, archive: boolean) => {
const type = t as SubscriptionType.CHANNEL | SubscriptionType.GROUP;
if (archive) { if (archive) {
// RC 0.48.0 // RC 0.48.0
// TODO: missing definitions from server return sdk.post(`${roomTypeToApiType(type)}.archive`, { roomId });
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.archive`, { roomId });
} }
// RC 0.48.0 // RC 0.48.0
// TODO: missing definitions from server return sdk.post(`${roomTypeToApiType(type)}.unarchive`, { roomId });
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.unarchive`, { roomId });
}; };
export const hideRoom = (roomId: string, t: RoomTypes): any => export const hideRoom = (roomId: string, t: RoomTypes): any =>