From 15fd73ed9c1486c33ecac7061f86edbd2309ea64 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 9 Nov 2023 09:56:56 +0000 Subject: [PATCH] Add ability to adjust the token on the homeserver API. --- src/matrix/Session.js | 9 +++++++++ src/matrix/net/HomeServerApi.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 3fc3b006..348b626b 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -1094,6 +1094,15 @@ export class Session { return body.room_id; }); } + + /** + * Updates the access token used by the API. Does NOT + * change the token in storage. + * @param {string} token + */ + updateAccessToken(token) { + this._hsApi.updateAccessToken(token); + } } import {FeatureSet} from "../features"; diff --git a/src/matrix/net/HomeServerApi.ts b/src/matrix/net/HomeServerApi.ts index eebc692a..50e51c21 100644 --- a/src/matrix/net/HomeServerApi.ts +++ b/src/matrix/net/HomeServerApi.ts @@ -46,7 +46,7 @@ type BaseRequestOptions = { export class HomeServerApi { private readonly _homeserver: string; - private readonly _accessToken: string; + private _accessToken: string; private readonly _requestFn: RequestFunction; private readonly _reconnector: Reconnector; @@ -125,6 +125,14 @@ export class HomeServerApi { return this._authedRequest("GET", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options); } + /** + * Update the access token used by the API. + * @param token + */ + public updateAccessToken(token: string) { + this._accessToken = token; + } + sync(since: string, filter: string, timeout: number, options?: BaseRequestOptions): IHomeServerRequest { return this._get("/sync", {since, timeout, filter}, undefined, options); }