From d385abbf575bb870a84a01a7b589980f64c88b62 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 21 Jun 2025 14:17:55 +0800 Subject: [PATCH] :bug: Trying to fix post link auto preview --- DysonNetwork.Sphere/Post/PostService.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/DysonNetwork.Sphere/Post/PostService.cs b/DysonNetwork.Sphere/Post/PostService.cs index f7c11b4..bee4964 100644 --- a/DysonNetwork.Sphere/Post/PostService.cs +++ b/DysonNetwork.Sphere/Post/PostService.cs @@ -282,7 +282,7 @@ public partial class PostService( // Initialize meta dictionary if null item.Meta ??= new Dictionary(); - // Initialize embeds array if it doesn't exist + // Initialize the embeds' array if it doesn't exist if (!item.Meta.TryGetValue("embeds", out var existingEmbeds) || existingEmbeds is not List) { item.Meta["embeds"] = new List(); @@ -292,7 +292,7 @@ public partial class PostService( // Process up to 3 links to avoid excessive processing var processedLinks = 0; - foreach (System.Text.RegularExpressions.Match match in matches) + foreach (Match match in matches) { if (processedLinks >= 3) break; @@ -301,7 +301,7 @@ public partial class PostService( try { - // Check if this URL is already in the embeds list + // Check if this URL is already in the embed list var urlAlreadyEmbedded = embeds.OfType().Any(e => e.Url == url); if (urlAlreadyEmbedded) continue; @@ -317,6 +317,8 @@ public partial class PostService( } } + item.Meta["embeds"] = embeds; + return item; } @@ -339,8 +341,7 @@ public partial class PostService( // If embeds were added, update the post in the database if (updatedPost.Meta != null && updatedPost.Meta.TryGetValue("embeds", out var embeds) && - embeds is List embedsList && - embedsList.Count > 0) + embeds is List { Count: > 0 } embedsList) { // Get a fresh copy of the post from the database var dbPost = await dbContext.Posts.FindAsync(post.Id);