From 5affd9f061e75f6575a2fe6715f9e8757cfe87e8 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Thu, 14 Dec 2023 07:20:46 +0100 Subject: Cleanup --- .../Common/MjolnirShortcodeEventContent.cs | 9 +++ .../Common/RoomEmotesEventContent.cs | 22 ++++++ LibMatrix.EventTypes/EventContent.cs | 50 ++++++++++++++ LibMatrix.EventTypes/LibMatrix.EventTypes.csproj | 9 +++ LibMatrix.EventTypes/MatrixEventAttribute.cs | 7 ++ .../Spec/Ephemeral/PresenceStateEventContent.cs | 21 ++++++ .../Spec/Ephemeral/RoomTypingEventContent.cs | 11 +++ .../Spec/RoomMessageEventContent.cs | 46 +++++++++++++ .../State/Policy/PolicyRuleStateEventContent.cs | 74 ++++++++++++++++++++ .../Spec/State/RoomInfo/RoomAliasEventContent.cs | 11 +++ .../Spec/State/RoomInfo/RoomAvatarEventContent.cs | 28 ++++++++ .../RoomInfo/RoomCanonicalAliasEventContent.cs | 14 ++++ .../Spec/State/RoomInfo/RoomCreateEventContent.cs | 31 +++++++++ .../State/RoomInfo/RoomEncryptionEventContent.cs | 13 ++++ .../State/RoomInfo/RoomGuestAccessEventContent.cs | 15 +++++ .../RoomInfo/RoomHistoryVisibilityEventContent.cs | 9 +++ .../State/RoomInfo/RoomJoinRulesEventContent.cs | 52 +++++++++++++++ .../Spec/State/RoomInfo/RoomMemberEventContent.cs | 29 ++++++++ .../Spec/State/RoomInfo/RoomNameEventContent.cs | 11 +++ .../Spec/State/RoomInfo/RoomPinnedEventContent.cs | 9 +++ .../State/RoomInfo/RoomPowerLevelEventContent.cs | 78 ++++++++++++++++++++++ .../State/RoomInfo/RoomServerACLEventContent.cs | 15 +++++ .../Spec/State/RoomInfo/RoomTopicEventContent.cs | 10 +++ .../Spec/State/Space/SpaceChildEventContent.cs | 13 ++++ .../Spec/State/Space/SpaceParentEventContent.cs | 12 ++++ 25 files changed, 599 insertions(+) create mode 100644 LibMatrix.EventTypes/Common/MjolnirShortcodeEventContent.cs create mode 100644 LibMatrix.EventTypes/Common/RoomEmotesEventContent.cs create mode 100644 LibMatrix.EventTypes/EventContent.cs create mode 100644 LibMatrix.EventTypes/LibMatrix.EventTypes.csproj create mode 100644 LibMatrix.EventTypes/MatrixEventAttribute.cs create mode 100644 LibMatrix.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/RoomMessageEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs create mode 100644 LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs (limited to 'LibMatrix.EventTypes') diff --git a/LibMatrix.EventTypes/Common/MjolnirShortcodeEventContent.cs b/LibMatrix.EventTypes/Common/MjolnirShortcodeEventContent.cs new file mode 100644 index 0000000..7924a33 --- /dev/null +++ b/LibMatrix.EventTypes/Common/MjolnirShortcodeEventContent.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Common; + +[MatrixEvent(EventName = "org.matrix.mjolnir.shortcode")] +public class MjolnirShortcodeEventContent : TimelineEventContent { + [JsonPropertyName("shortcode")] + public string? Shortcode { get; set; } +} diff --git a/LibMatrix.EventTypes/Common/RoomEmotesEventContent.cs b/LibMatrix.EventTypes/Common/RoomEmotesEventContent.cs new file mode 100644 index 0000000..bfe480e --- /dev/null +++ b/LibMatrix.EventTypes/Common/RoomEmotesEventContent.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Common; + +[MatrixEvent(EventName = "im.ponies.room_emotes")] +public class RoomEmotesEventContent : TimelineEventContent { + [JsonPropertyName("emoticons")] + public Dictionary? Emoticons { get; set; } + + [JsonPropertyName("images")] + public Dictionary? Images { get; set; } + + [JsonPropertyName("pack")] + public PackInfo? Pack { get; set; } + + public class EmoticonData { + [JsonPropertyName("url")] + public string? Url { get; set; } + } + + public class PackInfo; // TODO: Implement this +} diff --git a/LibMatrix.EventTypes/EventContent.cs b/LibMatrix.EventTypes/EventContent.cs new file mode 100644 index 0000000..608550f --- /dev/null +++ b/LibMatrix.EventTypes/EventContent.cs @@ -0,0 +1,50 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes; + +public abstract class EventContent; + +public class UnknownEventContent : TimelineEventContent; + +public abstract class TimelineEventContent : EventContent { + [JsonPropertyName("m.relates_to")] + public MessageRelatesTo? RelatesTo { get; set; } + + [JsonPropertyName("m.new_content")] + public JsonObject? NewContent { get; set; } + + public TimelineEventContent SetReplaceRelation(string eventId) { + NewContent = JsonSerializer.SerializeToNode(this, GetType())!.AsObject(); + // NewContent = JsonSerializer.Deserialize(jsonText, GetType()); + RelatesTo = new MessageRelatesTo { + RelationType = "m.replace", + EventId = eventId + }; + return this; + } + + public T SetReplaceRelation(string eventId) where T : TimelineEventContent { + return SetReplaceRelation(eventId) as T ?? throw new InvalidOperationException(); + } + + public class MessageRelatesTo { + [JsonPropertyName("m.in_reply_to")] + public EventInReplyTo? InReplyTo { get; set; } + + [JsonPropertyName("event_id")] + public string? EventId { get; set; } + + [JsonPropertyName("rel_type")] + public string? RelationType { get; set; } + + public class EventInReplyTo { + [JsonPropertyName("event_id")] + public string? EventId { get; set; } + + [JsonPropertyName("rel_type")] + public string? RelType { get; set; } + } + } +} \ No newline at end of file diff --git a/LibMatrix.EventTypes/LibMatrix.EventTypes.csproj b/LibMatrix.EventTypes/LibMatrix.EventTypes.csproj new file mode 100644 index 0000000..3a63532 --- /dev/null +++ b/LibMatrix.EventTypes/LibMatrix.EventTypes.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/LibMatrix.EventTypes/MatrixEventAttribute.cs b/LibMatrix.EventTypes/MatrixEventAttribute.cs new file mode 100644 index 0000000..baa88ff --- /dev/null +++ b/LibMatrix.EventTypes/MatrixEventAttribute.cs @@ -0,0 +1,7 @@ +namespace LibMatrix.EventTypes; + +[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] +public class MatrixEventAttribute : Attribute { + public required string EventName { get; set; } + public bool Legacy { get; set; } +} diff --git a/LibMatrix.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs b/LibMatrix.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs new file mode 100644 index 0000000..1e98e12 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs @@ -0,0 +1,21 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.Ephemeral; + +[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")] + public long LastActiveAgo { get; set; } + [JsonPropertyName("currently_active")] + public bool CurrentlyActive { get; set; } + [JsonPropertyName("status_msg"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? StatusMessage { get; set; } + [JsonPropertyName("avatar_url"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? AvatarUrl { get; set; } + [JsonPropertyName("displayname"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? DisplayName { get; set; } +} diff --git a/LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs b/LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs new file mode 100644 index 0000000..b62b448 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[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 new file mode 100644 index 0000000..1e27bce --- /dev/null +++ b/LibMatrix.EventTypes/Spec/RoomMessageEventContent.cs @@ -0,0 +1,46 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec; + +[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 ?? ""; + } + + [JsonPropertyName("body")] + public string Body { get; set; } + + [JsonPropertyName("msgtype")] + public string MessageType { get; set; } = "m.notice"; + + [JsonPropertyName("formatted_body")] + public string? FormattedBody { get; set; } + + [JsonPropertyName("format")] + public string? Format { get; set; } + + /// + /// Media URI for this message, if any + /// + [JsonPropertyName("url")] + public string? Url { get; set; } + + public string? FileName { get; set; } + + [JsonPropertyName("info")] + public FileInfoStruct? FileInfo { get; set; } + + public class FileInfoStruct { + [JsonPropertyName("mimetype")] + public string? MimeType { get; set; } + [JsonPropertyName("size")] + public long Size { get; set; } + [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 new file mode 100644 index 0000000..d3ab8cb --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs @@ -0,0 +1,74 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State.Policy; + +//spec +[MatrixEvent(EventName = EventId)] //spec +[MatrixEvent(EventName = "m.room.rule.server")] //??? +[MatrixEvent(EventName = "org.matrix.mjolnir.rule.server")] //legacy +public class ServerPolicyRuleEventContent : PolicyRuleEventContent { + public const string EventId = "m.policy.rule.server"; +} + +[MatrixEvent(EventName = EventId)] //spec +[MatrixEvent(EventName = "m.room.rule.user")] //??? +[MatrixEvent(EventName = "org.matrix.mjolnir.rule.user")] //legacy +public class UserPolicyRuleEventContent : PolicyRuleEventContent { + public const string EventId = "m.policy.rule.user"; +} + +[MatrixEvent(EventName = EventId)] //spec +[MatrixEvent(EventName = "m.room.rule.room")] //??? +[MatrixEvent(EventName = "org.matrix.mjolnir.rule.room")] //legacy +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; } + + /// + /// Reason this user is banned + /// + [JsonPropertyName("reason")] + public string? Reason { get; set; } + + /// + /// Suggested action to take + /// + [JsonPropertyName("recommendation")] + public string? Recommendation { get; set; } + + /// + /// Expiry time in milliseconds since the unix epoch, or null if the ban has no expiry. + /// + [JsonPropertyName("support.feline.policy.expiry.rev.2")] //stable prefix: expiry, msc pending + public long? Expiry { get; set; } + + //utils + /// + /// Readable expiry time, provided for easy interaction + /// + [JsonPropertyName("gay.rory.matrix_room_utils.readable_expiry_time_utc")] + public DateTime? ExpiryDateTime { + get => Expiry == null ? null : DateTimeOffset.FromUnixTimeMilliseconds(Expiry.Value).DateTime; + set => Expiry = ((DateTimeOffset)value).ToUnixTimeMilliseconds(); + } +} + +public static class PolicyRecommendationTypes { + /// + /// Ban this user + /// + public static string Ban = "m.ban"; + + /// + /// Mute this user + /// + public static string Mute = "support.feline.policy.recommendation_mute"; //stable prefix: m.mute, msc pending +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs new file mode 100644 index 0000000..53b85b8 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State.RoomInfo; + +[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 new file mode 100644 index 0000000..d15e88e --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State.RoomInfo; + +[MatrixEvent(EventName = EventId)] +public class RoomAvatarEventContent : TimelineEventContent { + public const string EventId = "m.room.avatar"; + + [JsonPropertyName("url")] + public string? Url { get; set; } + + [JsonPropertyName("info")] + public RoomAvatarInfo? Info { get; set; } + + public class RoomAvatarInfo { + [JsonPropertyName("h")] + public int? Height { get; set; } + + [JsonPropertyName("w")] + public int? Width { get; set; } + + [JsonPropertyName("mimetype")] + public string? MimeType { get; set; } + + [JsonPropertyName("size")] + public int? Size { get; set; } + } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs new file mode 100644 index 0000000..265775e --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[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/RoomCreateEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs new file mode 100644 index 0000000..7d25dc7 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs @@ -0,0 +1,31 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = EventId)] +public class RoomCreateEventContent : TimelineEventContent { + public const string EventId = "m.room.create"; + + [JsonPropertyName("room_version")] + public string? RoomVersion { get; set; } + + [JsonPropertyName("creator")] + public string? Creator { get; set; } + + [JsonPropertyName("m.federate")] + public bool? Federate { get; set; } + + [JsonPropertyName("predecessor")] + public RoomCreatePredecessor? Predecessor { get; set; } + + [JsonPropertyName("type")] + public string? Type { get; set; } + + public class RoomCreatePredecessor { + [JsonPropertyName("room_id")] + public string? RoomId { get; set; } + + [JsonPropertyName("event_id")] + public string? EventId { get; set; } + } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs new file mode 100644 index 0000000..8e9e05f --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.encryption")] +public class RoomEncryptionEventContent : TimelineEventContent { + [JsonPropertyName("algorithm")] + public string? Algorithm { get; set; } + [JsonPropertyName("rotation_period_ms")] + public ulong? RotationPeriodMs { get; set; } + [JsonPropertyName("rotation_period_msgs")] + public ulong? RotationPeriodMsgs { get; set; } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs new file mode 100644 index 0000000..30f2def --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.guest_access")] +public class RoomGuestAccessEventContent : TimelineEventContent { + [JsonPropertyName("guest_access")] + public required string GuestAccess { get; set; } + + [JsonIgnore] + public bool IsGuestAccessEnabled { + get => GuestAccess == "can_join"; + set => GuestAccess = value ? "can_join" : "forbidden"; + } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs new file mode 100644 index 0000000..26d40e1 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.history_visibility")] +public class RoomHistoryVisibilityEventContent : TimelineEventContent { + [JsonPropertyName("history_visibility")] + public required string HistoryVisibility { get; set; } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs new file mode 100644 index 0000000..e300b5d --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs @@ -0,0 +1,52 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.join_rules")] +public class RoomJoinRulesEventContent : TimelineEventContent { + /// + /// one of ["public", "invite", "knock", "restricted", "knock_restricted"] + /// "private" is reserved without implementation! + /// + [JsonPropertyName("join_rule")] + public string JoinRuleValue { get; set; } + + [JsonIgnore] + public required JoinRules JoinRule { + get => JoinRuleValue switch { + "public" => JoinRules.Public, + "invite" => JoinRules.Invite, + "knock" => JoinRules.Knock, + "restricted" => JoinRules.Restricted, + "knock_restricted" => JoinRules.KnockRestricted, + _ => throw new ArgumentOutOfRangeException() + }; + set => JoinRuleValue = value switch { + JoinRules.Public => "public", + JoinRules.Invite => "invite", + JoinRules.Knock => "knock", + JoinRules.Restricted => "restricted", + JoinRules.KnockRestricted => "knock_restricted", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, null) + }; + } + + [JsonPropertyName("allow")] + public List? Allow { get; set; } + + public class AllowEntry { + [JsonPropertyName("type")] + public required string Type { get; set; } + + [JsonPropertyName("room_id")] + public required string RoomId { get; set; } + } + + public enum JoinRules { + Public, + Invite, + Knock, + Restricted, + KnockRestricted + } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs new file mode 100644 index 0000000..7e4f9b6 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs @@ -0,0 +1,29 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = EventId)] +public class RoomMemberEventContent : TimelineEventContent { + public const string EventId = "m.room.member"; + + [JsonPropertyName("reason")] + public string? Reason { get; set; } + + [JsonPropertyName("membership")] + public required string Membership { get; set; } + + [JsonPropertyName("displayname")] + public string? DisplayName { get; set; } + + [JsonPropertyName("is_direct")] + public bool? IsDirect { get; set; } + + [JsonPropertyName("avatar_url")] + public string? AvatarUrl { get; set; } + + [JsonPropertyName("kind")] + public string? Kind { get; set; } + + [JsonPropertyName("join_authorised_via_users_server")] + public string? JoinAuthorisedViaUsersServer { get; set; } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs new file mode 100644 index 0000000..00a1e8f --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = EventId)] +public class RoomNameEventContent : TimelineEventContent { + public const string EventId = "m.room.name"; + + [JsonPropertyName("name")] + public string? Name { get; set; } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs new file mode 100644 index 0000000..9bbcd90 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.pinned_events")] +public class RoomPinnedEventContent : TimelineEventContent { + [JsonPropertyName("pinned")] + public string[]? PinnedEvents { get; set; } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs new file mode 100644 index 0000000..1a09ab8 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs @@ -0,0 +1,78 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = EventId)] +public class RoomPowerLevelEventContent : TimelineEventContent { + public const string EventId = "m.room.power_levels"; + + [JsonPropertyName("ban")] + public long? Ban { get; set; } = 50; + + [JsonPropertyName("events_default")] + public long? EventsDefault { get; set; } = 0; + + [JsonPropertyName("invite")] + public long? Invite { get; set; } = 0; + + [JsonPropertyName("kick")] + public long? Kick { get; set; } = 50; + + [JsonPropertyName("notifications")] + public NotificationsPL? NotificationsPl { get; set; } // = null!; + + [JsonPropertyName("redact")] + public long? Redact { get; set; } = 50; + + [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!; + + [JsonPropertyName("users_default")] + public long? UsersDefault { get; set; } = 0; + + [Obsolete("Historical was a key related to MSC2716, a spec change on backfill that was dropped!", true)] + [JsonIgnore] + [JsonPropertyName("historical")] + public long Historical { get; set; } // = 50; + + public class NotificationsPL { + [JsonPropertyName("room")] + public long Room { get; set; } = 50; + } + + public bool IsUserAdmin(string userId) { + ArgumentNullException.ThrowIfNull(userId); + return Users.TryGetValue(userId, out var level) && level >= Events.Max(x => x.Value); + } + + public bool UserHasTimelinePermission(string userId, string eventType) { + ArgumentNullException.ThrowIfNull(userId); + return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault ?? 0); + } + + public bool UserHasStatePermission(string userId, string eventType) { + ArgumentNullException.ThrowIfNull(userId); + return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, StateDefault ?? 50); + } + + public long GetUserPowerLevel(string userId) { + ArgumentNullException.ThrowIfNull(userId); + return Users.TryGetValue(userId, out var level) ? level : UsersDefault ?? UsersDefault ?? 0; + } + + public long GetEventPowerLevel(string eventType) { + return Events.TryGetValue(eventType, out var level) ? level : EventsDefault ?? EventsDefault ?? 0; + } + + public void SetUserPowerLevel(string userId, long powerLevel) { + ArgumentNullException.ThrowIfNull(userId); + Users ??= new(); + Users[userId] = powerLevel; + } +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs new file mode 100644 index 0000000..75337f5 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.server_acl")] +public class RoomServerACLEventContent : TimelineEventContent { + [JsonPropertyName("allow")] + public List? Allow { get; set; } // = null!; + + [JsonPropertyName("deny")] + public List? Deny { get; set; } // = null!; + + [JsonPropertyName("allow_ip_literals")] + public bool AllowIpLiterals { get; set; } // = false; +} diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs new file mode 100644 index 0000000..3121c39 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.topic")] +[MatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)] +public class RoomTopicEventContent : TimelineEventContent { + [JsonPropertyName("topic")] + public string? Topic { get; set; } +} diff --git a/LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs b/LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs new file mode 100644 index 0000000..fb5c938 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.space.child")] +public class SpaceChildEventContent : TimelineEventContent { + [JsonPropertyName("auto_join")] + public bool? AutoJoin { get; set; } + [JsonPropertyName("via")] + public List? Via { get; set; } + [JsonPropertyName("suggested")] + public bool? Suggested { get; set; } +} diff --git a/LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs b/LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs new file mode 100644 index 0000000..0c23298 --- /dev/null +++ b/LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.space.parent")] +public class SpaceParentEventContent : TimelineEventContent { + [JsonPropertyName("via")] + public string[]? Via { get; set; } + + [JsonPropertyName("canonical")] + public bool? Canonical { get; set; } +} -- cgit 1.4.1