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/Ephemeral/PresenceStateEventContent.cs | 4 +++- .../Spec/Ephemeral/RoomTypingEventContent.cs | 4 +++- .../EventTypes/Spec/RoomMessageEventContent.cs | 10 ++++---- .../State/Policy/PolicyRuleStateEventContent.cs | 23 +++++++++++------- .../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 +++++++++++----------- 9 files changed, 50 insertions(+), 31 deletions(-) (limited to 'LibMatrix/EventTypes') diff --git a/LibMatrix/EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs b/LibMatrix/EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs index 558e4fc..8ffbca5 100644 --- a/LibMatrix/EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs +++ b/LibMatrix/EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs @@ -3,8 +3,10 @@ using LibMatrix.Interfaces; namespace LibMatrix.EventTypes.Spec.State; -[MatrixEvent(EventName = "m.presence")] +[MatrixEvent(EventName = EventId)] public class PresenceEventContent : EventContent { + public const string EventId = "m.presence"; + [JsonPropertyName("presence"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Presence { get; set; } [JsonPropertyName("last_active_ago")] diff --git a/LibMatrix/EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs b/LibMatrix/EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs index 661cf63..b947096 100644 --- a/LibMatrix/EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs +++ b/LibMatrix/EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs @@ -3,8 +3,10 @@ using LibMatrix.Interfaces; namespace LibMatrix.EventTypes.Spec.State; -[MatrixEvent(EventName = "m.typing")] +[MatrixEvent(EventName = EventId)] public class RoomTypingEventContent : TimelineEventContent { + public const string EventId = "m.typing"; + [JsonPropertyName("user_ids")] public string[]? UserIds { get; set; } } diff --git a/LibMatrix/EventTypes/Spec/RoomMessageEventContent.cs b/LibMatrix/EventTypes/Spec/RoomMessageEventContent.cs index 8a22489..944ed99 100644 --- a/LibMatrix/EventTypes/Spec/RoomMessageEventContent.cs +++ b/LibMatrix/EventTypes/Spec/RoomMessageEventContent.cs @@ -3,8 +3,10 @@ using LibMatrix.Interfaces; namespace LibMatrix.EventTypes.Spec; -[MatrixEvent(EventName = "m.room.message")] +[MatrixEvent(EventName = EventId)] public class RoomMessageEventContent : TimelineEventContent { + public const string EventId = "m.room.message"; + public RoomMessageEventContent(string? messageType = "m.notice", string? body = null) { MessageType = messageType; Body = body; @@ -27,9 +29,9 @@ public class RoomMessageEventContent : TimelineEventContent { /// [JsonPropertyName("url")] public string? Url { get; set; } - + public string? FileName { get; set; } - + [JsonPropertyName("info")] public FileInfoStruct? FileInfo { get; set; } @@ -41,5 +43,5 @@ public class RoomMessageEventContent : TimelineEventContent { [JsonPropertyName("thumbnail_url")] public string? ThumbnailUrl { get; set; } } - + } 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 { /// /// Entity this ban applies to, can use * and ? as globs. + /// Policy is invalid if entity is null /// [JsonPropertyName("entity")] - public string Entity { get; set; } + public string? Entity { get; set; } /// /// Reason this user is banned @@ -65,4 +72,4 @@ public static class PolicyRecommendationTypes { /// Mute this user /// 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? 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