From cbed0426725a29cf0f2406763a9a24f8272a3ea6 Mon Sep 17 00:00:00 2001 From: MTRNord Date: Sat, 17 Aug 2024 13:08:49 +0200 Subject: [PATCH 1/5] Fix the bot-sdk crypto by initializing the bot-sdk earlier Signed-off-by: MTRNord --- .gitignore | 3 +++ src/index.ts | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c670a1f2..803f335a 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,6 @@ mjolnir.egg-info/ .yarn # Only contains possibly broken path, replaced by .yarnrc.yml in modern Yarn .yarnrc + +# VS Code workspace settings +/.vscode \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 5ffd9644..99fc9b0b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,12 +97,13 @@ void (async function () { } patchMatrixClient(); config.RUNTIME.client = client; + await config.RUNTIME.client.start(); const eventDecoder = DefaultEventDecoder; const store = config.roomStateBackingStore.enabled ? new SqliteRoomStateBackingStore( - path.join(config.dataPath, "room-state-backing-store.db"), - eventDecoder - ) + path.join(config.dataPath, "room-state-backing-store.db"), + eventDecoder + ) : undefined; bot = await makeDraupnirBotModeFromConfig( client, @@ -119,7 +120,6 @@ void (async function () { } try { await bot.start(); - await config.RUNTIME.client.start(); await apis.start(); healthz.isHealthy = true; } catch (err) { From 7430055d28b1ccc027bfb1c034cd81c2e401004d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 17 Aug 2024 11:11:09 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 803f335a..10d20fa8 100644 --- a/.gitignore +++ b/.gitignore @@ -96,4 +96,4 @@ mjolnir.egg-info/ .yarnrc # VS Code workspace settings -/.vscode \ No newline at end of file +/.vscode From cedd50d55bf9023097fe9486fb415924c2c3aa9b Mon Sep 17 00:00:00 2001 From: MTRNord Date: Sat, 17 Aug 2024 13:59:26 +0200 Subject: [PATCH 3/5] Fix formatting Signed-off-by: MTRNord --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 99fc9b0b..ed9286be 100644 --- a/src/index.ts +++ b/src/index.ts @@ -101,9 +101,9 @@ void (async function () { const eventDecoder = DefaultEventDecoder; const store = config.roomStateBackingStore.enabled ? new SqliteRoomStateBackingStore( - path.join(config.dataPath, "room-state-backing-store.db"), - eventDecoder - ) + path.join(config.dataPath, "room-state-backing-store.db"), + eventDecoder + ) : undefined; bot = await makeDraupnirBotModeFromConfig( client, From 3b3c1c4bba02855a5df6b518f3f4a6514c8c0a2b Mon Sep 17 00:00:00 2001 From: MTRNord Date: Sat, 17 Aug 2024 18:23:24 +0200 Subject: [PATCH 4/5] Instead of moving the sync start we move the one message causing issues. This makes sure we are actually ready for incoming messages Signed-off-by: MTRNord --- src/Draupnir.ts | 3 +-- src/index.ts | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Draupnir.ts b/src/Draupnir.ts index 232adc2c..5f84f2f3 100644 --- a/src/Draupnir.ts +++ b/src/Draupnir.ts @@ -275,11 +275,10 @@ export class Draupnir implements Client { if (isError(managementRoomProtectResult)) { return managementRoomProtectResult; } - void Task(draupnir.startupComplete()); return Ok(draupnir); } - private async startupComplete(): Promise { + public async startupComplete(): Promise { const statusInfo = await draupnirStatusInfo(this); try { await this.managementRoomOutput.logMessage( diff --git a/src/index.ts b/src/index.ts index ed9286be..b0fe4609 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,7 +30,7 @@ import { } from "./DraupnirBotMode"; import { Draupnir } from "./Draupnir"; import { SafeMatrixEmitterWrapper } from "matrix-protection-suite-for-matrix-bot-sdk"; -import { DefaultEventDecoder } from "matrix-protection-suite"; +import { DefaultEventDecoder, Task } from "matrix-protection-suite"; import { WebAPIs } from "./webapis/WebAPIs"; import { SqliteRoomStateBackingStore } from "./backingstore/better-sqlite3/SqliteRoomStateBackingStore"; @@ -97,7 +97,6 @@ void (async function () { } patchMatrixClient(); config.RUNTIME.client = client; - await config.RUNTIME.client.start(); const eventDecoder = DefaultEventDecoder; const store = config.roomStateBackingStore.enabled ? new SqliteRoomStateBackingStore( @@ -120,6 +119,8 @@ void (async function () { } try { await bot.start(); + await config.RUNTIME.client.start(); + void Task(bot.startupComplete()); await apis.start(); healthz.isHealthy = true; } catch (err) { From ed5cc7dd813f3d169bb4905fa18b5f7c1536d705 Mon Sep 17 00:00:00 2001 From: MTRNord Date: Sat, 17 Aug 2024 22:58:59 +0200 Subject: [PATCH 5/5] Add a comment on why the startupComplete method is public --- src/Draupnir.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Draupnir.ts b/src/Draupnir.ts index 5f84f2f3..8e655aa9 100644 --- a/src/Draupnir.ts +++ b/src/Draupnir.ts @@ -278,6 +278,11 @@ export class Draupnir implements Client { return Ok(draupnir); } + /** + * Note: This is only public due to having to first start the syncloop before sending events + * when we use encryption. + * This means this is only used in the index.ts. + */ public async startupComplete(): Promise { const statusInfo = await draupnirStatusInfo(this); try {