From 5990de6ce316c9cbb1673b994273c35867d4b1cd Mon Sep 17 00:00:00 2001 From: gnuxie Date: Tue, 16 Apr 2024 12:30:20 +0100 Subject: [PATCH] Use `handleProtectionDisable` hook to disable protection listeners. Fixes https://github.com/the-draupnir-project/Draupnir/issues/345. --- src/protections/BanPropagation.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/protections/BanPropagation.tsx b/src/protections/BanPropagation.tsx index dadf398d..1d8424e0 100644 --- a/src/protections/BanPropagation.tsx +++ b/src/protections/BanPropagation.tsx @@ -147,6 +147,9 @@ export class BanPropagationProtection implements DraupnirProtection { private readonly userConsequences: UserConsequences; + + private readonly banPropagationPromptListener = this.banReactionListener.bind(this); + private readonly unbanPropagationPromptListener = this.unbanUserReactionListener.bind(this); constructor( description: BanPropagationProtectionCapabilitiesDescription, capabilities: BanPropagationProtectionCapabilities, @@ -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> {