From f5447484512d726f4403f0d7725777d0a95601fb Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Tue, 19 Sep 2023 00:16:36 +0200 Subject: Add more stuff, add unit tests --- .../EventTypes/Common/MjolnirShortcodeEventData.cs | 11 +++++ LibMatrix/EventTypes/Common/RoomEmotesEventData.cs | 26 ++++++++++ LibMatrix/EventTypes/Spec/RoomMessageEventData.cs | 31 ++++++++++++ .../Spec/State/CanonicalAliasEventContent.cs | 13 +++++ .../EventTypes/Spec/State/GuestAccessEventData.cs | 16 +++++++ .../Spec/State/HistoryVisibilityEventData.cs | 11 +++++ .../EventTypes/Spec/State/JoinRulesEventData.cs | 30 ++++++++++++ .../Spec/State/PolicyRuleStateEventData.cs | 56 ++++++++++++++++++++++ .../Spec/State/PresenceStateEventData.cs | 21 ++++++++ .../Spec/State/ProfileResponseEventData.cs | 12 +++++ .../EventTypes/Spec/State/RoomAliasEventData.cs | 11 +++++ .../EventTypes/Spec/State/RoomAvatarEventData.cs | 28 +++++++++++ .../EventTypes/Spec/State/RoomCreateEventData.cs | 27 +++++++++++ .../Spec/State/RoomEncryptionEventData.cs | 15 ++++++ .../EventTypes/Spec/State/RoomMemberEventData.cs | 29 +++++++++++ .../EventTypes/Spec/State/RoomNameEventData.cs | 11 +++++ .../EventTypes/Spec/State/RoomPinnedEventData.cs | 11 +++++ .../Spec/State/RoomPowerLevelEventData.cs | 56 ++++++++++++++++++++++ .../EventTypes/Spec/State/RoomTopicEventData.cs | 12 +++++ .../EventTypes/Spec/State/RoomTypingEventData.cs | 11 +++++ .../EventTypes/Spec/State/ServerACLEventData.cs | 17 +++++++ .../EventTypes/Spec/State/SpaceChildEventData.cs | 15 ++++++ .../EventTypes/Spec/State/SpaceParentEventData.cs | 14 ++++++ LibMatrix/EventTypes/UnknownStateEventData.cs | 7 +++ LibMatrix/Extensions/HttpClientExtensions.cs | 12 ++++- LibMatrix/Extensions/StringExtensions.cs | 13 ----- LibMatrix/Helpers/MediaResolver.cs | 7 --- LibMatrix/Helpers/MessageFormatter.cs | 2 +- LibMatrix/Helpers/SyncHelper.cs | 18 +++---- .../Homeservers/AuthenticatedHomeserverGeneric.cs | 23 ++++++--- .../AuthenticatedHomeserverMxApiExtended.cs | 2 +- .../Homeservers/AuthenticatedHomeserverSynapse.cs | 2 +- LibMatrix/Homeservers/RemoteHomeServer.cs | 27 +++++++++-- LibMatrix/Interfaces/IStateEventType.cs | 4 +- LibMatrix/Responses/CreateRoomRequest.cs | 2 +- LibMatrix/Responses/StateEventResponse.cs | 5 ++ LibMatrix/RoomTypes/GenericRoom.cs | 33 ++++++++----- LibMatrix/RoomTypes/SpaceRoom.cs | 6 +-- LibMatrix/Services/HomeserverProviderService.cs | 4 +- LibMatrix/Services/HomeserverResolverService.cs | 2 +- LibMatrix/Services/TieredStorageService.cs | 6 +-- LibMatrix/StateEvent.cs | 5 +- .../Common/MjolnirShortcodeEventData.cs | 11 ----- .../StateEventTypes/Common/RoomEmotesEventData.cs | 26 ---------- .../Spec/CanonicalAliasEventContent.cs | 13 ----- .../StateEventTypes/Spec/GuestAccessEventData.cs | 16 ------- .../Spec/HistoryVisibilityEventData.cs | 11 ----- .../StateEventTypes/Spec/JoinRulesEventData.cs | 30 ------------ .../Spec/PolicyRuleStateEventData.cs | 56 ---------------------- .../StateEventTypes/Spec/PresenceStateEventData.cs | 21 -------- .../Spec/ProfileResponseEventData.cs | 12 ----- .../StateEventTypes/Spec/RoomAliasEventData.cs | 11 ----- .../StateEventTypes/Spec/RoomAvatarEventData.cs | 28 ----------- .../StateEventTypes/Spec/RoomCreateEventData.cs | 27 ----------- .../Spec/RoomEncryptionEventData.cs | 15 ------ .../StateEventTypes/Spec/RoomMemberEventData.cs | 29 ----------- .../StateEventTypes/Spec/RoomMessageEventData.cs | 32 ------------- .../StateEventTypes/Spec/RoomNameEventData.cs | 11 ----- .../StateEventTypes/Spec/RoomPinnedEventData.cs | 11 ----- .../Spec/RoomPowerLevelEventData.cs | 56 ---------------------- .../StateEventTypes/Spec/RoomTopicEventData.cs | 12 ----- .../StateEventTypes/Spec/RoomTypingEventData.cs | 11 ----- .../StateEventTypes/Spec/ServerACLEventData.cs | 17 ------- .../StateEventTypes/Spec/SpaceChildEventData.cs | 15 ------ .../StateEventTypes/Spec/SpaceParentEventData.cs | 14 ------ LibMatrix/StateEventTypes/UnknownStateEventData.cs | 7 --- 66 files changed, 594 insertions(+), 562 deletions(-) create mode 100644 LibMatrix/EventTypes/Common/MjolnirShortcodeEventData.cs create mode 100644 LibMatrix/EventTypes/Common/RoomEmotesEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/RoomMessageEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/CanonicalAliasEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/GuestAccessEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/HistoryVisibilityEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/JoinRulesEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/PolicyRuleStateEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/PresenceStateEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/ProfileResponseEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomAliasEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomAvatarEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomCreateEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomEncryptionEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomMemberEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomNameEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomPinnedEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomPowerLevelEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomTopicEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomTypingEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/ServerACLEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/SpaceChildEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/SpaceParentEventData.cs create mode 100644 LibMatrix/EventTypes/UnknownStateEventData.cs delete mode 100644 LibMatrix/Extensions/StringExtensions.cs delete mode 100644 LibMatrix/Helpers/MediaResolver.cs delete mode 100644 LibMatrix/StateEventTypes/Common/MjolnirShortcodeEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Common/RoomEmotesEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/CanonicalAliasEventContent.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/GuestAccessEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/HistoryVisibilityEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/JoinRulesEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/PolicyRuleStateEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/PresenceStateEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/ProfileResponseEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomAliasEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomAvatarEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomCreateEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomEncryptionEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomMemberEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomMessageEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomNameEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomPinnedEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomPowerLevelEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomTopicEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/RoomTypingEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/ServerACLEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/SpaceChildEventData.cs delete mode 100644 LibMatrix/StateEventTypes/Spec/SpaceParentEventData.cs delete mode 100644 LibMatrix/StateEventTypes/UnknownStateEventData.cs (limited to 'LibMatrix') diff --git a/LibMatrix/EventTypes/Common/MjolnirShortcodeEventData.cs b/LibMatrix/EventTypes/Common/MjolnirShortcodeEventData.cs new file mode 100644 index 0000000..9067351 --- /dev/null +++ b/LibMatrix/EventTypes/Common/MjolnirShortcodeEventData.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Common; + +[MatrixEvent(EventName = "org.matrix.mjolnir.shortcode")] +public class MjolnirShortcodeEventContent : EventContent { + [JsonPropertyName("shortcode")] + public string? Shortcode { get; set; } +} diff --git a/LibMatrix/EventTypes/Common/RoomEmotesEventData.cs b/LibMatrix/EventTypes/Common/RoomEmotesEventData.cs new file mode 100644 index 0000000..abf936c --- /dev/null +++ b/LibMatrix/EventTypes/Common/RoomEmotesEventData.cs @@ -0,0 +1,26 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Common; + +[MatrixEvent(EventName = "im.ponies.room_emotes")] +public class RoomEmotesEventContent : EventContent { + [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 { + + } +} diff --git a/LibMatrix/EventTypes/Spec/RoomMessageEventData.cs b/LibMatrix/EventTypes/Spec/RoomMessageEventData.cs new file mode 100644 index 0000000..b76b176 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/RoomMessageEventData.cs @@ -0,0 +1,31 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec; + +[MatrixEvent(EventName = "m.room.message")] +public class RoomMessageEventContent : EventContent { + 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; } +} diff --git a/LibMatrix/EventTypes/Spec/State/CanonicalAliasEventContent.cs b/LibMatrix/EventTypes/Spec/State/CanonicalAliasEventContent.cs new file mode 100644 index 0000000..71f3d0d --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/CanonicalAliasEventContent.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.canonical_alias")] +public class CanonicalAliasEventContent : EventContent { + [JsonPropertyName("alias")] + public string? Alias { get; set; } + [JsonPropertyName("alt_aliases")] + public string[]? AltAliases { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/GuestAccessEventData.cs b/LibMatrix/EventTypes/Spec/State/GuestAccessEventData.cs new file mode 100644 index 0000000..af1b2ce --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/GuestAccessEventData.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.guest_access")] +public class GuestAccessEventContent : EventContent { + [JsonPropertyName("guest_access")] + public string GuestAccess { get; set; } + + public bool IsGuestAccessEnabled { + get => GuestAccess == "can_join"; + set => GuestAccess = value ? "can_join" : "forbidden"; + } +} diff --git a/LibMatrix/EventTypes/Spec/State/HistoryVisibilityEventData.cs b/LibMatrix/EventTypes/Spec/State/HistoryVisibilityEventData.cs new file mode 100644 index 0000000..b57ade5 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/HistoryVisibilityEventData.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.history_visibility")] +public class HistoryVisibilityEventContent : EventContent { + [JsonPropertyName("history_visibility")] + public string HistoryVisibility { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/JoinRulesEventData.cs b/LibMatrix/EventTypes/Spec/State/JoinRulesEventData.cs new file mode 100644 index 0000000..0098bef --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/JoinRulesEventData.cs @@ -0,0 +1,30 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.join_rules")] +public class JoinRulesEventContent : EventContent { + private static string Public = "public"; + private static string Invite = "invite"; + private static string Knock = "knock"; + + /// + /// one of ["public", "invite", "knock", "restricted", "knock_restricted"] + /// "private" is reserved without implementation! + /// + [JsonPropertyName("join_rule")] + public string JoinRule { get; set; } + + [JsonPropertyName("allow")] + public List Allow { get; set; } + + public class AllowEntry { + [JsonPropertyName("type")] + public string Type { get; set; } + + [JsonPropertyName("room_id")] + public string RoomId { get; set; } + } +} diff --git a/LibMatrix/EventTypes/Spec/State/PolicyRuleStateEventData.cs b/LibMatrix/EventTypes/Spec/State/PolicyRuleStateEventData.cs new file mode 100644 index 0000000..fde02c1 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/PolicyRuleStateEventData.cs @@ -0,0 +1,56 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.policy.rule.user")] +[MatrixEvent(EventName = "m.policy.rule.server")] +[MatrixEvent(EventName = "org.matrix.mjolnir.rule.server")] +public class PolicyRuleEventContent : EventContent { + /// + /// Entity this ban applies to, can use * and ? as globs. + /// + [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/PresenceStateEventData.cs b/LibMatrix/EventTypes/Spec/State/PresenceStateEventData.cs new file mode 100644 index 0000000..b12da5b --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/PresenceStateEventData.cs @@ -0,0 +1,21 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.presence")] +public class PresenceEventContent : EventContent { + [JsonPropertyName("presence")] + 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")] + public string StatusMessage { get; set; } + [JsonPropertyName("avatar_url")] + public string AvatarUrl { get; set; } + [JsonPropertyName("displayname")] + public string DisplayName { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/ProfileResponseEventData.cs b/LibMatrix/EventTypes/Spec/State/ProfileResponseEventData.cs new file mode 100644 index 0000000..893fce1 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/ProfileResponseEventData.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +public class ProfileResponseEventContent : EventContent { + [JsonPropertyName("avatar_url")] + public string? AvatarUrl { get; set; } + + [JsonPropertyName("displayname")] + public string? DisplayName { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomAliasEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomAliasEventData.cs new file mode 100644 index 0000000..5b0e914 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomAliasEventData.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.alias")] +public class RoomAliasEventContent : EventContent { + [JsonPropertyName("aliases")] + public List? Aliases { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomAvatarEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomAvatarEventData.cs new file mode 100644 index 0000000..601d014 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomAvatarEventData.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.avatar")] +public class RoomAvatarEventContent : EventContent { + [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/RoomCreateEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomCreateEventData.cs new file mode 100644 index 0000000..e409f3a --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomCreateEventData.cs @@ -0,0 +1,27 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.create")] +public class RoomCreateEventContent : EventContent { + [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/RoomEncryptionEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomEncryptionEventData.cs new file mode 100644 index 0000000..6ffa4c5 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomEncryptionEventData.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.encryption")] +public class RoomEncryptionEventContent : EventContent { + [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/RoomMemberEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomMemberEventData.cs new file mode 100644 index 0000000..da158f1 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomMemberEventData.cs @@ -0,0 +1,29 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.member")] +public class RoomMemberEventContent : EventContent { + [JsonPropertyName("reason")] + public string? Reason { get; set; } + + [JsonPropertyName("membership")] + public string Membership { get; set; } = null!; + + [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/RoomNameEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomNameEventData.cs new file mode 100644 index 0000000..7cb881a --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomNameEventData.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.name")] +public class RoomNameEventContent : EventContent { + [JsonPropertyName("name")] + public string? Name { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomPinnedEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomPinnedEventData.cs new file mode 100644 index 0000000..eb02cc7 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomPinnedEventData.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.pinned_events")] +public class RoomPinnedEventContent : EventContent { + [JsonPropertyName("pinned")] + public string[]? PinnedEvents { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomPowerLevelEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomPowerLevelEventData.cs new file mode 100644 index 0000000..1a5d5f5 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomPowerLevelEventData.cs @@ -0,0 +1,56 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.power_levels")] +public class RoomPowerLevelEventContent : EventContent { + [JsonPropertyName("ban")] + public long? Ban { get; set; } // = 50; + + [JsonPropertyName("events_default")] + public long EventsDefault { get; set; } // = 0; + + [JsonPropertyName("events")] + public Dictionary? Events { get; set; } // = null!; + + [JsonPropertyName("invite")] + public long? Invite { get; set; } // = 50; + + [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("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) { + return Users.TryGetValue(userId, out var level) && level >= Events.Max(x=>x.Value); + } + + public bool UserHasPermission(string userId, string eventType) { + return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault); + } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomTopicEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomTopicEventData.cs new file mode 100644 index 0000000..52c7e42 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomTopicEventData.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.topic")] +[MatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)] +public class RoomTopicEventContent : EventContent { + [JsonPropertyName("topic")] + public string? Topic { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomTypingEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomTypingEventData.cs new file mode 100644 index 0000000..01cfacf --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomTypingEventData.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.typing")] +public class RoomTypingEventContent : EventContent { + [JsonPropertyName("user_ids")] + public string[]? UserIds { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/ServerACLEventData.cs b/LibMatrix/EventTypes/Spec/State/ServerACLEventData.cs new file mode 100644 index 0000000..f18fe43 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/ServerACLEventData.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.server_acl")] +public class ServerACLEventContent : EventContent { + [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/SpaceChildEventData.cs b/LibMatrix/EventTypes/Spec/State/SpaceChildEventData.cs new file mode 100644 index 0000000..a13ba2e --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/SpaceChildEventData.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.space.child")] +public class SpaceChildEventContent : EventContent { + [JsonPropertyName("auto_join")] + public bool? AutoJoin { get; set; } + [JsonPropertyName("via")] + public string[]? Via { get; set; } + [JsonPropertyName("suggested")] + public bool? Suggested { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/SpaceParentEventData.cs b/LibMatrix/EventTypes/Spec/State/SpaceParentEventData.cs new file mode 100644 index 0000000..0ffa193 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/SpaceParentEventData.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.space.parent")] +public class SpaceParentEventContent : EventContent { + [JsonPropertyName("via")] + public string[]? Via { get; set; } + + [JsonPropertyName("canonical")] + public bool? Canonical { get; set; } +} diff --git a/LibMatrix/EventTypes/UnknownStateEventData.cs b/LibMatrix/EventTypes/UnknownStateEventData.cs new file mode 100644 index 0000000..9a276c8 --- /dev/null +++ b/LibMatrix/EventTypes/UnknownStateEventData.cs @@ -0,0 +1,7 @@ +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes; + +public class UnknownEventContent : EventContent { + +} diff --git a/LibMatrix/Extensions/HttpClientExtensions.cs b/LibMatrix/Extensions/HttpClientExtensions.cs index 31ae650..a5eb40f 100644 --- a/LibMatrix/Extensions/HttpClientExtensions.cs +++ b/LibMatrix/Extensions/HttpClientExtensions.cs @@ -1,6 +1,8 @@ using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Net.Http.Headers; using System.Reflection; +using System.Text; using System.Text.Json; using ArcaneLibs.Extensions; @@ -28,7 +30,8 @@ public class MatrixHttpClient : HttpClient { if (request.RequestUri is null) throw new NullReferenceException("RequestUri is null"); if (AssertedUserId is not null) request.RequestUri = request.RequestUri.AddQuery("user_id", AssertedUserId); - Console.WriteLine($"Sending request to {request.RequestUri}"); + // Console.WriteLine($"Sending request to {request.RequestUri}"); + try { var webAssemblyEnableStreamingResponseKey = new HttpRequestOptionsKey("WebAssemblyEnableStreamingResponse"); @@ -76,4 +79,11 @@ public class MatrixHttpClient : HttpClient { response.EnsureSuccessStatusCode(); return await response.Content.ReadAsStreamAsync(cancellationToken); } + + public new async Task PutAsJsonAsync([StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, T value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) { + var request = new HttpRequestMessage(HttpMethod.Put, requestUri); + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + request.Content = new StringContent(JsonSerializer.Serialize(value, value.GetType()), Encoding.UTF8, "application/json"); + return await SendAsync(request, cancellationToken); + } } diff --git a/LibMatrix/Extensions/StringExtensions.cs b/LibMatrix/Extensions/StringExtensions.cs deleted file mode 100644 index 491fa77..0000000 --- a/LibMatrix/Extensions/StringExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace LibMatrix.Extensions; - -public static class StringExtensions { - // public static async Task GetMediaUrl(this string MxcUrl) - // { - // //MxcUrl: mxc://rory.gay/ocRVanZoUTCcifcVNwXgbtTg - // //target: https://matrix.rory.gay/_matrix/media/v3/download/rory.gay/ocRVanZoUTCcifcVNwXgbtTg - // - // var server = MxcUrl.Split('/')[2]; - // var mediaId = MxcUrl.Split('/')[3]; - // return $"{(await new RemoteHomeServer(server).Configure()).FullHomeServerDomain}/_matrix/media/v3/download/{server}/{mediaId}"; - // } -} diff --git a/LibMatrix/Helpers/MediaResolver.cs b/LibMatrix/Helpers/MediaResolver.cs deleted file mode 100644 index 5886618..0000000 --- a/LibMatrix/Helpers/MediaResolver.cs +++ /dev/null @@ -1,7 +0,0 @@ -using LibMatrix.Services; - -namespace LibMatrix.Helpers; - -public static class MediaResolver { - public static string ResolveMediaUri(string homeserver, string mxc) => mxc.Replace("mxc://", $"{homeserver}/_matrix/media/v3/download/"); -} diff --git a/LibMatrix/Helpers/MessageFormatter.cs b/LibMatrix/Helpers/MessageFormatter.cs index 37d7004..ae02afc 100644 --- a/LibMatrix/Helpers/MessageFormatter.cs +++ b/LibMatrix/Helpers/MessageFormatter.cs @@ -1,5 +1,5 @@ using ArcaneLibs.Extensions; -using LibMatrix.StateEventTypes.Spec; +using LibMatrix.EventTypes.Spec; namespace LibMatrix.Helpers; diff --git a/LibMatrix/Helpers/SyncHelper.cs b/LibMatrix/Helpers/SyncHelper.cs index d719184..386fd4d 100644 --- a/LibMatrix/Helpers/SyncHelper.cs +++ b/LibMatrix/Helpers/SyncHelper.cs @@ -9,17 +9,17 @@ using LibMatrix.Services; namespace LibMatrix.Helpers; -public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, TieredStorageService storageService) { +public class SyncHelper(AuthenticatedHomeserverGeneric homeserver) { public async Task Sync( string? since = null, int? timeout = 30000, string? setPresence = "online", SyncFilter? filter = null, CancellationToken? cancellationToken = null) { - var outFileName = "sync-" + - (await storageService.CacheStorageProvider.GetAllKeysAsync()).Count( - x => x.StartsWith("sync")) + - ".json"; + // var outFileName = "sync-" + + // (await storageService.CacheStorageProvider.GetAllKeysAsync()).Count( + // x => x.StartsWith("sync")) + + // ".json"; var url = $"/_matrix/client/v3/sync?timeout={timeout}&set_presence={setPresence}"; if (!string.IsNullOrWhiteSpace(since)) url += $"&since={since}"; if (filter is not null) url += $"&filter={filter.ToJson(ignoreNull: true, indent: false)}"; @@ -65,10 +65,10 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, TieredStorage SyncFilter? filter = null, CancellationToken? cancellationToken = null ) { - await Task.WhenAll((await storageService.CacheStorageProvider.GetAllKeysAsync()) - .Where(x => x.StartsWith("sync")) - .ToList() - .Select(x => storageService.CacheStorageProvider.DeleteObjectAsync(x))); + // await Task.WhenAll((await storageService.CacheStorageProvider.GetAllKeysAsync()) + // .Where(x => x.StartsWith("sync")) + // .ToList() + // .Select(x => storageService.CacheStorageProvider.DeleteObjectAsync(x))); var nextBatch = since; while (cancellationToken is null || !cancellationToken.Value.IsCancellationRequested) { var sync = await Sync(since: nextBatch, timeout: timeout, setPresence: setPresence, filter: filter, diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs index a280c54..b881e6c 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs @@ -12,25 +12,26 @@ using LibMatrix.Services; namespace LibMatrix.Homeservers; public class AuthenticatedHomeserverGeneric : RemoteHomeServer { - public AuthenticatedHomeserverGeneric(TieredStorageService storage, string canonicalHomeServerDomain, string accessToken) : base(canonicalHomeServerDomain) { - Storage = storage; + public AuthenticatedHomeserverGeneric(string canonicalHomeServerDomain, string accessToken) : base(canonicalHomeServerDomain) { AccessToken = accessToken.Trim(); - SyncHelper = new SyncHelper(this, storage); + SyncHelper = new SyncHelper(this); } - public virtual TieredStorageService Storage { get; set; } public virtual SyncHelper SyncHelper { get; init; } public virtual WhoAmIResponse WhoAmI { get; set; } = null!; public virtual string UserId => WhoAmI.UserId; public virtual string AccessToken { get; set; } - public virtual Task GetRoom(string roomId) => Task.FromResult(new(this, roomId)); + public virtual GenericRoom GetRoom(string roomId) { + if(roomId is null || !roomId.StartsWith("!")) throw new ArgumentException("Room ID must start with !", nameof(roomId)); + return new GenericRoom(this, roomId); + } public virtual async Task> GetJoinedRooms() { var roomQuery = await _httpClient.GetAsync("/_matrix/client/v3/joined_rooms"); var roomsJson = await roomQuery.Content.ReadFromJsonAsync(); - var rooms = roomsJson.GetProperty("joined_rooms").EnumerateArray().Select(room => new GenericRoom(this, room.GetString()!)).ToList(); + var rooms = roomsJson.GetProperty("joined_rooms").EnumerateArray().Select(room => GetRoom(room.GetString()!)).ToList(); Console.WriteLine($"Fetched {rooms.Count} rooms"); @@ -58,7 +59,7 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeServer { throw new InvalidDataException($"Failed to create room: {await res.Content.ReadAsStringAsync()}"); } - var room = await GetRoom((await res.Content.ReadFromJsonAsync())!["room_id"]!.ToString()); + var room = GetRoom((await res.Content.ReadFromJsonAsync())!["room_id"]!.ToString()); foreach (var user in creationEvent.Invite) { await room.InviteUser(user); @@ -67,6 +68,14 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeServer { return room; } + public virtual async Task Logout() { + var res = await _httpClient.PostAsync("/_matrix/client/v3/logout", null); + if (!res.IsSuccessStatusCode) { + Console.WriteLine($"Failed to logout: {await res.Content.ReadAsStringAsync()}"); + throw new InvalidDataException($"Failed to logout: {await res.Content.ReadAsStringAsync()}"); + } + } + #region Utility Functions public virtual async IAsyncEnumerable GetJoinedRoomsByType(string type) { var rooms = await GetJoinedRooms(); diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverMxApiExtended.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverMxApiExtended.cs index e44d727..5319f46 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverMxApiExtended.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverMxApiExtended.cs @@ -4,5 +4,5 @@ using LibMatrix.Services; namespace LibMatrix.Homeservers; -public class AuthenticatedHomeserverMxApiExtended(TieredStorageService storage, string canonicalHomeServerDomain, string accessToken) : AuthenticatedHomeserverGeneric(storage, canonicalHomeServerDomain, +public class AuthenticatedHomeserverMxApiExtended(string canonicalHomeServerDomain, string accessToken) : AuthenticatedHomeserverGeneric(canonicalHomeServerDomain, accessToken); diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs index 218ded0..ae26f69 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs @@ -102,7 +102,7 @@ public class AuthenticatedHomeserverSynapse : AuthenticatedHomeserverGeneric { } } - public AuthenticatedHomeserverSynapse(TieredStorageService storage, string canonicalHomeServerDomain, string accessToken) : base(storage, canonicalHomeServerDomain, accessToken) { + public AuthenticatedHomeserverSynapse(string canonicalHomeServerDomain, string accessToken) : base(canonicalHomeServerDomain, accessToken) { Admin = new(this); } } diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs index caed397..ab3ab51 100644 --- a/LibMatrix/Homeservers/RemoteHomeServer.cs +++ b/LibMatrix/Homeservers/RemoteHomeServer.cs @@ -1,7 +1,9 @@ using System.Net.Http.Json; +using System.Text.Json.Serialization; +using ArcaneLibs.Extensions; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Extensions; using LibMatrix.Responses; -using LibMatrix.StateEventTypes.Spec; namespace LibMatrix.Homeservers; @@ -13,12 +15,13 @@ public class RemoteHomeServer(string canonicalHomeServerDomain) { public string FullHomeServerDomain { get; set; } public MatrixHttpClient _httpClient { get; set; } = new(); - public async Task GetProfile(string mxid) { - if(mxid is null) throw new ArgumentNullException(nameof(mxid)); + public async Task GetProfileAsync(string mxid) { + if (mxid is null) throw new ArgumentNullException(nameof(mxid)); if (_profileCache.TryGetValue(mxid, out var value)) { if (value is SemaphoreSlim s) await s.WaitAsync(); if (value is ProfileResponseEventContent p) return p; } + _profileCache[mxid] = new SemaphoreSlim(1); var resp = await _httpClient.GetAsync($"/_matrix/client/v3/profile/{mxid}"); @@ -29,10 +32,26 @@ public class RemoteHomeServer(string canonicalHomeServerDomain) { return data; } - public async Task GetClientVersions() { + public async Task GetClientVersionsAsync() { var resp = await _httpClient.GetAsync($"/_matrix/client/versions"); var data = await resp.Content.ReadFromJsonAsync(); if (!resp.IsSuccessStatusCode) Console.WriteLine("ClientVersions: " + data); return data; } + + public async Task ResolveRoomAliasAsync(string alias) { + var resp = await _httpClient.GetAsync($"/_matrix/client/v3/directory/room/{alias.Replace("#", "%23")}"); + var data = await resp.Content.ReadFromJsonAsync(); + var text = await resp.Content.ReadAsStringAsync(); + if (!resp.IsSuccessStatusCode) Console.WriteLine("ResolveAlias: " + data.ToJson()); + return data; + } +} + +public class AliasResult { + [JsonPropertyName("room_id")] + public string RoomId { get; set; } = null!; + + [JsonPropertyName("servers")] + public List Servers { get; set; } = null!; } diff --git a/LibMatrix/Interfaces/IStateEventType.cs b/LibMatrix/Interfaces/IStateEventType.cs index f2e4a3b..b187970 100644 --- a/LibMatrix/Interfaces/IStateEventType.cs +++ b/LibMatrix/Interfaces/IStateEventType.cs @@ -4,10 +4,10 @@ namespace LibMatrix.Interfaces; public abstract class EventContent { [JsonPropertyName("m.relates_to")] - public virtual MessageRelatesTo? RelatesTo { get; set; } + public MessageRelatesTo? RelatesTo { get; set; } [JsonPropertyName("m.new_content")] - public virtual EventContent? NewContent { get; set; } + public EventContent? NewContent { get; set; } public abstract class MessageRelatesTo { [JsonPropertyName("m.in_reply_to")] diff --git a/LibMatrix/Responses/CreateRoomRequest.cs b/LibMatrix/Responses/CreateRoomRequest.cs index 82a4b12..381271b 100644 --- a/LibMatrix/Responses/CreateRoomRequest.cs +++ b/LibMatrix/Responses/CreateRoomRequest.cs @@ -2,10 +2,10 @@ using System.Reflection; using System.Text.Json.Nodes; using System.Text.Json.Serialization; using System.Text.RegularExpressions; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Helpers; using LibMatrix.Homeservers; using LibMatrix.Interfaces; -using LibMatrix.StateEventTypes.Spec; namespace LibMatrix.Responses; diff --git a/LibMatrix/Responses/StateEventResponse.cs b/LibMatrix/Responses/StateEventResponse.cs index c60d71c..7ca6bab 100644 --- a/LibMatrix/Responses/StateEventResponse.cs +++ b/LibMatrix/Responses/StateEventResponse.cs @@ -45,3 +45,8 @@ public class StateEventResponse : StateEvent { public JsonObject? PrevContent { get; set; } } } + +public class ChunkedStateEventResponse { + [JsonPropertyName("chunk")] + public List? Chunk { get; set; } +} diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index 146b5dd..ab748fe 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -2,10 +2,12 @@ using System.Net.Http.Json; using System.Text.Json; using System.Text.Json.Serialization; using System.Web; +using LibMatrix.EventTypes.Spec; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Extensions; using LibMatrix.Homeservers; +using LibMatrix.Interfaces; using LibMatrix.Responses; -using LibMatrix.StateEventTypes.Spec; using Microsoft.Extensions.Logging; namespace LibMatrix.RoomTypes; @@ -65,12 +67,12 @@ public class GenericRoom { #endif } catch (MatrixException e) { - if (e is not { ErrorCode: "M_NOT_FOUND" }) { + // if (e is not { ErrorCodode: "M_NOT_FOUND" }) { throw; - } + // } - Console.WriteLine(e); - return default; + // Console.WriteLine(e); + // return default; } } @@ -93,7 +95,7 @@ public class GenericRoom { } } - public async Task JoinAsync(string[]? homeservers = null, string? reason = null) { + public async Task JoinAsync(string[]? homeservers = null, string? reason = null) { var join_url = $"/_matrix/client/v3/join/{HttpUtility.UrlEncode(RoomId)}"; Console.WriteLine($"Calling {join_url} with {homeservers?.Length ?? 0} via's..."); if (homeservers == null || homeservers.Length == 0) homeservers = new[] { RoomId.Split(':')[1] }; @@ -101,6 +103,7 @@ public class GenericRoom { var res = await _httpClient.PostAsJsonAsync(fullJoinUrl, new { reason }); + return await res.Content.ReadFromJsonAsync() ?? throw new Exception("Failed to join room?"); } // TODO: rewrite (members endpoint?) @@ -111,10 +114,10 @@ public class GenericRoom { // if (joinedOnly && (member.TypedContent as RoomMemberEventContent)?.Membership is not "join") continue; // yield return member; // } - var res = await _httpClient.GetAsync($"/_matrix/client/v3/rooms/{RoomId}/members"); - var result = - JsonSerializer.DeserializeAsyncEnumerable(await res.Content.ReadAsStreamAsync()); - await foreach (var resp in result) { + var res = await _httpClient.GetAsync($"/_matrix/client/v3/rooms/{RoomId}/members?limit=2"); + var resText = await res.Content.ReadAsStringAsync(); + var result = await JsonSerializer.DeserializeAsync(await res.Content.ReadAsStreamAsync()); + foreach (var resp in result.Chunk) { if (resp?.Type != "m.room.member") continue; if (joinedOnly && (resp.TypedContent as RoomMemberEventContent)?.Membership is not "join") continue; yield return resp; @@ -123,6 +126,9 @@ public class GenericRoom { #region Utility shortcuts + public async Task SendMessageEventAsync(RoomMessageEventContent content) => + await SendTimelineEventAsync("m.room.message", content); + public async Task> GetAliasesAsync() { var res = await GetStateAsync("m.room.aliases"); return res.Aliases; @@ -187,7 +193,7 @@ public class GenericRoom { await (await _httpClient.PutAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/state/{eventType}/{stateKey}", content)) .Content.ReadFromJsonAsync(); - public async Task SendMessageEventAsync(string eventType, RoomMessageEventContent content) { + public async Task SendTimelineEventAsync(string eventType, EventContent content) { var res = await _httpClient.PutAsJsonAsync( $"/_matrix/client/v3/rooms/{RoomId}/send/{eventType}/" + Guid.NewGuid(), content, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull @@ -244,3 +250,8 @@ public class GenericRoom { await _httpClient.PostAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/invite", new UserIdAndReason(userId, reason)); } } + +public class RoomIdResponse { + [JsonPropertyName("room_id")] + public string RoomId { get; set; } = null!; +} diff --git a/LibMatrix/RoomTypes/SpaceRoom.cs b/LibMatrix/RoomTypes/SpaceRoom.cs index 0a4447a..a43ae82 100644 --- a/LibMatrix/RoomTypes/SpaceRoom.cs +++ b/LibMatrix/RoomTypes/SpaceRoom.cs @@ -13,14 +13,14 @@ public class SpaceRoom : GenericRoom { private static SemaphoreSlim _semaphore = new(1, 1); public async IAsyncEnumerable GetChildrenAsync(bool includeRemoved = false) { - await _semaphore.WaitAsync(); + // await _semaphore.WaitAsync(); var rooms = new List(); var state = GetFullStateAsync(); await foreach (var stateEvent in state) { if (stateEvent.Type != "m.space.child") continue; if (stateEvent.RawContent.ToJson() != "{}" || includeRemoved) - yield return await _homeserver.GetRoom(stateEvent.StateKey); + yield return _homeserver.GetRoom(stateEvent.StateKey); } - _semaphore.Release(); + // _semaphore.Release(); } } diff --git a/LibMatrix/Services/HomeserverProviderService.cs b/LibMatrix/Services/HomeserverProviderService.cs index 71d9860..49167fa 100644 --- a/LibMatrix/Services/HomeserverProviderService.cs +++ b/LibMatrix/Services/HomeserverProviderService.cs @@ -39,10 +39,10 @@ public class HomeserverProviderService { AuthenticatedHomeserverGeneric hs; if (true) { - hs = new AuthenticatedHomeserverMxApiExtended(_tieredStorageService, homeserver, accessToken); + hs = new AuthenticatedHomeserverMxApiExtended(homeserver, accessToken); } else { - hs = new AuthenticatedHomeserverGeneric(_tieredStorageService, homeserver, accessToken); + hs = new AuthenticatedHomeserverGeneric(homeserver, accessToken); } hs.FullHomeServerDomain = domain; diff --git a/LibMatrix/Services/HomeserverResolverService.cs b/LibMatrix/Services/HomeserverResolverService.cs index f2c0781..685724b 100644 --- a/LibMatrix/Services/HomeserverResolverService.cs +++ b/LibMatrix/Services/HomeserverResolverService.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.Logging; namespace LibMatrix.Services; -public class HomeserverResolverService(ILogger? logger) { +public class HomeserverResolverService(ILogger? logger = null) { private readonly MatrixHttpClient _httpClient = new(); private static readonly Dictionary _wellKnownCache = new(); diff --git a/LibMatrix/Services/TieredStorageService.cs b/LibMatrix/Services/TieredStorageService.cs index 954a2ce..f242785 100644 --- a/LibMatrix/Services/TieredStorageService.cs +++ b/LibMatrix/Services/TieredStorageService.cs @@ -3,10 +3,10 @@ using LibMatrix.Interfaces.Services; namespace LibMatrix.Services; public class TieredStorageService { - public IStorageProvider CacheStorageProvider { get; } - public IStorageProvider DataStorageProvider { get; } + public IStorageProvider? CacheStorageProvider { get; } + public IStorageProvider? DataStorageProvider { get; } - public TieredStorageService(IStorageProvider cacheStorageProvider, IStorageProvider dataStorageProvider) { + public TieredStorageService(IStorageProvider? cacheStorageProvider, IStorageProvider? dataStorageProvider) { CacheStorageProvider = cacheStorageProvider; DataStorageProvider = dataStorageProvider; } diff --git a/LibMatrix/StateEvent.cs b/LibMatrix/StateEvent.cs index 9ca9141..97348a5 100644 --- a/LibMatrix/StateEvent.cs +++ b/LibMatrix/StateEvent.cs @@ -4,15 +4,14 @@ using System.Text.Json.Nodes; using System.Text.Json.Serialization; using ArcaneLibs; using ArcaneLibs.Extensions; +using LibMatrix.EventTypes; using LibMatrix.Helpers; using LibMatrix.Interfaces; -using LibMatrix.StateEventTypes; namespace LibMatrix; public class StateEvent { - public static readonly List KnownStateEventTypes = - new ClassCollector().ResolveFromAllAccessibleAssemblies(); + public static List KnownStateEventTypes { get; } = new ClassCollector().ResolveFromAllAccessibleAssemblies(); public static readonly Dictionary KnownStateEventTypesByName = KnownStateEventTypes.Aggregate( new Dictionary(), diff --git a/LibMatrix/StateEventTypes/Common/MjolnirShortcodeEventData.cs b/LibMatrix/StateEventTypes/Common/MjolnirShortcodeEventData.cs deleted file mode 100644 index ff11be7..0000000 --- a/LibMatrix/StateEventTypes/Common/MjolnirShortcodeEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Common; - -[MatrixEvent(EventName = "org.matrix.mjolnir.shortcode")] -public class MjolnirShortcodeEventContent : EventContent { - [JsonPropertyName("shortcode")] - public string? Shortcode { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Common/RoomEmotesEventData.cs b/LibMatrix/StateEventTypes/Common/RoomEmotesEventData.cs deleted file mode 100644 index a056eda..0000000 --- a/LibMatrix/StateEventTypes/Common/RoomEmotesEventData.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Common; - -[MatrixEvent(EventName = "im.ponies.room_emotes")] -public class RoomEmotesEventContent : EventContent { - [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 { - - } -} diff --git a/LibMatrix/StateEventTypes/Spec/CanonicalAliasEventContent.cs b/LibMatrix/StateEventTypes/Spec/CanonicalAliasEventContent.cs deleted file mode 100644 index 7a0e84c..0000000 --- a/LibMatrix/StateEventTypes/Spec/CanonicalAliasEventContent.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.canonical_alias")] -public class CanonicalAliasEventContent : EventContent { - [JsonPropertyName("alias")] - public string? Alias { get; set; } - [JsonPropertyName("alt_aliases")] - public string[]? AltAliases { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/GuestAccessEventData.cs b/LibMatrix/StateEventTypes/Spec/GuestAccessEventData.cs deleted file mode 100644 index 0709b86..0000000 --- a/LibMatrix/StateEventTypes/Spec/GuestAccessEventData.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.guest_access")] -public class GuestAccessEventContent : EventContent { - [JsonPropertyName("guest_access")] - public string GuestAccess { get; set; } - - public bool IsGuestAccessEnabled { - get => GuestAccess == "can_join"; - set => GuestAccess = value ? "can_join" : "forbidden"; - } -} diff --git a/LibMatrix/StateEventTypes/Spec/HistoryVisibilityEventData.cs b/LibMatrix/StateEventTypes/Spec/HistoryVisibilityEventData.cs deleted file mode 100644 index b19dd32..0000000 --- a/LibMatrix/StateEventTypes/Spec/HistoryVisibilityEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.history_visibility")] -public class HistoryVisibilityEventContent : EventContent { - [JsonPropertyName("history_visibility")] - public string HistoryVisibility { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/JoinRulesEventData.cs b/LibMatrix/StateEventTypes/Spec/JoinRulesEventData.cs deleted file mode 100644 index 8c0772f..0000000 --- a/LibMatrix/StateEventTypes/Spec/JoinRulesEventData.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.join_rules")] -public class JoinRulesEventContent : EventContent { - private static string Public = "public"; - private static string Invite = "invite"; - private static string Knock = "knock"; - - /// - /// one of ["public", "invite", "knock", "restricted", "knock_restricted"] - /// "private" is reserved without implementation! - /// - [JsonPropertyName("join_rule")] - public string JoinRule { get; set; } - - [JsonPropertyName("allow")] - public List Allow { get; set; } - - public class AllowEntry { - [JsonPropertyName("type")] - public string Type { get; set; } - - [JsonPropertyName("room_id")] - public string RoomId { get; set; } - } -} diff --git a/LibMatrix/StateEventTypes/Spec/PolicyRuleStateEventData.cs b/LibMatrix/StateEventTypes/Spec/PolicyRuleStateEventData.cs deleted file mode 100644 index 539e371..0000000 --- a/LibMatrix/StateEventTypes/Spec/PolicyRuleStateEventData.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.policy.rule.user")] -[MatrixEvent(EventName = "m.policy.rule.server")] -[MatrixEvent(EventName = "org.matrix.mjolnir.rule.server")] -public class PolicyRuleEventContent : EventContent { - /// - /// Entity this ban applies to, can use * and ? as globs. - /// - [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/StateEventTypes/Spec/PresenceStateEventData.cs b/LibMatrix/StateEventTypes/Spec/PresenceStateEventData.cs deleted file mode 100644 index b897ff0..0000000 --- a/LibMatrix/StateEventTypes/Spec/PresenceStateEventData.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.presence")] -public class PresenceEventContent : EventContent { - [JsonPropertyName("presence")] - 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")] - public string StatusMessage { get; set; } - [JsonPropertyName("avatar_url")] - public string AvatarUrl { get; set; } - [JsonPropertyName("displayname")] - public string DisplayName { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/ProfileResponseEventData.cs b/LibMatrix/StateEventTypes/Spec/ProfileResponseEventData.cs deleted file mode 100644 index 9b4f1d0..0000000 --- a/LibMatrix/StateEventTypes/Spec/ProfileResponseEventData.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -public class ProfileResponseEventContent : EventContent { - [JsonPropertyName("avatar_url")] - public string? AvatarUrl { get; set; } - - [JsonPropertyName("displayname")] - public string? DisplayName { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/RoomAliasEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomAliasEventData.cs deleted file mode 100644 index d3960a1..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomAliasEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.alias")] -public class RoomAliasEventContent : EventContent { - [JsonPropertyName("aliases")] - public List? Aliases { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/RoomAvatarEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomAvatarEventData.cs deleted file mode 100644 index e2263c8..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomAvatarEventData.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.avatar")] -public class RoomAvatarEventContent : EventContent { - [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/StateEventTypes/Spec/RoomCreateEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomCreateEventData.cs deleted file mode 100644 index 22df784..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomCreateEventData.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.create")] -public class RoomCreateEventContent : EventContent { - [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/StateEventTypes/Spec/RoomEncryptionEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomEncryptionEventData.cs deleted file mode 100644 index 1d5ec2c..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomEncryptionEventData.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.encryption")] -public class RoomEncryptionEventContent : EventContent { - [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/StateEventTypes/Spec/RoomMemberEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomMemberEventData.cs deleted file mode 100644 index a9d4710..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomMemberEventData.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.member")] -public class RoomMemberEventContent : EventContent { - [JsonPropertyName("reason")] - public string? Reason { get; set; } - - [JsonPropertyName("membership")] - public string Membership { get; set; } = null!; - - [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/StateEventTypes/Spec/RoomMessageEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomMessageEventData.cs deleted file mode 100644 index a15efe8..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomMessageEventData.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Text.Json.Serialization; -using ArcaneLibs.Extensions; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.message")] -public class RoomMessageEventContent : EventContent { - 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; } -} diff --git a/LibMatrix/StateEventTypes/Spec/RoomNameEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomNameEventData.cs deleted file mode 100644 index 3002102..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomNameEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.name")] -public class RoomNameEventContent : EventContent { - [JsonPropertyName("name")] - public string? Name { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/RoomPinnedEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomPinnedEventData.cs deleted file mode 100644 index 16144bc..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomPinnedEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.pinned_events")] -public class RoomPinnedEventContent : EventContent { - [JsonPropertyName("pinned")] - public string[]? PinnedEvents { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/RoomPowerLevelEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomPowerLevelEventData.cs deleted file mode 100644 index 960c198..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomPowerLevelEventData.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.power_levels")] -public class RoomPowerLevelEventContent : EventContent { - [JsonPropertyName("ban")] - public long Ban { get; set; } // = 50; - - [JsonPropertyName("events_default")] - public long EventsDefault { get; set; } // = 0; - - [JsonPropertyName("events")] - public Dictionary Events { get; set; } // = null!; - - [JsonPropertyName("invite")] - public long Invite { get; set; } // = 50; - - [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("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) { - return Users.TryGetValue(userId, out var level) && level >= Events.Max(x=>x.Value); - } - - public bool UserHasPermission(string userId, string eventType) { - return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault); - } -} diff --git a/LibMatrix/StateEventTypes/Spec/RoomTopicEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomTopicEventData.cs deleted file mode 100644 index 61d1a01..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomTopicEventData.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.topic")] -[MatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)] -public class RoomTopicEventContent : EventContent { - [JsonPropertyName("topic")] - public string? Topic { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/RoomTypingEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomTypingEventData.cs deleted file mode 100644 index e935cb2..0000000 --- a/LibMatrix/StateEventTypes/Spec/RoomTypingEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.typing")] -public class RoomTypingEventContent : EventContent { - [JsonPropertyName("user_ids")] - public string[]? UserIds { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/ServerACLEventData.cs b/LibMatrix/StateEventTypes/Spec/ServerACLEventData.cs deleted file mode 100644 index 031d113..0000000 --- a/LibMatrix/StateEventTypes/Spec/ServerACLEventData.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.room.server_acl")] -public class ServerACLEventContent : EventContent { - [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/StateEventTypes/Spec/SpaceChildEventData.cs b/LibMatrix/StateEventTypes/Spec/SpaceChildEventData.cs deleted file mode 100644 index 80fc771..0000000 --- a/LibMatrix/StateEventTypes/Spec/SpaceChildEventData.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.space.child")] -public class SpaceChildEventContent : EventContent { - [JsonPropertyName("auto_join")] - public bool? AutoJoin { get; set; } - [JsonPropertyName("via")] - public string[]? Via { get; set; } - [JsonPropertyName("suggested")] - public bool? Suggested { get; set; } -} diff --git a/LibMatrix/StateEventTypes/Spec/SpaceParentEventData.cs b/LibMatrix/StateEventTypes/Spec/SpaceParentEventData.cs deleted file mode 100644 index 1bc89ab..0000000 --- a/LibMatrix/StateEventTypes/Spec/SpaceParentEventData.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes.Spec; - -[MatrixEvent(EventName = "m.space.parent")] -public class SpaceParentEventContent : EventContent { - [JsonPropertyName("via")] - public string[]? Via { get; set; } - - [JsonPropertyName("canonical")] - public bool? Canonical { get; set; } -} diff --git a/LibMatrix/StateEventTypes/UnknownStateEventData.cs b/LibMatrix/StateEventTypes/UnknownStateEventData.cs deleted file mode 100644 index 59d8fd4..0000000 --- a/LibMatrix/StateEventTypes/UnknownStateEventData.cs +++ /dev/null @@ -1,7 +0,0 @@ -using LibMatrix.Interfaces; - -namespace LibMatrix.StateEventTypes; - -public class UnknownEventContent : EventContent { - -} -- cgit 1.4.1