From fe4e84c762c94cd367823dca9ffb164437be2c09 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Tue, 9 May 2023 13:30:53 +0530 Subject: [PATCH] add more hs api --- src/matrix/net/HomeServerApi.ts | 77 +++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/src/matrix/net/HomeServerApi.ts b/src/matrix/net/HomeServerApi.ts index c5f90555..42c5aecf 100644 --- a/src/matrix/net/HomeServerApi.ts +++ b/src/matrix/net/HomeServerApi.ts @@ -146,6 +146,10 @@ export class HomeServerApi { send(roomId: string, eventType: string, txnId: string, content: Record, options?: BaseRequestOptions): IHomeServerRequest { return this._put(`/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/${encodeURIComponent(txnId)}`, {}, content, options); } + + event(roomId: string, eventId: string , options?: BaseRequestOptions): IHomeServerRequest { + return this._get(`/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`, undefined, undefined, options); + } redact(roomId: string, eventId: string, txnId: string, content: Record, options?: BaseRequestOptions): IHomeServerRequest { return this._put(`/rooms/${encodeURIComponent(roomId)}/redact/${encodeURIComponent(eventId)}/${encodeURIComponent(txnId)}`, {}, content, options); @@ -275,6 +279,12 @@ export class HomeServerApi { return this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`, {}, {}, options); } + invite(roomId: string, userId: string, options?: BaseRequestOptions): IHomeServerRequest { + return this._post(`/rooms/${encodeURIComponent(roomId)}/invite`, {}, { + user_id: userId + }, options); + } + leave(roomId: string, options?: BaseRequestOptions): IHomeServerRequest { return this._post(`/rooms/${encodeURIComponent(roomId)}/leave`, {}, {}, options); } @@ -283,10 +293,35 @@ export class HomeServerApi { return this._post(`/rooms/${encodeURIComponent(roomId)}/forget`, {}, {}, options); } + kick(roomId: string, userId: string, reason?: string, options?: BaseRequestOptions): IHomeServerRequest { + return this._post(`/rooms/${encodeURIComponent(roomId)}/kick`, {}, { + user_id: userId, + reason: reason, + }, options); + } + + ban(roomId: string, userId: string, reason?: string, options?: BaseRequestOptions): IHomeServerRequest { + return this._post(`/rooms/${encodeURIComponent(roomId)}/ban`, {}, { + user_id: userId, + reason: reason, + }, options); + } + + unban(roomId: string, userId: string, reason?: string, options?: BaseRequestOptions): IHomeServerRequest { + return this._post(`/rooms/${encodeURIComponent(roomId)}/unban`, {}, { + user_id: userId, + reason: reason, + }, options); + } + logout(options?: BaseRequestOptions): IHomeServerRequest { return this._post(`/logout`, {}, {}, options); } + whoami(options?: BaseRequestOptions): IHomeServerRequest { + return this._get(`/account/whoami`, undefined, undefined, options); + } + getDehydratedDevice(options: BaseRequestOptions = {}): IHomeServerRequest { options.prefix = DEHYDRATION_PREFIX; return this._get(`/dehydrated_device`, undefined, undefined, options); @@ -302,18 +337,60 @@ export class HomeServerApi { return this._post(`/dehydrated_device/claim`, {}, {device_id: deviceId}, options); } + searchProfile(searchTerm: string, limit?: number, options?: BaseRequestOptions): IHomeServerRequest { + return this._post(`/user_directory/search`, {}, { + limit: limit ?? 10, + search_term: searchTerm, + }, options); + } + profile(userId: string, options?: BaseRequestOptions): IHomeServerRequest { return this._get(`/profile/${encodeURIComponent(userId)}`); } + setProfileDisplayName(userId, displayName, options?: BaseRequestOptions): IHomeServerRequest { + return this._put(`/profile/${encodeURIComponent(userId)}/displayname`, {}, { displayname: displayName }, options); + } + + setProfileAvatarUrl(userId, avatarUrl, options?: BaseRequestOptions): IHomeServerRequest { + return this._put(`/profile/${encodeURIComponent(userId)}/avatar_url`, {}, { avatar_url: avatarUrl }, options); + } + createRoom(payload: Record, options?: BaseRequestOptions): IHomeServerRequest { return this._post(`/createRoom`, {}, payload, options); } + accountData(ownUserId: string, type: string, options?: BaseRequestOptions): IHomeServerRequest { + return this._get( + `/user/${encodeURIComponent(ownUserId)}/account_data/${encodeURIComponent(type)}`, + undefined, + undefined, + options, + ); + } + setAccountData(ownUserId: string, type: string, content: Record, options?: BaseRequestOptions): IHomeServerRequest { return this._put(`/user/${encodeURIComponent(ownUserId)}/account_data/${encodeURIComponent(type)}`, {}, content, options); } + roomAccountData(ownUserId: string, roomId: string, type: string, options?: BaseRequestOptions): IHomeServerRequest { + return this._get( + `/user/${encodeURIComponent(ownUserId)}/rooms/${encodeURIComponent(roomId)}/account_data/${encodeURIComponent(type)}`, + undefined, + undefined, + options + ); + } + + setRoomAccountData(ownUserId: string, roomId: string, type: string, content: Record, options?: BaseRequestOptions): IHomeServerRequest { + return this._put( + `/user/${encodeURIComponent(ownUserId)}/rooms/${encodeURIComponent(roomId)}/account_data/${encodeURIComponent(type)}`, + {}, + content, + options + ); + } + getTurnServer(options?: BaseRequestOptions): IHomeServerRequest { return this._get(`/voip/turnServer`, undefined, undefined, options); }