From 8b4e919f39fd5826d9e558fbacda5809026a913b Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 11 Mar 2023 20:26:52 +0100 Subject: [PATCH 1/6] Make bridgeInfoState configuration reloadable This will be useful for tests --- changelog.d/1681.feat | 1 + src/bridge/IrcBridge.ts | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 changelog.d/1681.feat diff --git a/changelog.d/1681.feat b/changelog.d/1681.feat new file mode 100644 index 000000000..9d41f2c95 --- /dev/null +++ b/changelog.d/1681.feat @@ -0,0 +1 @@ +Make bridgeInfoState configuration reloadable diff --git a/src/bridge/IrcBridge.ts b/src/bridge/IrcBridge.ts index 12a02608e..843054051 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) { + 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) { + 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); + }); + } + } + else { + this.bridgeStateSyncer = undefined; + } + + this.config.ircService.bridgeInfoState = config.ircService.bridgeInfoState; + } + private logMetric(req: Request, outcome: string) { if (!this.timers) { return; // metrics are disabled From 37941eb2a43927fcc3d66e1104b8e171b6ce92aa Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 11 Mar 2023 21:54:24 +0100 Subject: [PATCH 2/6] Fix changelog file name --- changelog.d/{1681.feat => 1681.feature} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog.d/{1681.feat => 1681.feature} (100%) diff --git a/changelog.d/1681.feat b/changelog.d/1681.feature similarity index 100% rename from changelog.d/1681.feat rename to changelog.d/1681.feature From d9c84e345a5a5865185c3db353df2dae55abbec1 Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Mon, 10 Apr 2023 15:19:44 +0200 Subject: [PATCH 3/6] Short-circuit setupStateSyncer Co-authored-by: Will Hunt --- src/bridge/IrcBridge.ts | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/bridge/IrcBridge.ts b/src/bridge/IrcBridge.ts index 843054051..740c69b16 100644 --- a/src/bridge/IrcBridge.ts +++ b/src/bridge/IrcBridge.ts @@ -810,26 +810,24 @@ export class IrcBridge { } private async setupStateSyncer(config: BridgeConfig) { - if (config.ircService.bridgeInfoState?.enabled) { - 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) { - 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); - }); - } - } - else { + 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) { + 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) { From 555c2b04e7a704feb2e632339a2585916cd63184 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 10 Apr 2023 15:28:49 +0200 Subject: [PATCH 4/6] Don't trigger initial sync when bridgeInfoState.initial was already true. --- src/bridge/IrcBridge.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bridge/IrcBridge.ts b/src/bridge/IrcBridge.ts index 740c69b16..93743968e 100644 --- a/src/bridge/IrcBridge.ts +++ b/src/bridge/IrcBridge.ts @@ -820,7 +820,8 @@ export class IrcBridge { bridgeName: 'org.matrix.appservice-irc', getMapping: async (roomId, { channel, networkId }) => this.createInfoMapping(channel, networkId), }); - if (config.ircService.bridgeInfoState.initial) { + 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"); From c4d99720ef4250477b46ca87e1edb1cc178fbff3 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 21 Apr 2023 22:21:18 +0200 Subject: [PATCH 5/6] Update bridgeInfoState after processing the update --- src/bridge/IrcBridge.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bridge/IrcBridge.ts b/src/bridge/IrcBridge.ts index 93743968e..2b148dada 100644 --- a/src/bridge/IrcBridge.ts +++ b/src/bridge/IrcBridge.ts @@ -829,6 +829,7 @@ export class IrcBridge { log.error("Bridge state syncing resulted in an error:", err); }); } + this.config.ircService.bridgeInfoState = config.ircService.bridgeInfoState; } private logMetric(req: Request, outcome: string) { From ebc98a8b780f6d1673eb7404c4d4c6761cea9ca9 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 26 Apr 2023 12:06:01 +0100 Subject: [PATCH 6/6] Update 1681.feature --- changelog.d/1681.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/1681.feature b/changelog.d/1681.feature index 9d41f2c95..1ace8c0ea 100644 --- a/changelog.d/1681.feature +++ b/changelog.d/1681.feature @@ -1 +1 @@ -Make bridgeInfoState configuration reloadable +Make bridgeInfoState configuration reloadable.