Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1681.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make bridgeInfoState configuration reloadable
40 changes: 26 additions & 14 deletions src/bridge/IrcBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is a subtle-y expensive operation that might be a bit surprising on reload. I think if the config hasn't changed, we shouldn't attempt a resync.

I'm slightly more open to a resync if initial has changed.

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<BridgeRequestData>, outcome: string) {
if (!this.timers) {
return; // metrics are disabled
Expand Down