From 42b46243a44ff728fc1aa532c2ef76885feadacd Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 1 Jan 2026 00:10:00 +0800 Subject: [PATCH] :sparkles: Query params in the timeline controller to control fediverse content --- .../Timeline/TimelineController.cs | 7 ++++--- .../Timeline/TimelineService.cs | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/DysonNetwork.Sphere/Timeline/TimelineController.cs b/DysonNetwork.Sphere/Timeline/TimelineController.cs index 9d50805..d150a2f 100644 --- a/DysonNetwork.Sphere/Timeline/TimelineController.cs +++ b/DysonNetwork.Sphere/Timeline/TimelineController.cs @@ -25,7 +25,8 @@ public class ActivityController(TimelineService acts) : ControllerBase public async Task>> ListEvents( [FromQuery] string? cursor, [FromQuery] string? filter, - [FromQuery] int take = 20 + [FromQuery] int take = 20, + [FromQuery] bool showFediverse = false ) { Instant? cursorTimestamp = null; @@ -43,7 +44,7 @@ public class ActivityController(TimelineService acts) : ControllerBase HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue); return currentUserValue is not Account currentUser - ? Ok(await acts.ListEventsForAnyone(take, cursorTimestamp)) - : Ok(await acts.ListEvents(take, cursorTimestamp, currentUser, filter)); + ? Ok(await acts.ListEventsForAnyone(take, cursorTimestamp, showFediverse)) + : Ok(await acts.ListEvents(take, cursorTimestamp, currentUser, filter, showFediverse)); } } diff --git a/DysonNetwork.Sphere/Timeline/TimelineService.cs b/DysonNetwork.Sphere/Timeline/TimelineService.cs index 37c9cab..e72f0f2 100644 --- a/DysonNetwork.Sphere/Timeline/TimelineService.cs +++ b/DysonNetwork.Sphere/Timeline/TimelineService.cs @@ -32,7 +32,7 @@ public class TimelineService( return performanceWeight / Math.Pow(normalizedTime + 1.0, 1.2); } - public async Task> ListEventsForAnyone(int take, Instant? cursor) + public async Task> ListEventsForAnyone(int take, Instant? cursor, bool showFediverse = false) { var activities = new List(); @@ -43,6 +43,8 @@ public class TimelineService( var postsQuery = BuildPostsQuery(cursor, null, publicRealmIds) .FilterWithVisibility(null, [], [], isListing: true) .Take(take * 5); + if (!showFediverse) + postsQuery = postsQuery.Where(p => p.FediverseUri == null); var posts = await GetAndProcessPosts(postsQuery); await LoadPostsRealmsAsync(posts, rs); @@ -55,7 +57,7 @@ public class TimelineService( // Randomly insert a discovery activity before some posts if (random.NextDouble() < 0.15) { - var discovery = await MaybeGetDiscoveryActivity(cursor: cursor); + var discovery = await MaybeGetDiscoveryActivity(); if (discovery != null) interleaved.Add(discovery); } @@ -75,7 +77,8 @@ public class TimelineService( int take, Instant? cursor, Account currentUser, - string? filter = null + string? filter = null, + bool showFediverse = false ) { var activities = new List(); @@ -95,6 +98,8 @@ public class TimelineService( // Build and execute the post query var postsQuery = BuildPostsQuery(cursor, filteredPublishersId, userRealms); + if (!showFediverse) + postsQuery = postsQuery.Where(p => p.FediverseUri == null); // Apply visibility filtering and execute postsQuery = postsQuery @@ -119,7 +124,7 @@ public class TimelineService( { if (random.NextDouble() < 0.15) { - var discovery = await MaybeGetDiscoveryActivity(cursor: cursor); + var discovery = await MaybeGetDiscoveryActivity(); if (discovery != null) interleaved.Add(discovery); } @@ -135,7 +140,7 @@ public class TimelineService( return activities; } - private async Task MaybeGetDiscoveryActivity(Instant? cursor) + private async Task MaybeGetDiscoveryActivity() { var options = new List>>(); if (Random.Shared.NextDouble() < 0.5) @@ -165,7 +170,7 @@ public class TimelineService( // return posts.Take(take).ToList(); } - private async Task> GetPopularPublishers(int take) + private async Task> GetPopularPublishers(int take) { var now = SystemClock.Instance.GetCurrentInstant(); var recent = now.Minus(Duration.FromDays(7)); @@ -331,7 +336,7 @@ public class TimelineService( return query; } - private async Task?> GetFilteredPublishers( + private async Task?> GetFilteredPublishers( string? filter, Account currentUser, List userFriends