mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
Remove connection from room when the state event is redacted (#258)
* Remove connections from a room when redacted * changelog
This commit is contained in:
parent
43db45a698
commit
e287cca495
1
changelog.d/258.bugfix
Normal file
1
changelog.d/258.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Connections are now properly cleaned up when the state event is redacted.
|
@ -816,8 +816,9 @@ export class Bridge {
|
|||||||
const existingConnections = this.connectionManager.getInterestedForRoomState(roomId, event.type, event.state_key);
|
const existingConnections = this.connectionManager.getInterestedForRoomState(roomId, event.type, event.state_key);
|
||||||
for (const connection of existingConnections) {
|
for (const connection of existingConnections) {
|
||||||
try {
|
try {
|
||||||
if (event.content.disabled === true) {
|
// Empty object == redacted
|
||||||
await this.connectionManager.purgeConnection(connection.roomId, connection.connectionId);
|
if (event.content.disabled === true || Object.keys(event.content).length === 0) {
|
||||||
|
await this.connectionManager.purgeConnection(connection.roomId, connection.connectionId, false);
|
||||||
} else {
|
} else {
|
||||||
connection.onStateUpdate?.(event);
|
connection.onStateUpdate?.(event);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,8 @@ export class ConnectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createConnectionForState(roomId: string, state: StateEvent<any>) {
|
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}`);
|
log.debug(`${roomId} has disabled state for ${state.type}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -387,12 +388,12 @@ export class ConnectionManager {
|
|||||||
return this.connections.find((c) => c.connectionId === connectionId && c.roomId === roomId);
|
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);
|
const connection = this.connections.find((c) => c.connectionId === connectionId && c.roomId == roomId);
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw Error("Connection not found");
|
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");
|
throw Error("Connection doesn't support removal, and so cannot be safely removed");
|
||||||
}
|
}
|
||||||
await connection.onRemove?.();
|
await connection.onRemove?.();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user