From 6211f546b12514f075ec7679d4119f37ce00e5c9 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 15 Aug 2025 02:23:14 +0800 Subject: [PATCH] :sparkles: Post list shuffle mode --- DysonNetwork.Sphere/Post/PostController.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/DysonNetwork.Sphere/Post/PostController.cs b/DysonNetwork.Sphere/Post/PostController.cs index 6f1e3c1..a304ba5 100644 --- a/DysonNetwork.Sphere/Post/PostController.cs +++ b/DysonNetwork.Sphere/Post/PostController.cs @@ -46,7 +46,8 @@ public class PostController( [FromQuery(Name = "query")] string? queryTerm = null, [FromQuery(Name = "vector")] bool queryVector = false, [FromQuery(Name = "replies")] bool includeReplies = false, - [FromQuery(Name = "media")] bool onlyMedia = false + [FromQuery(Name = "media")] bool onlyMedia = false, + [FromQuery(Name = "shuffle")] bool shuffle = false ) { HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue); @@ -98,10 +99,15 @@ public class PostController( var totalCount = await query .CountAsync(); + + if (shuffle) + query = query.OrderBy(e => EF.Functions.Random()); + else + query = query.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt); + var posts = await query .Include(e => e.RepliedPost) .Include(e => e.ForwardedPost) - .OrderByDescending(e => e.PublishedAt ?? e.CreatedAt) .Skip(offset) .Take(take) .ToListAsync();