From 56a9125672968b7c11b6d138fb3ca1851fe7e90e Mon Sep 17 00:00:00 2001 From: Rory& Date: Sat, 24 May 2025 21:17:17 +0200 Subject: Make rejecting invites not depend on having a log room configured --- MatrixAntiDmSpam.Core/InviteManager.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'MatrixAntiDmSpam.Core/InviteManager.cs') diff --git a/MatrixAntiDmSpam.Core/InviteManager.cs b/MatrixAntiDmSpam.Core/InviteManager.cs index e8a5dc1..a48cea2 100644 --- a/MatrixAntiDmSpam.Core/InviteManager.cs +++ b/MatrixAntiDmSpam.Core/InviteManager.cs @@ -23,7 +23,6 @@ public class InviteManager( public List> OnInviteRejected { get; } = []; public List> OnBeforeInviteRejected { get; } = []; - public async Task StartAsync(CancellationToken cancellationToken) { roomInviteHandler.OnInviteReceived.Add(CheckPoliciesAgainstInvite); policyStore.OnPolicyAdded.Add(CheckPolicyAgainstOutstandingInvites); @@ -90,23 +89,25 @@ public class InviteManager( var policyRoom = config.PolicyLists.First(x => x.RoomId == policyEvent.RoomId); logger.LogWarning("[{}] Rejecting invite to {}, matching {} in {}: {}", homeserver.WhoAmI.UserId, invite.RoomId, policy.GetType().GetFriendlyName(), policyRoom.Name, policy.ToJson(ignoreNull: true)); - + foreach (var callback in OnBeforeInviteRejected) { await callback(invite, policyEvent); } if (_logRoom is not null) { var roomName = await invite.TryGetRoomNameAsync(); - - await roomInviteHandler.RejectInvite(invite, new MessageBuilder() + var logMessage = new MessageBuilder() .WithColoredBody("#FF0000", cb => cb.WithBody("Rejecting invite to ").WithMention(invite.RoomId, roomName) .WithBody($", matching {policy.GetType().GetFriendlyName().ToLowerInvariant()} in {policyRoom.Name}.") .WithNewline()) .WithCollapsibleSection("Policy JSON", cb => cb.WithCodeBlock(policy.ToJson(ignoreNull: true), "json")) - ); + .Build(); + await _logRoom.SendMessageEventAsync(logMessage); } + await roomInviteHandler.RejectInvite(invite); + foreach (var callback in OnInviteRejected) { await callback(invite, policyEvent); } -- cgit 1.5.1