Remove connection from room when the state event is redacted (#258)

* Remove connections from a room when redacted

* changelog
This commit is contained in:
Will Hunt 2022-03-30 10:35:17 +01:00 committed by GitHub
parent 43db45a698
commit e287cca495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

1
changelog.d/258.bugfix Normal file
View File

@ -0,0 +1 @@
Connections are now properly cleaned up when the state event is redacted.

View File

@ -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);
}

View File

@ -132,7 +132,8 @@ export class ConnectionManager {
}
public async createConnectionForState(roomId: string, state: StateEvent<any>) {
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?.();