about summary refs log tree commit diff
path: root/LibMatrix.EventTypes
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-02-23 12:33:45 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2024-02-23 12:33:55 +0100
commitc7b7dbe3d929d787fe0c76015082a117c4222278 (patch)
treedb765a9655f875d751f061e1000e199dd209d841 /LibMatrix.EventTypes
parentHS emulator (diff)
downloadLibMatrix-bak-c7b7dbe3d929d787fe0c76015082a117c4222278.tar.xz
Unknown changes
Diffstat (limited to 'LibMatrix.EventTypes')
-rw-r--r--LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs4
-rw-r--r--LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs22
2 files changed, 23 insertions, 3 deletions
diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs
index b557e47..349c8a7 100644
--- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs
@@ -43,6 +43,10 @@ public class RoomJoinRulesEventContent : EventContent {
 
         [JsonPropertyName("room_id")]
         public required string RoomId { get; set; }
+
+        public static class Types {
+            public const string RoomMembership = "m.room_membership";
+        }
     }
 
     public enum JoinRules {
diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
index cb9ebb7..49a1b62 100644
--- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
@@ -59,15 +59,31 @@ public class RoomPowerLevelEventContent : EventContent {
 
     public bool UserHasStatePermission(string userId, string eventType) {
         ArgumentNullException.ThrowIfNull(userId);
-        return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, StateDefault ?? 50);
+        var userLevel = GetUserPowerLevel(userId);
+        var eventLevel = GetStateEventPowerLevel(eventType);
+        
+        Console.WriteLine($"{userId}={userLevel} >= {eventType}={eventLevel} = {userLevel >= eventLevel}");
+
+        return userLevel >= eventLevel;
     }
 
     public long GetUserPowerLevel(string userId) {
         ArgumentNullException.ThrowIfNull(userId);
-        return Users.TryGetValue(userId, out var level) ? level : UsersDefault ?? UsersDefault ?? 0;
+        if (Users is null) return UsersDefault ?? 0;
+        return Users.TryGetValue(userId, out var level) ? level : UsersDefault ?? 0;
     }
 
-    public long GetEventPowerLevel(string eventType) => Events.TryGetValue(eventType, out var level) ? level : EventsDefault ?? EventsDefault ?? 0;
+    public long GetStateEventPowerLevel(string eventType) {
+        ArgumentNullException.ThrowIfNull(eventType);
+        if (Events is null) return StateDefault ?? 0;
+        return Events.TryGetValue(eventType, out var level) ? level : StateDefault ?? 0;
+    }
+    
+    public long GetTimelineEventPowerLevel(string eventType) {
+        ArgumentNullException.ThrowIfNull(eventType);
+        if (Events is null) return EventsDefault ?? 0;
+        return Events.TryGetValue(eventType, out var level) ? level : EventsDefault ?? 0;
+    }
 
     public void SetUserPowerLevel(string userId, long powerLevel) {
         ArgumentNullException.ThrowIfNull(userId);