From 765c6e6f93064c87269534e397c1fe5324ed76d2 Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Sat, 21 Oct 2023 14:01:25 +0900 Subject: [PATCH] Add RecordWithMediaViewEmbed.cs --- src/FishyFlip/Constants.cs | 1 + .../Models/RecordWithMediaViewEmbed.cs | 25 +++++++++++++++++++ src/FishyFlip/Tools/Json/EmbedConverter.cs | 24 ++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/FishyFlip/Models/RecordWithMediaViewEmbed.cs diff --git a/src/FishyFlip/Constants.cs b/src/FishyFlip/Constants.cs index 1989f9ff..9d74534e 100644 --- a/src/FishyFlip/Constants.cs +++ b/src/FishyFlip/Constants.cs @@ -175,6 +175,7 @@ public static class EmbedTypes public const string RecordView = "app.bsky.embed.record#view"; public const string Record = "app.bsky.embed.record"; public const string RecordWithMedia = "app.bsky.embed.recordWithMedia"; + public const string RecordWithMediaView = "app.bsky.embed.recordWithMedia#view"; } public static class FeedType diff --git a/src/FishyFlip/Models/RecordWithMediaViewEmbed.cs b/src/FishyFlip/Models/RecordWithMediaViewEmbed.cs new file mode 100644 index 00000000..bdf1041f --- /dev/null +++ b/src/FishyFlip/Models/RecordWithMediaViewEmbed.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishyFlip.Models; + +/// +/// Record with Media Embed. +/// +public class RecordWithMediaViewEmbed : Embed +{ + [JsonConstructor] + public RecordWithMediaViewEmbed(RecordViewEmbed? record, ImageViewEmbed? images) + { + this.Record = record; + this.Images = images; + this.Type = Constants.EmbedTypes.RecordWithMedia; + } + + public RecordViewEmbed? Record { get; } + + public ImageViewEmbed? Images { get; } +} \ No newline at end of file diff --git a/src/FishyFlip/Tools/Json/EmbedConverter.cs b/src/FishyFlip/Tools/Json/EmbedConverter.cs index 5094357b..594d4aee 100644 --- a/src/FishyFlip/Tools/Json/EmbedConverter.cs +++ b/src/FishyFlip/Tools/Json/EmbedConverter.cs @@ -64,6 +64,30 @@ public class EmbedConverter : JsonConverter } break; + case Constants.EmbedTypes.RecordWithMediaView: + RecordViewEmbed? record1 = null; + ImageViewEmbed? media1 = null; + + if (doc.RootElement.TryGetProperty("record", out var recordVal2)) + { + record1 = JsonSerializer.Deserialize(recordVal2.GetRawText(), options); + } + + if (doc.RootElement.TryGetProperty("media", out var mediaVal2)) + { + if (mediaVal2.TryGetProperty("$type", out var mediaType2)) + { + var mediaText = mediaType2.GetString()?.Trim() ?? string.Empty; + switch (mediaText) + { + case Constants.EmbedTypes.ImageView: + media1 = JsonSerializer.Deserialize(mediaVal2.GetRawText(), options); + break; + } + } + } + + return new RecordWithMediaViewEmbed(record1, media1); case Constants.EmbedTypes.RecordWithMedia: RecordEmbed? record = null; ImagesEmbed? media = null;