Skip to content

Commit 5990de6

Browse files
committed
Use handleProtectionDisable hook to disable protection listeners.
Fixes #345.
1 parent ae86e17 commit 5990de6

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/protections/BanPropagation.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ export class BanPropagationProtection
147147
implements DraupnirProtection<BanPropagationProtectionCapabilitiesDescription> {
148148

149149
private readonly userConsequences: UserConsequences;
150+
151+
private readonly banPropagationPromptListener = this.banReactionListener.bind(this);
152+
private readonly unbanPropagationPromptListener = this.unbanUserReactionListener.bind(this);
150153
constructor(
151154
description: BanPropagationProtectionCapabilitiesDescription,
152155
capabilities: BanPropagationProtectionCapabilities,
@@ -155,10 +158,13 @@ export class BanPropagationProtection
155158
) {
156159
super(description, capabilities, protectedRoomsSet, [], []);
157160
this.userConsequences = capabilities.userConsequences;
158-
// FIXME: These listeners are gonna leak all over if we don't have a
159-
// hook for stopping protections.
160-
this.draupnir.reactionHandler.on(BAN_PROPAGATION_PROMPT_LISTENER, this.banReactionListener.bind(this));
161-
this.draupnir.reactionHandler.on(UNBAN_PROPAGATION_PROMPT_LISTENER, this.unbanUserReactionListener.bind(this));
161+
this.draupnir.reactionHandler.on(BAN_PROPAGATION_PROMPT_LISTENER, this.banPropagationPromptListener);
162+
this.draupnir.reactionHandler.on(UNBAN_PROPAGATION_PROMPT_LISTENER, this.unbanPropagationPromptListener);
163+
}
164+
165+
handleProtectionDisable(): void {
166+
this.draupnir.reactionHandler.off(BAN_PROPAGATION_PROMPT_LISTENER, this.banPropagationPromptListener);
167+
this.draupnir.reactionHandler.off(UNBAN_PROPAGATION_PROMPT_LISTENER, this.unbanPropagationPromptListener)
162168
}
163169

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

0 commit comments

Comments
 (0)