Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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) {
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<BridgeRequestData>, outcome: string) {
if (!this.timers) {
return; // metrics are disabled
Expand Down