From eb51e76f9db594d00ededf44eeb59e02685e0429 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Wed, 29 Jun 2022 15:58:29 +0530 Subject: [PATCH 1/2] Add more hs api --- src/matrix/net/HomeServerApi.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/matrix/net/HomeServerApi.ts b/src/matrix/net/HomeServerApi.ts index 7f0f17ca..e351ff19 100644 --- a/src/matrix/net/HomeServerApi.ts +++ b/src/matrix/net/HomeServerApi.ts @@ -271,6 +271,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); } @@ -298,6 +304,13 @@ 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)}`); } From 83b233b97e0e029efca91212b7a52d3a1b2df592 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Wed, 29 Jun 2022 15:58:51 +0530 Subject: [PATCH 2/2] Add type for invite rom --- src/matrix/room/BaseRoom.js | 2 +- src/matrix/room/Invite.js | 8 ++++++-- src/matrix/room/timeline/persistence/GapWriter.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index 7865723b..76c6c9f7 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -415,7 +415,7 @@ export class BaseRoom extends EventEmitter { } get type() { - return this._summary.data.type; + return this._summary.data.type ?? undefined; } get lastMessageTimestamp() { diff --git a/src/matrix/room/Invite.js b/src/matrix/room/Invite.js index 6c5ef121..4324ba38 100644 --- a/src/matrix/room/Invite.js +++ b/src/matrix/room/Invite.js @@ -61,6 +61,10 @@ export class Invite extends EventEmitter { return this._inviteData.avatarColorId || this.id; } + get type() { + return this._inviteData.type ?? undefined; + } + get timestamp() { return this._inviteData.timestamp; } @@ -89,7 +93,7 @@ export class Invite extends EventEmitter { await this._platform.logger.wrapOrRun(log, "acceptInvite", async log => { this._accepting = true; this._emitChange("accepting"); - await this._hsApi.join(this._roomId, {log}).response(); + await this._hsApi.joinIdOrAlias(this.canonicalAlias ?? this._roomId, {log}).response(); }); } @@ -189,7 +193,7 @@ export class Invite extends EventEmitter { roomId: this.id, isEncrypted: !!summaryData.encryption, isDirectMessage: summaryData.isDirectMessage, -// type: + type: summaryData.type, name, avatarUrl, avatarColorId, diff --git a/src/matrix/room/timeline/persistence/GapWriter.js b/src/matrix/room/timeline/persistence/GapWriter.js index 3e520608..4458e1c5 100644 --- a/src/matrix/room/timeline/persistence/GapWriter.js +++ b/src/matrix/room/timeline/persistence/GapWriter.js @@ -163,7 +163,7 @@ export class GapWriter { if (!Array.isArray(chunk)) { throw new Error("Invalid chunk in response"); } - if (typeof end !== "string") { + if (typeof end !== "string" && typeof end !== "undefined") { throw new Error("Invalid end token in response"); }