✨ Query params in the timeline controller to control fediverse content
This commit is contained in:
@@ -25,7 +25,8 @@ public class ActivityController(TimelineService acts) : ControllerBase
|
|||||||
public async Task<ActionResult<List<SnTimelineEvent>>> ListEvents(
|
public async Task<ActionResult<List<SnTimelineEvent>>> ListEvents(
|
||||||
[FromQuery] string? cursor,
|
[FromQuery] string? cursor,
|
||||||
[FromQuery] string? filter,
|
[FromQuery] string? filter,
|
||||||
[FromQuery] int take = 20
|
[FromQuery] int take = 20,
|
||||||
|
[FromQuery] bool showFediverse = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Instant? cursorTimestamp = null;
|
Instant? cursorTimestamp = null;
|
||||||
@@ -43,7 +44,7 @@ public class ActivityController(TimelineService acts) : ControllerBase
|
|||||||
|
|
||||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||||
return currentUserValue is not Account currentUser
|
return currentUserValue is not Account currentUser
|
||||||
? Ok(await acts.ListEventsForAnyone(take, cursorTimestamp))
|
? Ok(await acts.ListEventsForAnyone(take, cursorTimestamp, showFediverse))
|
||||||
: Ok(await acts.ListEvents(take, cursorTimestamp, currentUser, filter));
|
: Ok(await acts.ListEvents(take, cursorTimestamp, currentUser, filter, showFediverse));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class TimelineService(
|
|||||||
return performanceWeight / Math.Pow(normalizedTime + 1.0, 1.2);
|
return performanceWeight / Math.Pow(normalizedTime + 1.0, 1.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<SnTimelineEvent>> ListEventsForAnyone(int take, Instant? cursor)
|
public async Task<List<SnTimelineEvent>> ListEventsForAnyone(int take, Instant? cursor, bool showFediverse = false)
|
||||||
{
|
{
|
||||||
var activities = new List<SnTimelineEvent>();
|
var activities = new List<SnTimelineEvent>();
|
||||||
|
|
||||||
@@ -43,6 +43,8 @@ public class TimelineService(
|
|||||||
var postsQuery = BuildPostsQuery(cursor, null, publicRealmIds)
|
var postsQuery = BuildPostsQuery(cursor, null, publicRealmIds)
|
||||||
.FilterWithVisibility(null, [], [], isListing: true)
|
.FilterWithVisibility(null, [], [], isListing: true)
|
||||||
.Take(take * 5);
|
.Take(take * 5);
|
||||||
|
if (!showFediverse)
|
||||||
|
postsQuery = postsQuery.Where(p => p.FediverseUri == null);
|
||||||
|
|
||||||
var posts = await GetAndProcessPosts(postsQuery);
|
var posts = await GetAndProcessPosts(postsQuery);
|
||||||
await LoadPostsRealmsAsync(posts, rs);
|
await LoadPostsRealmsAsync(posts, rs);
|
||||||
@@ -55,7 +57,7 @@ public class TimelineService(
|
|||||||
// Randomly insert a discovery activity before some posts
|
// Randomly insert a discovery activity before some posts
|
||||||
if (random.NextDouble() < 0.15)
|
if (random.NextDouble() < 0.15)
|
||||||
{
|
{
|
||||||
var discovery = await MaybeGetDiscoveryActivity(cursor: cursor);
|
var discovery = await MaybeGetDiscoveryActivity();
|
||||||
if (discovery != null)
|
if (discovery != null)
|
||||||
interleaved.Add(discovery);
|
interleaved.Add(discovery);
|
||||||
}
|
}
|
||||||
@@ -75,7 +77,8 @@ public class TimelineService(
|
|||||||
int take,
|
int take,
|
||||||
Instant? cursor,
|
Instant? cursor,
|
||||||
Account currentUser,
|
Account currentUser,
|
||||||
string? filter = null
|
string? filter = null,
|
||||||
|
bool showFediverse = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var activities = new List<SnTimelineEvent>();
|
var activities = new List<SnTimelineEvent>();
|
||||||
@@ -95,6 +98,8 @@ public class TimelineService(
|
|||||||
|
|
||||||
// Build and execute the post query
|
// Build and execute the post query
|
||||||
var postsQuery = BuildPostsQuery(cursor, filteredPublishersId, userRealms);
|
var postsQuery = BuildPostsQuery(cursor, filteredPublishersId, userRealms);
|
||||||
|
if (!showFediverse)
|
||||||
|
postsQuery = postsQuery.Where(p => p.FediverseUri == null);
|
||||||
|
|
||||||
// Apply visibility filtering and execute
|
// Apply visibility filtering and execute
|
||||||
postsQuery = postsQuery
|
postsQuery = postsQuery
|
||||||
@@ -119,7 +124,7 @@ public class TimelineService(
|
|||||||
{
|
{
|
||||||
if (random.NextDouble() < 0.15)
|
if (random.NextDouble() < 0.15)
|
||||||
{
|
{
|
||||||
var discovery = await MaybeGetDiscoveryActivity(cursor: cursor);
|
var discovery = await MaybeGetDiscoveryActivity();
|
||||||
if (discovery != null)
|
if (discovery != null)
|
||||||
interleaved.Add(discovery);
|
interleaved.Add(discovery);
|
||||||
}
|
}
|
||||||
@@ -135,7 +140,7 @@ public class TimelineService(
|
|||||||
return activities;
|
return activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<SnTimelineEvent?> MaybeGetDiscoveryActivity(Instant? cursor)
|
private async Task<SnTimelineEvent?> MaybeGetDiscoveryActivity()
|
||||||
{
|
{
|
||||||
var options = new List<Func<Task<SnTimelineEvent?>>>();
|
var options = new List<Func<Task<SnTimelineEvent?>>>();
|
||||||
if (Random.Shared.NextDouble() < 0.5)
|
if (Random.Shared.NextDouble() < 0.5)
|
||||||
@@ -165,7 +170,7 @@ public class TimelineService(
|
|||||||
// return posts.Take(take).ToList();
|
// return posts.Take(take).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<Shared.Models.SnPublisher>> GetPopularPublishers(int take)
|
private async Task<List<SnPublisher>> GetPopularPublishers(int take)
|
||||||
{
|
{
|
||||||
var now = SystemClock.Instance.GetCurrentInstant();
|
var now = SystemClock.Instance.GetCurrentInstant();
|
||||||
var recent = now.Minus(Duration.FromDays(7));
|
var recent = now.Minus(Duration.FromDays(7));
|
||||||
@@ -331,7 +336,7 @@ public class TimelineService(
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<Shared.Models.SnPublisher>?> GetFilteredPublishers(
|
private async Task<List<SnPublisher>?> GetFilteredPublishers(
|
||||||
string? filter,
|
string? filter,
|
||||||
Account currentUser,
|
Account currentUser,
|
||||||
List<Guid> userFriends
|
List<Guid> userFriends
|
||||||
|
|||||||
Reference in New Issue
Block a user