♻️ Refactored publishers

This commit is contained in:
2025-06-14 16:19:45 +08:00
parent 2821beb1b7
commit 1f2e9b1de8
8 changed files with 213 additions and 44 deletions

View File

@ -1,11 +1,12 @@
using DysonNetwork.Sphere.Account;
using DysonNetwork.Sphere.Post;
using DysonNetwork.Sphere.Publisher;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Sphere.Activity;
public class ActivityService(AppDatabase db, RelationshipService rels, PostService ps)
public class ActivityService(AppDatabase db, PublisherService pub, RelationshipService rels, PostService ps)
{
public async Task<List<Activity>> GetActivitiesForAnyone(int take, Instant? cursor)
{
@ -20,7 +21,7 @@ public class ActivityService(AppDatabase db, RelationshipService rels, PostServi
.Where(e => e.RepliedPostId == null)
.Where(p => cursor == null || p.PublishedAt < cursor)
.OrderByDescending(p => p.PublishedAt)
.FilterWithVisibility(null, [], isListing: true)
.FilterWithVisibility(null, [], [], isListing: true)
.Take(take)
.ToListAsync();
posts = PostService.TruncatePostContent(posts);
@ -46,17 +47,20 @@ public class ActivityService(AppDatabase db, RelationshipService rels, PostServi
{
var activities = new List<Activity>();
var userFriends = await rels.ListAccountFriends(currentUser);
var userPublishers = await pub.GetUserPublishers(currentUser.Id);
var publishersId = userPublishers.Select(e => e.Id).ToList();
// Crunching data
var posts = await db.Posts
.Include(e => e.RepliedPost)
.Include(e => e.ForwardedPost)
.Include(e => e.Categories)
.Include(e => e.Tags)
.Where(e => e.RepliedPostId == null)
.Where(e => e.RepliedPostId == null || publishersId.Contains(e.RepliedPost!.PublisherId))
.Where(p => cursor == null || p.PublishedAt < cursor)
.OrderByDescending(p => p.PublishedAt)
.FilterWithVisibility(currentUser, userFriends, isListing: true)
.FilterWithVisibility(currentUser, userFriends, userPublishers, isListing: true)
.Take(take)
.ToListAsync();
posts = PostService.TruncatePostContent(posts);