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:
parent
718ae48e83
commit
af3a6c5da1
|
@ -29,6 +29,12 @@ export type ChannelsEndpoints = {
|
|||
messages: IMessageFromServer[];
|
||||
};
|
||||
};
|
||||
'channels.archive': {
|
||||
POST: (params: { roomId: string }) => void;
|
||||
};
|
||||
'channels.unarchive': {
|
||||
POST: (params: { roomId: string }) => void;
|
||||
};
|
||||
'channels.create': {
|
||||
POST: (params: {
|
||||
name: string;
|
||||
|
|
|
@ -23,6 +23,12 @@ export type GroupsEndpoints = {
|
|||
messages: IMessageFromServer[];
|
||||
};
|
||||
};
|
||||
'groups.archive': {
|
||||
POST: (params: { roomId: string }) => void;
|
||||
};
|
||||
'groups.unarchive': {
|
||||
POST: (params: { roomId: string }) => void;
|
||||
};
|
||||
'groups.create': {
|
||||
POST: (params: {
|
||||
name: string;
|
||||
|
|
|
@ -4,17 +4,25 @@ enum ETypes {
|
|||
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,
|
||||
d: ETypes.Im,
|
||||
p: ETypes.Groups,
|
||||
l: ETypes.Channels
|
||||
};
|
||||
|
||||
// TODO: refactor this
|
||||
export type RoomTypes = keyof typeof types;
|
||||
type ApiTypes = typeof types[RoomTypes];
|
||||
|
||||
const roomTypeToApiType = (t: RoomTypes): ApiTypes => types[t];
|
||||
const roomTypeToApiType = <T extends RoomTypes>(t: T) => types[t];
|
||||
|
||||
export default roomTypeToApiType;
|
||||
|
|
|
@ -568,17 +568,14 @@ export const ignoreUser = ({ rid, userId, ignore }: { rid: string; userId: strin
|
|||
// @ts-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) {
|
||||
// RC 0.48.0
|
||||
// TODO: missing definitions from server
|
||||
// @ts-ignore
|
||||
return sdk.post(`${roomTypeToApiType(t)}.archive`, { roomId });
|
||||
return sdk.post(`${roomTypeToApiType(type)}.archive`, { roomId });
|
||||
}
|
||||
// RC 0.48.0
|
||||
// TODO: missing definitions from server
|
||||
// @ts-ignore
|
||||
return sdk.post(`${roomTypeToApiType(t)}.unarchive`, { roomId });
|
||||
return sdk.post(`${roomTypeToApiType(type)}.unarchive`, { roomId });
|
||||
};
|
||||
|
||||
export const hideRoom = (roomId: string, t: RoomTypes): any =>
|
||||
|
|
Loading…
Reference in New Issue