[backend/masto-client] Paginate likes & bookmarks based on their identifier (instead of the note identifier)
This commit is contained in:
parent
9f3bbe6c08
commit
8b36f1aecf
3 changed files with 49 additions and 14 deletions
|
@ -504,13 +504,18 @@ public class AccountController(
|
|||
public async Task<IActionResult> GetLikedNotes(MastodonPaginationQuery query)
|
||||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
var res = await db.Notes
|
||||
.Where(p => db.Users.First(u => u == user).HasLiked(p))
|
||||
.IncludeCommonProperties()
|
||||
.Paginate(query, ControllerContext)
|
||||
.PrecomputeVisibilities(user)
|
||||
.RenderAllForMastodonAsync(noteRenderer, user);
|
||||
var likes = await db.NoteLikes
|
||||
.Where(p => p.User == user)
|
||||
.IncludeCommonProperties()
|
||||
.Select(p => new EntityWrapper<Note>
|
||||
{
|
||||
Id = p.Id, Entity = p.Note.WithPrecomputedVisibilities(user)
|
||||
})
|
||||
.Paginate(query, ControllerContext)
|
||||
.ToListAsync();
|
||||
|
||||
HttpContext.SetPaginationData(likes);
|
||||
var res = await noteRenderer.RenderManyAsync(likes.Select(p => p.Entity).EnforceRenoteReplyVisibility(), user);
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
|
@ -522,13 +527,19 @@ public class AccountController(
|
|||
public async Task<IActionResult> GetBookmarkedNotes(MastodonPaginationQuery query)
|
||||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
var res = await db.Notes
|
||||
.Where(p => db.Users.First(u => u == user).HasBookmarked(p))
|
||||
.IncludeCommonProperties()
|
||||
.Paginate(query, ControllerContext)
|
||||
.PrecomputeVisibilities(user)
|
||||
.RenderAllForMastodonAsync(noteRenderer, user);
|
||||
var bookmarks = await db.NoteBookmarks
|
||||
.Where(p => p.User == user)
|
||||
.IncludeCommonProperties()
|
||||
.Select(p => new EntityWrapper<Note>
|
||||
{
|
||||
Id = p.Id, Entity = p.Note.WithPrecomputedVisibilities(user)
|
||||
})
|
||||
.Paginate(query, ControllerContext)
|
||||
.ToListAsync();
|
||||
|
||||
HttpContext.SetPaginationData(bookmarks);
|
||||
var res =
|
||||
await noteRenderer.RenderManyAsync(bookmarks.Select(p => p.Entity).EnforceRenoteReplyVisibility(), user);
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,14 +61,14 @@ public class Note : IEntity
|
|||
[Column("renoteId")]
|
||||
[StringLength(32)]
|
||||
public string? RenoteId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The URI of the reply target, if it couldn't be resolved at time of ingestion.
|
||||
/// </summary>
|
||||
[Column("replyUri")]
|
||||
[StringLength(512)]
|
||||
public string? ReplyUri { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The URI of the renote target, if it couldn't be resolved at time of ingestion.
|
||||
/// </summary>
|
||||
|
@ -329,6 +329,14 @@ public class Note : IEntity
|
|||
return this;
|
||||
}
|
||||
|
||||
[Projectable]
|
||||
[SuppressMessage("ReSharper", "MergeIntoPattern", Justification = "Projectables")]
|
||||
[SuppressMessage("ReSharper", "MergeSequentialChecks", Justification = "Projectables")]
|
||||
public Note WithPrecomputedVisibilities(User user)
|
||||
=> WithPrecomputedVisibilities(Reply != null && Reply.IsVisibleFor(user),
|
||||
Renote != null && Renote.IsVisibleFor(user),
|
||||
Renote != null && Renote.Renote != null && Renote.Renote.IsVisibleFor(user));
|
||||
|
||||
public string GetPublicUri(Config.InstanceSection config) => UserHost == null
|
||||
? $"https://{config.WebDomain}/notes/{Id}"
|
||||
: throw new Exception("Cannot access PublicUri for remote note");
|
||||
|
|
|
@ -643,6 +643,22 @@ public static class QueryableExtensions
|
|||
.Include(p => p.Followee.UserProfile);
|
||||
}
|
||||
|
||||
public static IQueryable<NoteLike> IncludeCommonProperties(this IQueryable<NoteLike> query)
|
||||
{
|
||||
return query.Include(p => p.Note.User.UserProfile)
|
||||
.Include(p => p.Note.Renote.User.UserProfile)
|
||||
.Include(p => p.Note.Renote.Renote.User.UserProfile)
|
||||
.Include(p => p.Note.Reply.User.UserProfile);
|
||||
}
|
||||
|
||||
public static IQueryable<NoteBookmark> IncludeCommonProperties(this IQueryable<NoteBookmark> query)
|
||||
{
|
||||
return query.Include(p => p.Note.User.UserProfile)
|
||||
.Include(p => p.Note.Renote.User.UserProfile)
|
||||
.Include(p => p.Note.Renote.Renote.User.UserProfile)
|
||||
.Include(p => p.Note.Reply.User.UserProfile);
|
||||
}
|
||||
|
||||
public static IQueryable<Notification> IncludeCommonProperties(this IQueryable<Notification> query)
|
||||
{
|
||||
return query.Include(p => p.Notifiee.UserProfile)
|
||||
|
|
Loading…
Add table
Reference in a new issue