using Iceshrimp.Backend.Controllers.Mastodon.Renderers; using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities; using Iceshrimp.Backend.Core.Database.Tables; using Microsoft.EntityFrameworkCore; namespace Iceshrimp.Backend.Core.Extensions; public static class NoteQueryableExtensions { public static IQueryable WithIncludes(this IQueryable query) { return query.Include(p => p.User) .Include(p => p.Renote) .ThenInclude(p => p != null ? p.User : null) .Include(p => p.Reply) .ThenInclude(p => p != null ? p.User : null); } public static IQueryable HasVisibility(this IQueryable query, Note.NoteVisibility visibility) { return query.Where(note => note.Visibility == visibility); } public static IQueryable FilterByFollowingAndOwn(this IQueryable query, User user) { return query.Where(note => note.User == user || note.User.IsFollowedBy(user)); } public static IQueryable OrderByIdDesc(this IQueryable query) { return query.OrderByDescending(note => note.Id); } public static async Task> RenderAllForMastodonAsync( this IQueryable notes, NoteRenderer renderer) { var list = await notes.ToListAsync(); return await list.Select(renderer.RenderAsync).AwaitAllAsync(); } }