From 3afbeacffb9c3cb4d149d6d67a2f399e94e4a567 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 31 Jul 2025 16:33:28 +0800 Subject: [PATCH] :bug: Fix get featured reply --- DysonNetwork.Sphere/Post/PostController.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/DysonNetwork.Sphere/Post/PostController.cs b/DysonNetwork.Sphere/Post/PostController.cs index 4eb4c0e..f3a3d0d 100644 --- a/DysonNetwork.Sphere/Post/PostController.cs +++ b/DysonNetwork.Sphere/Post/PostController.cs @@ -95,7 +95,7 @@ public class PostController( post = await ps.LoadPostInfo(post, currentUser); // Track view - use the account ID as viewer ID if user is logged in - await ps.IncreaseViewCount(post.Id, currentUser?.Id.ToString()); + await ps.IncreaseViewCount(post.Id, currentUser?.Id); return Ok(post); } @@ -154,6 +154,18 @@ public class PostController( [HttpGet("{id:guid}/replies/featured")] public async Task> GetFeaturedReply(Guid id) { + HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue); + var currentUser = currentUserValue as Account; + List userFriends = []; + if (currentUser != null) + { + var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest + { AccountId = currentUser.Id }); + userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList(); + } + + var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(Guid.Parse(currentUser.Id)); + var now = SystemClock.Instance.GetCurrentInstant(); var post = await db.Posts .Where(e => e.RepliedPostId == id) @@ -162,8 +174,14 @@ public class PostController( p.Downvotes + ((p.CreatedAt - now).TotalMinutes < 60 ? 5 : 0) ) + .FilterWithVisibility(currentUser, userFriends, userPublishers) .FirstOrDefaultAsync(); if (post is null) return NotFound(); + post = await ps.LoadPostInfo(post, currentUser); + + // Track view - use the account ID as viewer ID if user is logged in + await ps.IncreaseViewCount(post.Id, currentUser?.Id); + return await ps.LoadPostInfo(post); }