about summary refs log tree commit diff
path: root/LibMatrix/EventTypes/Spec/State/RoomInfo
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix/EventTypes/Spec/State/RoomInfo')
-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
5 files changed, 23 insertions, 17 deletions
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;
     }
 }