From b274607f41ca9e700bd3f36fa9b706837f25ce70 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Fri, 4 Jun 2021 20:53:37 +0100 Subject: [PATCH] Allow registering and logging in as guest --- src/matrix/SessionContainer.js | 9 +++++++-- src/matrix/net/HomeServerApi.js | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/matrix/SessionContainer.js b/src/matrix/SessionContainer.js index 07c4a870..6a66178f 100644 --- a/src/matrix/SessionContainer.js +++ b/src/matrix/SessionContainer.js @@ -97,7 +97,7 @@ export class SessionContainer { }); } - async startWithLogin(homeServer, username, password) { + async startWithLogin(homeServer, username, password, guest = false) { if (this._status.get() !== LoadStatus.NotLoading) { return; } @@ -109,7 +109,12 @@ export class SessionContainer { try { const request = this._platform.request; const hsApi = new HomeServerApi({homeServer, request}); - const loginData = await hsApi.passwordLogin(username, password, "Hydrogen", {log}).response(); + let loginData; + if (guest === true) { + loginData = await hsApi.guestLogin("Hydrogen", {log}).response(); + } else { + loginData = await hsApi.passwordLogin(username, password, "Hydrogen", {log}).response(); + } const sessionId = this.createNewSessionId(); sessionInfo = { id: sessionId, diff --git a/src/matrix/net/HomeServerApi.js b/src/matrix/net/HomeServerApi.js index 02d4dc2d..1bac4936 100644 --- a/src/matrix/net/HomeServerApi.js +++ b/src/matrix/net/HomeServerApi.js @@ -142,6 +142,12 @@ export class HomeServerApi { }, options); } + guestLogin(initialDeviceDisplayName, options = null) { + return this._unauthedRequest("POST", this._url(`/register`), {kind: 'guest'}, { + "initial_device_display_name": initialDeviceDisplayName + }, options); + } + createFilter(userId, filter, options = null) { return this._post(`/user/${encodeURIComponent(userId)}/filter`, null, filter, options); }