From 71d115dc8e915a620dd935955ba980fcbe421dad Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Fri, 1 Dec 2023 12:16:00 +0100 Subject: Cleanup, move ArcaneLibs to submodule instead of parent submodule --- .../Spec/State/RoomInfo/RoomAliasEventContent.cs | 4 +++- .../Spec/State/RoomInfo/RoomAvatarEventContent.cs | 1 + .../RoomInfo/RoomCanonicalAliasEventContent.cs | 5 +++- .../Spec/State/RoomInfo/RoomNameEventContent.cs | 2 +- .../State/RoomInfo/RoomPowerLevelEventContent.cs | 28 +++++++++++----------- 5 files changed, 23 insertions(+), 17 deletions(-) (limited to 'LibMatrix/EventTypes/Spec/State/RoomInfo') 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? 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? 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? Events { get; set; } // = null!; + [JsonPropertyName("users")] public Dictionary? 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; } } -- cgit 1.4.1