Add support for ignoring users, add user/room/event reporting
HEAD master2 files changed, 39 insertions, 1 deletions
diff --git a/LibMatrix.EventTypes/Spec/IgnoredUserListEventContent.cs b/LibMatrix.EventTypes/Spec/IgnoredUserListEventContent.cs
new file mode 100644
index 0000000..3643b8c
--- /dev/null
+++ b/LibMatrix.EventTypes/Spec/IgnoredUserListEventContent.cs
@@ -0,0 +1,27 @@
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.EventTypes.Spec;
+
+[MatrixEvent(EventName = EventId)]
+public class IgnoredUserListEventContent : EventContent {
+ public const string EventId = "m.ignored_user_list";
+
+ [JsonPropertyName("ignored_users")]
+ public Dictionary<string, IgnoredUserContent> IgnoredUsers { get; set; } = new();
+
+ // Dummy type to provide easy access to the by-spec empty content
+ public class IgnoredUserContent {
+ [JsonExtensionData]
+ public Dictionary<string, object>? AdditionalData { get; set; } = [];
+
+ public T GetAdditionalData<T>(string key) {
+ if (AdditionalData == null || !AdditionalData.TryGetValue(key, out var value))
+ throw new KeyNotFoundException($"Key '{key}' not found in AdditionalData.");
+ if (value is T tValue)
+ return tValue;
+ throw new InvalidCastException($"Value for key '{key}' cannot be cast to type '{typeof(T)}'. Cannot continue.");
+ }
+ }
+}
\ No newline at end of file
diff --git a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
index 0cb4a25..6f8c194 100644
--- a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
@@ -97,16 +97,27 @@ public abstract class PolicyRuleEventContent : EventContent {
public Regex? GetEntityRegex() => Entity is null ? null : new(Entity.Replace(".", "\\.").Replace("*", ".*").Replace("?", "."));
+ public bool IsGlobRule() =>
+ Entity != null
+ && (Entity.Contains('*') || Entity.Contains('?'));
+
public bool EntityMatches(string entity) =>
Entity != null
&& (
Entity == entity
|| (
- Entity.Contains("*") || Entity.Contains("?")
+ IsGlobRule()
? GetEntityRegex()!.IsMatch(entity)
: entity == Entity
)
);
+
+ public string? GetNormalizedRecommendation() {
+ if (Recommendation is "m.ban" or "org.matrix.mjolnir.ban")
+ return PolicyRecommendationTypes.Ban;
+
+ return Recommendation;
+ }
}
public static class PolicyRecommendationTypes {
|