Skip to content

Commit

Permalink
Change Draupnir['start'] to be synchronous.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnuxie committed Sep 19, 2024
1 parent b52948b commit f1a6c8c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Draupnir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,17 @@ export class Draupnir implements Client, MatrixAdaptorContext {
* This will not start the appservice from listening and responding
* to events. Nor will it start any syncing client.
*/
public async start(): Promise<void> {
public start(): void {
// to avoid handlers getting out of sync on clientRooms and leaking
// when draupnir keeps being started and restarted, we can basically
// clear all listeners each time and add the factory listener back.
this.clientRooms.on("timeline", this.timelineEventListener);
if (this.reportPoller) {
const reportPollSetting = await ReportPoller.getReportPollSetting(
// allow this to crash draupnir if it fails, since we need to know.
void this.reportPoller.startFromStoredSetting(
this.client,
this.managementRoomOutput
);
this.reportPoller.start(reportPollSetting);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DraupnirBotMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class DraupnirBotModeToggle implements BotModeTogle {
return draupnirResult;
}
this.draupnir = draupnirResult.ok;
void Task(this.draupnir.start());
this.draupnir.start();
if (options?.sendStatusOnStart) {
void Task(this.draupnir.startupComplete());
try {
Expand Down
9 changes: 2 additions & 7 deletions src/draupnirfactory/StandardDraupnirManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
// https://github.com/matrix-org/mjolnir
// </text>

import {
ActionError,
ActionResult,
Task,
isError,
} from "matrix-protection-suite";
import { ActionError, ActionResult, isError } from "matrix-protection-suite";
import { IConfig } from "../config";
import { DraupnirFactory } from "./DraupnirFactory";
import { Draupnir } from "../Draupnir";
Expand Down Expand Up @@ -88,7 +83,7 @@ export class StandardDraupnirManager {
}
this.draupnir.set(clientUserID, draupnir.ok);
this.failedDraupnir.delete(clientUserID);
void Task(draupnir.ok.start());
draupnir.ok.start();
return draupnir;
}

Expand Down
12 changes: 12 additions & 0 deletions src/report/ReportPoller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ export class ReportPoller {
}
return reportPollSetting;
}

public async startFromStoredSetting(
client: MatrixSendClient,
managementRoomOutput: ManagementRoomOutput
): Promise<void> {
const reportPollSetting = await ReportPoller.getReportPollSetting(
client,
managementRoomOutput
);
this.start(reportPollSetting);
}

public start({ from: startFrom }: ReportPollSetting) {
if (this.timeout === null) {
this.from = startFrom;
Expand Down

0 comments on commit f1a6c8c

Please sign in to comment.