diff --git a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
index 0569477..86950e5 100644
--- a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
@@ -43,7 +43,7 @@ public abstract class PolicyRuleEventContent : EventContent {
[FriendlyName(Name = "Entity")]
public string? Entity { get; set; }
- private bool init;
+ // private bool init;
/// <summary>
/// Reason this user is banned
@@ -93,13 +93,18 @@ public abstract class PolicyRuleEventContent : EventContent {
public string GetDraupnir2StateKey() => Convert.ToBase64String(SHA256.HashData($"{Entity}{Recommendation}".AsBytes().ToArray()));
- public Regex GetEntityRegex() => new(Entity.Replace(".", "\\.").Replace("*", ".*").Replace("?", "."));
+ public Regex? GetEntityRegex() => Entity is null ? null : new(Entity.Replace(".", "\\.").Replace("*", ".*").Replace("?", "."));
public bool EntityMatches(string entity) =>
- Entity == entity
- || (Entity.Contains("*") || Entity.Contains("?")
- ? GetEntityRegex().IsMatch(entity)
- : entity == Entity);
+ Entity != null
+ && (
+ Entity == entity
+ || (
+ Entity.Contains("*") || Entity.Contains("?")
+ ? GetEntityRegex()!.IsMatch(entity)
+ : entity == Entity
+ )
+ );
}
public static class PolicyRecommendationTypes {
diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs
index 039c61f..37b831a 100644
--- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs
@@ -1,8 +1,11 @@
+using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
namespace LibMatrix.EventTypes.Spec.State.RoomInfo;
[MatrixEvent(EventName = EventId)]
+[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global", Justification = "Deserialization, public API")]
+[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global", Justification = "Deserialization, public API")]
public class RoomCreateEventContent : EventContent {
public const string EventId = "m.room.create";
@@ -20,12 +23,12 @@ public class RoomCreateEventContent : EventContent {
[JsonPropertyName("type")]
public string? Type { get; set; }
+}
- public class RoomCreatePredecessor {
- [JsonPropertyName("room_id")]
- public string? RoomId { get; set; }
+public class RoomCreatePredecessor {
+ [JsonPropertyName("room_id")]
+ public string? RoomId { get; set; }
- [JsonPropertyName("event_id")]
- public string? EventId { get; set; }
- }
+ [JsonPropertyName("event_id")]
+ public string? EventId { get; set; }
}
\ No newline at end of file
diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
index ee1e218..c9aa603 100644
--- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
@@ -20,7 +20,7 @@ public class RoomPowerLevelEventContent : EventContent {
public long? Kick { get; set; } = 50;
[JsonPropertyName("notifications")]
- public NotificationsPL? NotificationsPl { get; set; } // = null!;
+ public NotificationsPowerLevels? NotificationsPl { get; set; } // = null!;
[JsonPropertyName("redact")]
public long? Redact { get; set; } = 50;
@@ -42,19 +42,19 @@ public class RoomPowerLevelEventContent : EventContent {
[JsonPropertyName("historical")]
public long Historical { get; set; } // = 50;
- public class NotificationsPL {
+ public class NotificationsPowerLevels {
[JsonPropertyName("room")]
public long Room { get; set; } = 50;
}
public bool IsUserAdmin(string userId) {
ArgumentNullException.ThrowIfNull(userId);
- return Users.TryGetValue(userId, out var level) && level >= Events.Max(x => x.Value);
+ return GetUserPowerLevel(userId) >= Events?.Max(x => x.Value);
}
public bool UserHasTimelinePermission(string userId, string eventType) {
ArgumentNullException.ThrowIfNull(userId);
- return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault ?? 0);
+ return GetUserPowerLevel(userId) >= Events?.GetValueOrDefault(eventType, EventsDefault ?? 0);
}
public bool UserHasStatePermission(string userId, string eventType, bool log = false) {
diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs
index cb958ae..e3fc892 100644
--- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs
@@ -3,7 +3,7 @@ using System.Text.Json.Serialization;
namespace LibMatrix.EventTypes.Spec.State.RoomInfo;
[MatrixEvent(EventName = EventId)]
-public class RoomServerACLEventContent : EventContent {
+public class RoomServerAclEventContent : EventContent {
public const string EventId = "m.room.server_acl";
[JsonPropertyName("allow")]
|