
Instead of backfilling every note we come across that has a reply collection, only schedule a backfill job if someone wants to see the replies (on GET MastoAPI /context, or Iceshrimp API /descendants) Reply backfilling is also done on a ThreadIdOrId basis as opposed to the previous way of backfilling individual notes. This allows us finer grained control over the recursion and frees up the job queue, alongside allowing for easier implementation of context collection backfill in the future (by mapping each context collection to a thread) --- Currently, note threads are implicit based on the "threadId" column of a note, which can be null (where it's the same as the note's "id") This commit turns note threads into an actual entity, and as a part of that, makes "threadId" non-nullable (by specifically setting it to "id" for those cases) This is done to attach extra metadata to the entire thread, currently just the time of when it was last backfilled, but more may be added in the future (the context collection associated with this thread, for example) --- The data format for backfill jobs have backwards-incompatibly changed since the introduction of the feature. We can drop all old jobs without causing too much trouble as they will be re-scheduled on demand --- Signed-off-by: Laura Hausmann <laura@hausmann.dev>
66 lines
No EOL
2.5 KiB
C#
66 lines
No EOL
2.5 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Net;
|
|
using System.Net.Mime;
|
|
using Iceshrimp.Backend.Controllers.Shared.Attributes;
|
|
using Iceshrimp.Backend.Controllers.Shared.Schemas;
|
|
using Iceshrimp.Backend.Controllers.Web.Renderers;
|
|
using Iceshrimp.Backend.Core.Database;
|
|
using Iceshrimp.Backend.Core.Extensions;
|
|
using Iceshrimp.Backend.Core.Middleware;
|
|
using Iceshrimp.Backend.Core.Services;
|
|
using Iceshrimp.Shared.Schemas.Web;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.RateLimiting;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Iceshrimp.Backend.Controllers.Web;
|
|
|
|
[ApiController]
|
|
[Authenticate]
|
|
[Authorize]
|
|
[EnableRateLimiting("sliding")]
|
|
[Route("/api/iceshrimp/misc")]
|
|
[Produces(MediaTypeNames.Application.Json)]
|
|
public class MiscController(DatabaseContext db, NoteRenderer noteRenderer, BiteService biteSvc) : ControllerBase
|
|
{
|
|
[HttpPost("bite_back/{id}")]
|
|
[Authenticate]
|
|
[Authorize]
|
|
[ProducesResults(HttpStatusCode.OK)]
|
|
[ProducesErrors(HttpStatusCode.BadRequest, HttpStatusCode.NotFound)]
|
|
[SuppressMessage("ReSharper", "EntityFramework.NPlusOne.IncompleteDataUsage",
|
|
Justification = "IncludeCommonProperties")]
|
|
[SuppressMessage("ReSharper", "EntityFramework.NPlusOne.IncompleteDataQuery",
|
|
Justification = "IncludeCommonProperties")]
|
|
public async Task BiteBack(string id)
|
|
{
|
|
var user = HttpContext.GetUserOrFail();
|
|
var target = await db.Bites
|
|
.IncludeCommonProperties()
|
|
.Where(p => p.Id == id)
|
|
.FirstOrDefaultAsync() ??
|
|
throw GracefulException.NotFound("Bite not found");
|
|
|
|
if (user.Id != (target.TargetUserId ?? target.TargetNote?.UserId ?? target.TargetBite?.UserId))
|
|
throw GracefulException.BadRequest("You can only bite back at a user who bit you");
|
|
|
|
await biteSvc.BiteAsync(user, target);
|
|
}
|
|
|
|
[HttpGet("muted_threads")]
|
|
[LinkPagination(20, 40)]
|
|
[ProducesResults(HttpStatusCode.OK)]
|
|
public async Task<IEnumerable<NoteResponse>> GetMutedThreads(PaginationQuery pq)
|
|
{
|
|
var user = HttpContext.GetUserOrFail();
|
|
var notes = await db.Notes.IncludeCommonProperties()
|
|
.Where(p => db.NoteThreadMutings.Any(m => m.ThreadId == p.ThreadId))
|
|
.EnsureVisibleFor(user)
|
|
.FilterHidden(user, db, false, false)
|
|
.Paginate(pq, ControllerContext)
|
|
.PrecomputeVisibilities(user)
|
|
.ToListAsync();
|
|
|
|
return await noteRenderer.RenderMany(notes.EnforceRenoteReplyVisibility(), user);
|
|
}
|
|
} |