try to fix invalid ignore list entries
HEAD master2 files changed, 20 insertions, 7 deletions
diff --git a/LibMatrix b/LibMatrix
-Subproject f8f1feff2bcbfb2bd5fdb498b2e8572ecba37b2
+Subproject 51ff4a3b95ab38dd46c88f4e5482bf78449bb88
diff --git a/MatrixAntiDmSpam.Core/PolicyExecutor.cs b/MatrixAntiDmSpam.Core/PolicyExecutor.cs
index 4d1310a..40432b8 100644
--- a/MatrixAntiDmSpam.Core/PolicyExecutor.cs
+++ b/MatrixAntiDmSpam.Core/PolicyExecutor.cs
@@ -1,4 +1,5 @@
using System.Diagnostics;
+using System.Text.Json.Nodes;
using ArcaneLibs.Attributes;
using ArcaneLibs.Extensions;
using LibMatrix;
@@ -22,19 +23,27 @@ public class PolicyExecutor(
AuthenticatedHomeserverGeneric homeserver) : IHostedService {
private readonly GenericRoom? _logRoom = string.IsNullOrWhiteSpace(config.LogRoom) ? null : homeserver.GetRoom(config.LogRoom);
- public Task StartAsync(CancellationToken cancellationToken) {
+ public async Task StartAsync(CancellationToken cancellationToken) {
roomInviteHandler.OnInviteReceived.Add(CheckPoliciesAgainstInvite);
policyStore.OnPolicyAdded.Add(CheckPolicyAgainstOutstandingInvites);
if (config.IgnoreBannedUsers) {
+ var ignoreList = await homeserver.GetAccountDataOrNullAsync<IgnoredUserListEventContent>(IgnoredUserListEventContent.EventId);
+ if (ignoreList != null) {
+ ignoreList.IgnoredUsers.RemoveAll((id, meta) => {
+ if (meta.AdditionalData?.ContainsKey(MadsIgnoreMetadataContent.EventId) ?? false) {
+ var metadata = meta.GetAdditionalData<JsonObject>(MadsIgnoreMetadataContent.EventId);
+ if (metadata?["was_user_added"]?.GetValue<bool>() ?? false) {
+ return true;
+ }
+ }
+ return false;
+ });
+ }
policyStore.OnPoliciesChanged.Add(UpdateIgnoreList);
}
-
- return Task.CompletedTask;
}
- public Task StopAsync(CancellationToken cancellationToken) {
- return Task.CompletedTask;
- }
+ public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
#region Feature: Manage ignore list
@@ -52,7 +61,7 @@ public class PolicyExecutor(
var policyEventReference = new MadsIgnoreMetadataContent.PolicyEventReference() {
Type = newEvent.Type,
- RoomId = newEvent.RoomId,
+ RoomId = newEvent.RoomId ?? throw new InvalidOperationException("RoomId is null"),
StateKey = newEvent.StateKey!
};
@@ -102,6 +111,10 @@ public class PolicyExecutor(
await homeserver.SetAccountDataAsync(IgnoredUserListEventContent.EventId, ignoreListContent);
}
+ private async Task<IgnoredUserListEventContent> TryRecoverIgnoreList(IgnoredUserListEventContent content) {
+
+ }
+
#endregion
#region Feature: Report blocked invites
|