[backend/federation] Fetch featured notes as following user, if one is available (ISH-262)

This is the same logic Mastodon uses to ensure follower-only pinned notes can be resolved.
This commit is contained in:
Laura Hausmann 2024-04-16 18:19:29 +02:00
parent 08ced32e4d
commit 933361b0c6
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -1228,12 +1228,12 @@ public class NoteService(
collection = await objectResolver.ResolveObject(collection, force: true) as ASOrderedCollection; collection = await objectResolver.ResolveObject(collection, force: true) as ASOrderedCollection;
if (collection is not { Items: not null }) return; if (collection is not { Items: not null }) return;
var items = await collection.Items.Take(10) // ReSharper disable once EntityFramework.UnsupportedServerSideFunctionCall
.Select(p => objectResolver.ResolveObject(p)) var followingUser = await db.Users.FirstOrDefaultAsync(p => p.IsFollowing(user));
var notes = await collection.Items.Take(10)
.Select(p => ResolveNoteAsync(p.Id, null, followingUser, true))
.AwaitAllNoConcurrencyAsync(); .AwaitAllNoConcurrencyAsync();
var notes = await items.OfType<ASNote>()
.Select(p => ResolveNoteAsync(p.Id, p, null, true))
.AwaitAllNoConcurrencyAsync();
var previousPins = await db.Users.Where(p => p.Id == user.Id) var previousPins = await db.Users.Where(p => p.Id == user.Id)
.Select(p => p.PinnedNotes.Select(i => i.Id)) .Select(p => p.PinnedNotes.Select(i => i.Id))
.FirstOrDefaultAsync() ?? []; .FirstOrDefaultAsync() ?? [];