Skip to content

Commit dc5141a

Browse files
progvalHalf-Shot
andauthored
Make bridgeInfoState configuration reloadable (#1681)
* Make bridgeInfoState configuration reloadable This will be useful for tests * Fix changelog file name * Short-circuit setupStateSyncer Co-authored-by: Will Hunt <[email protected]> * Don't trigger initial sync when bridgeInfoState.initial was already true. * Update bridgeInfoState after processing the update * Update 1681.feature --------- Co-authored-by: Will Hunt <[email protected]>
1 parent e0aa290 commit dc5141a

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

changelog.d/1681.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make bridgeInfoState configuration reloadable.

src/bridge/IrcBridge.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ export class IrcBridge {
257257
log.info(`Adjusted media_url to ${newConfig.homeserver.media_url}`);
258258
}
259259

260+
await this.setupStateSyncer(newConfig);
261+
260262
this.ircHandler.onConfigChanged(newConfig.ircService.ircHandler || {});
261263
this.config.ircService.ircHandler = newConfig.ircService.ircHandler;
262264

@@ -725,20 +727,7 @@ export class IrcBridge {
725727
log.info("Fetching Matrix rooms that are already joined to...");
726728
await this.fetchJoinedRooms();
727729

728-
if (this.config.ircService.bridgeInfoState?.enabled) {
729-
this.bridgeStateSyncer = new BridgeInfoStateSyncer(this.bridge, {
730-
bridgeName: 'org.matrix.appservice-irc',
731-
getMapping: async (roomId, { channel, networkId }) => this.createInfoMapping(channel, networkId),
732-
});
733-
if (this.config.ircService.bridgeInfoState.initial) {
734-
const mappings = await this.dataStore.getAllChannelMappings();
735-
this.bridgeStateSyncer.initialSync(mappings).then(() => {
736-
log.info("Bridge state syncing completed");
737-
}).catch((err) => {
738-
log.error("Bridge state syncing resulted in an error:", err);
739-
});
740-
}
741-
}
730+
await this.setupStateSyncer(this.config);
742731

743732
log.info("Joining mapped Matrix rooms...");
744733
await this.joinMappedMatrixRooms();
@@ -822,6 +811,29 @@ export class IrcBridge {
822811
this.bridgeState = "running";
823812
}
824813

814+
private async setupStateSyncer(config: BridgeConfig) {
815+
if (!config.ircService.bridgeInfoState?.enabled) {
816+
this.bridgeStateSyncer = undefined;
817+
this.config.ircService.bridgeInfoState = undefined;
818+
return;
819+
}
820+
log.info("Syncing bridge state");
821+
this.bridgeStateSyncer = new BridgeInfoStateSyncer(this.bridge, {
822+
bridgeName: 'org.matrix.appservice-irc',
823+
getMapping: async (roomId, { channel, networkId }) => this.createInfoMapping(channel, networkId),
824+
});
825+
if (config.ircService.bridgeInfoState.initial && !this.config.ircService.bridgeInfoState?.initial) {
826+
/* Only run it on startup, or when a reload switches it from false to true */
827+
const mappings = await this.dataStore.getAllChannelMappings();
828+
this.bridgeStateSyncer.initialSync(mappings).then(() => {
829+
log.info("Bridge state syncing completed");
830+
}).catch((err) => {
831+
log.error("Bridge state syncing resulted in an error:", err);
832+
});
833+
}
834+
this.config.ircService.bridgeInfoState = config.ircService.bridgeInfoState;
835+
}
836+
825837
private logMetric(req: Request<BridgeRequestData>, outcome: string) {
826838
if (!this.timers) {
827839
return; // metrics are disabled

0 commit comments

Comments
 (0)