[backend/masto-client] Paginate note likes & renotes correctly (ISH-362)
This commit is contained in:
parent
946eed1b03
commit
364d0c54a0
1 changed files with 21 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using AsyncKeyedLock;
|
using AsyncKeyedLock;
|
||||||
|
using Iceshrimp.Backend.Controllers.Attributes;
|
||||||
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
|
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
|
||||||
using Iceshrimp.Backend.Controllers.Mastodon.Renderers;
|
using Iceshrimp.Backend.Controllers.Mastodon.Renderers;
|
||||||
using Iceshrimp.Backend.Controllers.Mastodon.Schemas;
|
using Iceshrimp.Backend.Controllers.Mastodon.Schemas;
|
||||||
|
@ -544,9 +545,10 @@ public class StatusController(
|
||||||
|
|
||||||
[HttpGet("{id}/favourited_by")]
|
[HttpGet("{id}/favourited_by")]
|
||||||
[Authenticate("read:statuses")]
|
[Authenticate("read:statuses")]
|
||||||
|
[LinkPagination(40, 80)]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<AccountEntity>))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<AccountEntity>))]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
|
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
|
||||||
public async Task<IActionResult> GetNoteLikes(string id)
|
public async Task<IActionResult> GetNoteLikes(string id, MastodonPaginationQuery pq)
|
||||||
{
|
{
|
||||||
var user = HttpContext.GetUser();
|
var user = HttpContext.GetUser();
|
||||||
if (security.Value.PublicPreview == Enums.PublicPreview.Lockdown && user == null)
|
if (security.Value.PublicPreview == Enums.PublicPreview.Lockdown && user == null)
|
||||||
|
@ -561,19 +563,23 @@ public class StatusController(
|
||||||
if (security.Value.PublicPreview <= Enums.PublicPreview.Restricted && note.UserHost != null && user == null)
|
if (security.Value.PublicPreview <= Enums.PublicPreview.Restricted && note.UserHost != null && user == null)
|
||||||
throw GracefulException.Forbidden("Public preview is disabled on this instance");
|
throw GracefulException.Forbidden("Public preview is disabled on this instance");
|
||||||
|
|
||||||
var res = await db.NoteLikes.Where(p => p.Note == note)
|
var likes = await db.NoteLikes.Where(p => p.Note == note)
|
||||||
.Include(p => p.User.UserProfile)
|
.Include(p => p.User.UserProfile)
|
||||||
.Select(p => p.User)
|
.Select(p => new EntityWrapper<User> { Id = p.Id, Entity = p.User })
|
||||||
.RenderAllForMastodonAsync(userRenderer);
|
.Paginate(pq, ControllerContext)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
HttpContext.SetPaginationData(likes);
|
||||||
|
var res = await userRenderer.RenderManyAsync(likes.Select(p => p.Entity));
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}/reblogged_by")]
|
[HttpGet("{id}/reblogged_by")]
|
||||||
[Authenticate("read:statuses")]
|
[Authenticate("read:statuses")]
|
||||||
|
[LinkPagination(40, 80)]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<AccountEntity>))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<AccountEntity>))]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
|
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
|
||||||
public async Task<IActionResult> GetNoteRenotes(string id)
|
public async Task<IActionResult> GetNoteRenotes(string id, MastodonPaginationQuery pq)
|
||||||
{
|
{
|
||||||
var user = HttpContext.GetUser();
|
var user = HttpContext.GetUser();
|
||||||
if (security.Value.PublicPreview == Enums.PublicPreview.Lockdown && user == null)
|
if (security.Value.PublicPreview == Enums.PublicPreview.Lockdown && user == null)
|
||||||
|
@ -589,13 +595,16 @@ public class StatusController(
|
||||||
if (security.Value.PublicPreview <= Enums.PublicPreview.Restricted && note.UserHost != null && user == null)
|
if (security.Value.PublicPreview <= Enums.PublicPreview.Restricted && note.UserHost != null && user == null)
|
||||||
throw GracefulException.Forbidden("Public preview is disabled on this instance");
|
throw GracefulException.Forbidden("Public preview is disabled on this instance");
|
||||||
|
|
||||||
var res = await db.Notes
|
var renotes = await db.Notes
|
||||||
.Where(p => p.Renote == note && p.IsPureRenote)
|
.Where(p => p.Renote == note && p.IsPureRenote)
|
||||||
.EnsureVisibleFor(user)
|
.EnsureVisibleFor(user)
|
||||||
.Include(p => p.User.UserProfile)
|
.Include(p => p.User.UserProfile)
|
||||||
.Select(p => p.User)
|
.Select(p => new EntityWrapper<User> { Id = p.Id, Entity = p.User })
|
||||||
.RenderAllForMastodonAsync(userRenderer);
|
.Paginate(pq, ControllerContext)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
HttpContext.SetPaginationData(renotes);
|
||||||
|
var res = await userRenderer.RenderManyAsync(renotes.Select(p => p.Entity));
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue