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.cs23
-rw-r--r--LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs4
-rw-r--r--LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs1
-rw-r--r--LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs5
-rw-r--r--LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs2
-rw-r--r--LibMatrix/EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs28
6 files changed, 38 insertions, 25 deletions
diff --git a/LibMatrix/EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix/EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
index 757a9e9..80d87d6 100644
--- a/LibMatrix/EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
+++ b/LibMatrix/EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
@@ -4,27 +4,34 @@ using LibMatrix.Interfaces;
 namespace LibMatrix.EventTypes.Spec.State;
 
 //spec
-[MatrixEvent(EventName = "m.policy.rule.server")] //spec
+[MatrixEvent(EventName = EventId)] //spec
 [MatrixEvent(EventName = "m.room.rule.server")] //???
 [MatrixEvent(EventName = "org.matrix.mjolnir.rule.server")] //legacy
-public class ServerPolicyRuleEventContent : PolicyRuleEventContent { }
+public class ServerPolicyRuleEventContent : PolicyRuleEventContent {
+    public const string EventId = "m.policy.rule.server";
+}
 
-[MatrixEvent(EventName = "m.policy.rule.user")] //spec
+[MatrixEvent(EventName = EventId)] //spec
 [MatrixEvent(EventName = "m.room.rule.user")] //???
 [MatrixEvent(EventName = "org.matrix.mjolnir.rule.user")] //legacy
-public class UserPolicyRuleEventContent : PolicyRuleEventContent { }
+public class UserPolicyRuleEventContent : PolicyRuleEventContent {
+    public const string EventId = "m.policy.rule.user";
+}
 
-[MatrixEvent(EventName = "m.policy.rule.room")] //spec
+[MatrixEvent(EventName = EventId)] //spec
 [MatrixEvent(EventName = "m.room.rule.room")] //???
 [MatrixEvent(EventName = "org.matrix.mjolnir.rule.room")] //legacy
-public class RoomPolicyRuleEventContent : PolicyRuleEventContent { }
+public class RoomPolicyRuleEventContent : PolicyRuleEventContent {
+    public const string EventId = "m.policy.rule.room";
+}
 
 public abstract class PolicyRuleEventContent : EventContent {
     /// <summary>
     ///     Entity this ban applies to, can use * and ? as globs.
+    ///     Policy is invalid if entity is null
     /// </summary>
     [JsonPropertyName("entity")]
-    public string Entity { get; set; }
+    public string? Entity { get; set; }
 
     /// <summary>
     ///     Reason this user is banned
@@ -65,4 +72,4 @@ public static class PolicyRecommendationTypes {
     ///     Mute this user
     /// </summary>
     public static string Mute = "support.feline.policy.recommendation_mute"; //stable prefix: m.mute, msc pending
-}
\ No newline at end of file
+}
diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs
index 28d525c..830386d 100644
--- a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs
+++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs
@@ -3,8 +3,10 @@ using LibMatrix.Interfaces;
 
 namespace LibMatrix.EventTypes.Spec.State;
 
-[MatrixEvent(EventName = "m.room.alias")]
+[MatrixEvent(EventName = EventId)]
 public class RoomAliasEventContent : TimelineEventContent {
+    public const string EventId = "m.room.alias";
+
     [JsonPropertyName("aliases")]
     public List<string>? Aliases { get; set; }
 }
diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs
index fb05b2a..9c208ba 100644
--- a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs
+++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs
@@ -6,6 +6,7 @@ namespace LibMatrix.EventTypes.Spec.State;
 [MatrixEvent(EventName = EventId)]
 public class RoomAvatarEventContent : TimelineEventContent {
     public const string EventId = "m.room.avatar";
+
     [JsonPropertyName("url")]
     public string? Url { get; set; }
 
diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs
index a5dec35..5ba253c 100644
--- a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs
+++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs
@@ -3,10 +3,13 @@ using LibMatrix.Interfaces;
 
 namespace LibMatrix.EventTypes.Spec.State;
 
-[MatrixEvent(EventName = "m.room.canonical_alias")]
+[MatrixEvent(EventName = EventId)]
 public class RoomCanonicalAliasEventContent : TimelineEventContent {
+    public const string EventId = "m.room.canonical_alias";
+
     [JsonPropertyName("alias")]
     public string? Alias { get; set; }
+
     [JsonPropertyName("alt_aliases")]
     public string[]? AltAliases { get; set; }
 }
diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs
index 3eacd44..9ad67eb 100644
--- a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs
+++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs
@@ -9,4 +9,4 @@ public class RoomNameEventContent : TimelineEventContent {
 
     [JsonPropertyName("name")]
     public string? Name { 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 6d01b8c..08f8ad5 100644
--- a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
+++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
@@ -13,9 +13,6 @@ public class RoomPowerLevelEventContent : TimelineEventContent {
     [JsonPropertyName("events_default")]
     public long? EventsDefault { get; set; } = 0;
 
-    [JsonPropertyName("events")]
-    public Dictionary<string, long>? Events { get; set; } // = null!;
-
     [JsonPropertyName("invite")]
     public long? Invite { get; set; } = 0;
 
@@ -31,6 +28,9 @@ public class RoomPowerLevelEventContent : TimelineEventContent {
     [JsonPropertyName("state_default")]
     public long? StateDefault { get; set; } = 50;
 
+    [JsonPropertyName("events")]
+    public Dictionary<string, long>? Events { get; set; } // = null!;
+
     [JsonPropertyName("users")]
     public Dictionary<string, long>? Users { get; set; } // = null!;
 
@@ -48,17 +48,22 @@ public class RoomPowerLevelEventContent : TimelineEventContent {
     }
 
     public bool IsUserAdmin(string userId) {
-        if(userId is null) throw new ArgumentNullException(nameof(userId));
+        if (userId is null) throw new ArgumentNullException(nameof(userId));
         return Users.TryGetValue(userId, out var level) && level >= Events.Max(x => x.Value);
     }
 
-    public bool UserHasPermission(string userId, string eventType) {
-        if(userId is null) throw new ArgumentNullException(nameof(userId));
+    public bool UserHasTimelinePermission(string userId, string eventType) {
+        if (userId is null) throw new ArgumentNullException(nameof(userId));
         return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault ?? 0);
     }
 
+    public bool UserHasStatePermission(string userId, string eventType) {
+        if (userId is null) throw new ArgumentNullException(nameof(userId));
+        return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, StateDefault ?? 50);
+    }
+
     public long GetUserPowerLevel(string userId) {
-        if(userId is null) throw new ArgumentNullException(nameof(userId));
+        if (userId is null) throw new ArgumentNullException(nameof(userId));
         return Users.TryGetValue(userId, out var level) ? level : UsersDefault ?? UsersDefault ?? 0;
     }
 
@@ -67,13 +72,8 @@ public class RoomPowerLevelEventContent : TimelineEventContent {
     }
 
     public void SetUserPowerLevel(string userId, long powerLevel) {
-        if(userId is null) throw new ArgumentNullException(nameof(userId));
+        if (userId is null) throw new ArgumentNullException(nameof(userId));
         Users ??= new();
-        if (Users.TryGetValue(userId, out var level)) {
-            Users[userId] = powerLevel;
-        }
-        else {
-            Users.Add(userId, powerLevel);
-        }
+        Users[userId] = powerLevel;
     }
 }