[backend/api] Add muted_threads endpoint (ISH-418)
This commit is contained in:
parent
3cb19f376b
commit
afd977d9ce
3 changed files with 52 additions and 0 deletions
40
Iceshrimp.Backend/Controllers/Web/MiscController.cs
Normal file
40
Iceshrimp.Backend/Controllers/Web/MiscController.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ internal class ApiService(ApiClient client)
|
||||||
public readonly TimelineControllerModel Timelines = new(client);
|
public readonly TimelineControllerModel Timelines = new(client);
|
||||||
public readonly UserControllerModel Users = new(client);
|
public readonly UserControllerModel Users = new(client);
|
||||||
public readonly FollowRequestControllerModel FollowRequests = new(client);
|
public readonly FollowRequestControllerModel FollowRequests = new(client);
|
||||||
|
public readonly MiscControllerModel Misc = new(client);
|
||||||
|
|
||||||
public void SetBearerToken(string token) => client.SetToken(token);
|
public void SetBearerToken(string token) => client.SetToken(token);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue