From 5dc3ad546c819d008b1ca059d9536da51611f005 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 1 May 2024 14:22:29 +0100 Subject: [PATCH] Improve comments and types in MatrixClientPeg (#12477) Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/MatrixClientPeg.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/MatrixClientPeg.ts b/src/MatrixClientPeg.ts index f19fa0c162..d14003dbfa 100644 --- a/src/MatrixClientPeg.ts +++ b/src/MatrixClientPeg.ts @@ -73,22 +73,44 @@ export interface IMatrixClientCreds { * you'll find a `MatrixClient` hanging on the `MatrixClientPeg`. */ export interface IMatrixClientPeg { + /** + * The opts used to start the client + */ opts: IStartClientOpts; /** * Return the server name of the user's homeserver * Throws an error if unable to deduce the homeserver name - * (eg. if the user is not logged in) + * (e.g. if the user is not logged in) * * @returns {string} The homeserver name, if present. */ getHomeserverName(): string; + /** + * Get the current MatrixClient, if any + */ get(): MatrixClient | null; + + /** + * Get the current MatrixClient, throwing an error if there isn't one + */ safeGet(): MatrixClient; + + /** + * Unset the current MatrixClient + */ unset(): void; - assign(): Promise; - start(): Promise; + + /** + * Prepare the MatrixClient for use, including initialising the store and crypto, but do not start it + */ + assign(): Promise; + + /** + * Prepare the MatrixClient for use, including initialising the store and crypto, and start it + */ + start(): Promise; /** * If we've registered a user ID we set this to the ID of the @@ -235,7 +257,7 @@ class MatrixClientPegClass implements IMatrixClientPeg { PlatformPeg.get()?.reload(); }; - public async assign(): Promise { + public async assign(): Promise { if (!this.matrixClient) { throw new Error("createClient must be called first"); } @@ -354,7 +376,7 @@ class MatrixClientPegClass implements IMatrixClientPeg { } } - public async start(): Promise { + public async start(): Promise { const opts = await this.assign(); logger.log(`MatrixClientPeg: really starting MatrixClient`);