From 91319ba62de889bde645b6f1df4dd6a960ee7de4 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 21 Sep 2025 15:49:54 +0200 Subject: Dependency updates, some fixes, partial msc2545 support --- .../Msc2545EmoteRoomsAccountDataEventContent.cs | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 LibMatrix.EventTypes/Common/Msc2545EmoteRoomsAccountDataEventContent.cs (limited to 'LibMatrix.EventTypes') diff --git a/LibMatrix.EventTypes/Common/Msc2545EmoteRoomsAccountDataEventContent.cs b/LibMatrix.EventTypes/Common/Msc2545EmoteRoomsAccountDataEventContent.cs new file mode 100644 index 0000000..4fd5c29 --- /dev/null +++ b/LibMatrix.EventTypes/Common/Msc2545EmoteRoomsAccountDataEventContent.cs @@ -0,0 +1,31 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Spec; + +[MatrixEvent(EventName = EventId)] +public class Msc2545EmoteRoomsAccountDataEventContent : EventContent { + public const string EventId = "im.ponies.emote_rooms"; + + [JsonPropertyName("rooms")] + public Dictionary> Rooms { get; set; } = new(); + + // Dummy type to provide easy access to the by-spec empty content + public class EnabledEmotePackEntry { + [JsonExtensionData] + public Dictionary? AdditionalData { get; set; } = []; + + public T? GetAdditionalData(string key) where T : class { + if (AdditionalData == null || !AdditionalData.TryGetValue(key, out var value)) + return null; + + if (value is T tValue) + return tValue; + if (value is JsonElement jsonElement) + return jsonElement.Deserialize(); + + throw new InvalidCastException($"Value for key '{key}' ({value.GetType()}) cannot be cast to type '{typeof(T)}'. Cannot continue."); + } + } +} \ No newline at end of file -- cgit 1.5.1