From 9679058081b92c531eae1eca57634200f1e3b482 Mon Sep 17 00:00:00 2001
From: Bruno Windels <bruno@windels.cloud>
Date: Tue, 18 May 2021 11:05:31 +0200
Subject: [PATCH] allow to join room by id or alias

---
 src/matrix/Session.js           | 7 +++++++
 src/matrix/net/HomeServerApi.js | 4 ++++
 2 files changed, 11 insertions(+)

diff --git a/src/matrix/Session.js b/src/matrix/Session.js
index 38771c87..a2c77752 100644
--- a/src/matrix/Session.js
+++ b/src/matrix/Session.js
@@ -717,6 +717,13 @@ export class Session {
             }
         });
     }
+
+    joinRoom(roomIdOrAlias, log = null) {
+        return this._platform.logger.wrapOrRun(log, "joinRoom", async log => {
+            const body = await this._hsApi.joinIdOrAlias(roomIdOrAlias).response();
+            return body.room_id;
+        });
+    }
 }
 
 export function tests() {
diff --git a/src/matrix/net/HomeServerApi.js b/src/matrix/net/HomeServerApi.js
index a3fe1bc9..f834b94b 100644
--- a/src/matrix/net/HomeServerApi.js
+++ b/src/matrix/net/HomeServerApi.js
@@ -190,6 +190,10 @@ export class HomeServerApi {
         return this._post(`/rooms/${encodeURIComponent(roomId)}/join`, null, null, options);
     }
 
+    joinIdOrAlias(roomIdOrAlias, options = null) {
+        return this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`, null, null, options);
+    }
+
     leave(roomId, options = null) {
         return this._post(`/rooms/${encodeURIComponent(roomId)}/leave`, null, null, options);
     }