about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-09-16 08:46:54 +0200
committerRory& <root@rory.gay>2024-09-16 08:46:54 +0200
commit3346c55e34d4f3f847dfe8113cb367e4bc72a2e5 (patch)
treea3b5b9a3bb3c443bf142c00a6723f54411cbdedf
parentAuthenticated media foundations (diff)
downloadLibMatrix-3346c55e34d4f3f847dfe8113cb367e4bc72a2e5.tar.xz
Fix room joining, power levels
-rw-r--r--LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs1
-rw-r--r--LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs9
-rw-r--r--LibMatrix/RoomTypes/GenericRoom.cs9
3 files changed, 11 insertions, 8 deletions
diff --git a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
index 6006048..89e2fdb 100644
--- a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
@@ -79,6 +79,7 @@ public abstract class PolicyRuleEventContent : EventContent {
     /// </summary>
     [JsonPropertyName("gay.rory.matrix_room_utils.readable_expiry_time_utc")]
     [FriendlyName(Name = "Expires at")]
+    [TableHide]
     public DateTime? ExpiryDateTime {
         get => Expiry == null ? null : DateTimeOffset.FromUnixTimeMilliseconds(Expiry.Value).DateTime;
         set {
diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
index 49a1b62..eb156b3 100644
--- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs
@@ -57,12 +57,13 @@ public class RoomPowerLevelEventContent : EventContent {
         return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault ?? 0);
     }
 
-    public bool UserHasStatePermission(string userId, string eventType) {
+    public bool UserHasStatePermission(string userId, string eventType, bool log = false) {
         ArgumentNullException.ThrowIfNull(userId);
         var userLevel = GetUserPowerLevel(userId);
         var eventLevel = GetStateEventPowerLevel(eventType);
-        
-        Console.WriteLine($"{userId}={userLevel} >= {eventType}={eventLevel} = {userLevel >= eventLevel}");
+
+        if (log)
+            Console.WriteLine($"{userId}={userLevel} >= {eventType}={eventLevel} = {userLevel >= eventLevel}");
 
         return userLevel >= eventLevel;
     }
@@ -78,7 +79,7 @@ public class RoomPowerLevelEventContent : EventContent {
         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;
diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs
index b22ce2f..4641349 100644
--- a/LibMatrix/RoomTypes/GenericRoom.cs
+++ b/LibMatrix/RoomTypes/GenericRoom.cs
@@ -210,10 +210,11 @@ public class GenericRoom {
     public async Task<RoomIdResponse> JoinAsync(string[]? homeservers = null, string? reason = null, bool checkIfAlreadyMember = true) {
         if (checkIfAlreadyMember)
             try {
-                _ = await GetCreateEventAsync();
-                return new RoomIdResponse {
-                    RoomId = RoomId
-                };
+                var ser = await GetStateEventOrNullAsync(RoomMemberEventContent.EventId, Homeserver.UserId);
+                if (ser?.TypedContent is RoomMemberEventContent { Membership: "join" })
+                    return new RoomIdResponse {
+                        RoomId = RoomId
+                    };
             }
             catch { } //ignore