diff --git a/changelog.d/1681.feature b/changelog.d/1681.feature new file mode 100644 index 000000000..1ace8c0ea --- /dev/null +++ b/changelog.d/1681.feature @@ -0,0 +1 @@ +Make bridgeInfoState configuration reloadable. diff --git a/src/bridge/IrcBridge.ts b/src/bridge/IrcBridge.ts index 12a02608e..2b148dada 100644 --- a/src/bridge/IrcBridge.ts +++ b/src/bridge/IrcBridge.ts @@ -255,6 +255,8 @@ export class IrcBridge { log.info(`Adjusted media_url to ${newConfig.homeserver.media_url}`); } + await this.setupStateSyncer(newConfig); + this.ircHandler.onConfigChanged(newConfig.ircService.ircHandler || {}); this.config.ircService.ircHandler = newConfig.ircService.ircHandler; @@ -723,20 +725,7 @@ export class IrcBridge { log.info("Fetching Matrix rooms that are already joined to..."); await this.fetchJoinedRooms(); - if (this.config.ircService.bridgeInfoState?.enabled) { - this.bridgeStateSyncer = new BridgeInfoStateSyncer(this.bridge, { - bridgeName: 'org.matrix.appservice-irc', - getMapping: async (roomId, { channel, networkId }) => this.createInfoMapping(channel, networkId), - }); - if (this.config.ircService.bridgeInfoState.initial) { - const mappings = await this.dataStore.getAllChannelMappings(); - this.bridgeStateSyncer.initialSync(mappings).then(() => { - log.info("Bridge state syncing completed"); - }).catch((err) => { - log.error("Bridge state syncing resulted in an error:", err); - }); - } - } + await this.setupStateSyncer(this.config); log.info("Joining mapped Matrix rooms..."); await this.joinMappedMatrixRooms(); @@ -820,6 +809,29 @@ export class IrcBridge { this.bridgeState = "running"; } + private async setupStateSyncer(config: BridgeConfig) { + if (!config.ircService.bridgeInfoState?.enabled) { + this.bridgeStateSyncer = undefined; + this.config.ircService.bridgeInfoState = undefined; + return; + } + log.info("Syncing bridge state"); + this.bridgeStateSyncer = new BridgeInfoStateSyncer(this.bridge, { + bridgeName: 'org.matrix.appservice-irc', + getMapping: async (roomId, { channel, networkId }) => this.createInfoMapping(channel, networkId), + }); + if (config.ircService.bridgeInfoState.initial && !this.config.ircService.bridgeInfoState?.initial) { + /* Only run it on startup, or when a reload switches it from false to true */ + const mappings = await this.dataStore.getAllChannelMappings(); + this.bridgeStateSyncer.initialSync(mappings).then(() => { + log.info("Bridge state syncing completed"); + }).catch((err) => { + log.error("Bridge state syncing resulted in an error:", err); + }); + } + this.config.ircService.bridgeInfoState = config.ircService.bridgeInfoState; + } + private logMetric(req: Request, outcome: string) { if (!this.timers) { return; // metrics are disabled