[backend/api] Add muted_threads endpoint (ISH-418)

This commit is contained in:
Laura Hausmann 2024-07-14 19:10:19 +02:00
parent 3cb19f376b
commit afd977d9ce
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,40 @@
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.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) : ControllerBase
{
[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 ?? p.Id)))
.EnsureVisibleFor(user)
.FilterHidden(user, db, false, false)
.Paginate(pq, ControllerContext)
.PrecomputeVisibilities(user)
.ToListAsync();
return await noteRenderer.RenderMany(notes.EnforceRenoteReplyVisibility(), user);
}
}

View file

@ -0,0 +1,11 @@
using Iceshrimp.Frontend.Core.Miscellaneous;
using Iceshrimp.Frontend.Core.Services;
using Iceshrimp.Shared.Schemas.Web;
namespace Iceshrimp.Frontend.Core.ControllerModels;
internal class MiscControllerModel(ApiClient api)
{
public Task<IEnumerable<NoteResponse>> GetMutedThreads(PaginationQuery pq) =>
api.Call<IEnumerable<NoteResponse>>(HttpMethod.Get, "/misc/muted_threads", pq);
}

View file

@ -15,6 +15,7 @@ internal class ApiService(ApiClient client)
public readonly TimelineControllerModel Timelines = new(client);
public readonly UserControllerModel Users = new(client);
public readonly FollowRequestControllerModel FollowRequests = new(client);
public readonly MiscControllerModel Misc = new(client);
public void SetBearerToken(string token) => client.SetToken(token);
}