Sometimes we see invitations twice on protect rooms on invite.

This commit is contained in:
gnuxie
2024-05-20 16:32:48 +01:00
parent 180594502d
commit d156eb3f6e
@@ -8,7 +8,7 @@
// https://github.com/matrix-org/mjolnir
// </text>
import { AbstractProtection, ActionError, ActionResult, Logger, MatrixRoomReference, MembershipEvent, Ok, Permalink, ProtectedRoomsSet, ProtectionDescription, RoomEvent, StringRoomID, Task, Value, describeProtection, isError, serverName } from "matrix-protection-suite";
import { AbstractProtection, ActionError, ActionResult, Logger, MatrixRoomReference, MembershipEvent, Ok, Permalink, ProtectedRoomsSet, ProtectionDescription, RoomEvent, StandardDeduplicator, StringRoomID, Task, Value, describeProtection, isError, serverName } from "matrix-protection-suite";
import { Draupnir } from "../../Draupnir";
import { DraupnirProtection } from "../Protection";
import { isInvitationForUser, isSenderJoinedInRevision } from "./inviteCore";
@@ -40,6 +40,7 @@ export class ProtectRoomsOnInviteProtection
implements DraupnirProtection<
ProtectRoomsOnInviteProtectionDescription
> {
private readonly promptedToProtectedDeduplicator = new StandardDeduplicator<StringRoomID>();
private readonly protectPromptListener = this.protectListener.bind(this);
public constructor(
description: ProtectRoomsOnInviteProtectionDescription,
@@ -67,6 +68,11 @@ export class ProtectRoomsOnInviteProtection
if (this.protectedRoomsSet.isProtectedRoom(roomID)) {
return;
}
// The event handler gets called again when we join the room we were invited to.
// As sometimes we get the invitation a second time from the join section of sync.
if (this.promptedToProtectedDeduplicator.isDuplicate(roomID)) {
return;
}
void Task(this.checkAgainstRequiredMembershipRoom(event));
}