about summary refs log tree commit diff
path: root/LibMatrix.EventTypes/Spec/State
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix.EventTypes/Spec/State')
-rw-r--r--LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs13
1 files changed, 12 insertions, 1 deletions
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 {