Skip to content

Commit

Permalink
Use handleProtectionDisable hook to disable protection listeners.
Browse files Browse the repository at this point in the history
Fixes #345.
  • Loading branch information
Gnuxie committed Apr 16, 2024
1 parent ae86e17 commit 5990de6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/protections/BanPropagation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export class BanPropagationProtection
implements DraupnirProtection<BanPropagationProtectionCapabilitiesDescription> {

private readonly userConsequences: UserConsequences;

private readonly banPropagationPromptListener = this.banReactionListener.bind(this);
private readonly unbanPropagationPromptListener = this.unbanUserReactionListener.bind(this);
constructor(
description: BanPropagationProtectionCapabilitiesDescription,
capabilities: BanPropagationProtectionCapabilities,
Expand All @@ -155,10 +158,13 @@ export class BanPropagationProtection
) {
super(description, capabilities, protectedRoomsSet, [], []);
this.userConsequences = capabilities.userConsequences;
// FIXME: These listeners are gonna leak all over if we don't have a
// hook for stopping protections.
this.draupnir.reactionHandler.on(BAN_PROPAGATION_PROMPT_LISTENER, this.banReactionListener.bind(this));
this.draupnir.reactionHandler.on(UNBAN_PROPAGATION_PROMPT_LISTENER, this.unbanUserReactionListener.bind(this));
this.draupnir.reactionHandler.on(BAN_PROPAGATION_PROMPT_LISTENER, this.banPropagationPromptListener);
this.draupnir.reactionHandler.on(UNBAN_PROPAGATION_PROMPT_LISTENER, this.unbanPropagationPromptListener);
}

handleProtectionDisable(): void {
this.draupnir.reactionHandler.off(BAN_PROPAGATION_PROMPT_LISTENER, this.banPropagationPromptListener);
this.draupnir.reactionHandler.off(UNBAN_PROPAGATION_PROMPT_LISTENER, this.unbanPropagationPromptListener)
}

public async handleMembershipChange(revision: RoomMembershipRevision, changes: MembershipChange[]): Promise<ActionResult<void>> {
Expand Down

0 comments on commit 5990de6

Please sign in to comment.