diff --git a/changelog.d/258.bugfix b/changelog.d/258.bugfix new file mode 100644 index 00000000..455000d3 --- /dev/null +++ b/changelog.d/258.bugfix @@ -0,0 +1 @@ +Connections are now properly cleaned up when the state event is redacted. \ No newline at end of file diff --git a/src/Bridge.ts b/src/Bridge.ts index 2dae2d6b..a8115722 100644 --- a/src/Bridge.ts +++ b/src/Bridge.ts @@ -816,8 +816,9 @@ export class Bridge { const existingConnections = this.connectionManager.getInterestedForRoomState(roomId, event.type, event.state_key); for (const connection of existingConnections) { try { - if (event.content.disabled === true) { - await this.connectionManager.purgeConnection(connection.roomId, connection.connectionId); + // Empty object == redacted + if (event.content.disabled === true || Object.keys(event.content).length === 0) { + await this.connectionManager.purgeConnection(connection.roomId, connection.connectionId, false); } else { connection.onStateUpdate?.(event); } diff --git a/src/ConnectionManager.ts b/src/ConnectionManager.ts index 03989bda..8f3fa414 100644 --- a/src/ConnectionManager.ts +++ b/src/ConnectionManager.ts @@ -132,7 +132,8 @@ export class ConnectionManager { } public async createConnectionForState(roomId: string, state: StateEvent) { - if (state.content.disabled === true) { + // Empty object == redacted + if (state.content.disabled === true || Object.keys(state.content).length === 0) { log.debug(`${roomId} has disabled state for ${state.type}`); return; } @@ -387,12 +388,12 @@ export class ConnectionManager { return this.connections.find((c) => c.connectionId === connectionId && c.roomId === roomId); } - public async purgeConnection(roomId: string, connectionId: string) { + public async purgeConnection(roomId: string, connectionId: string, requireNoRemoveHandler = true) { const connection = this.connections.find((c) => c.connectionId === connectionId && c.roomId == roomId); if (!connection) { throw Error("Connection not found"); } - if (!connection.onRemove) { + if (requireNoRemoveHandler && !connection.onRemove) { throw Error("Connection doesn't support removal, and so cannot be safely removed"); } await connection.onRemove?.();