[backend/masto-client] Add tag timeline endpoint (ISH-115)
This commit is contained in:
parent
75cf552453
commit
810c21a275
3 changed files with 43 additions and 0 deletions
|
@ -10,4 +10,11 @@ public abstract class TimelineSchemas
|
|||
[FromQuery(Name = "remote")] public bool OnlyRemote { get; set; } = false;
|
||||
[FromQuery(Name = "only_media")] public bool OnlyMedia { get; set; } = false;
|
||||
}
|
||||
|
||||
public class HashtagTimelineRequest : PublicTimelineRequest
|
||||
{
|
||||
[FromQuery(Name = "any")] public List<string> Any { get; set; } = [];
|
||||
[FromQuery(Name = "all")] public List<string> All { get; set; } = [];
|
||||
[FromQuery(Name = "none")] public List<string> None { get; set; } = [];
|
||||
}
|
||||
}
|
|
@ -69,6 +69,28 @@ public class TimelineController(DatabaseContext db, NoteRenderer noteRenderer, I
|
|||
return Ok(res);
|
||||
}
|
||||
|
||||
[Authorize("read:statuses")]
|
||||
[HttpGet("tag/{hashtag}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<StatusEntity>))]
|
||||
public async Task<IActionResult> GetHashtagTimeline(
|
||||
string hashtag, MastodonPaginationQuery query, TimelineSchemas.HashtagTimelineRequest request
|
||||
)
|
||||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
|
||||
var res = await db.Notes
|
||||
.IncludeCommonProperties()
|
||||
.Where(p => p.Tags.Contains(hashtag.ToLowerInvariant()))
|
||||
.FilterByHashtagTimelineRequest(request)
|
||||
.FilterBlocked(user)
|
||||
.FilterMuted(user)
|
||||
.Paginate(query, ControllerContext)
|
||||
.PrecomputeVisibilities(user)
|
||||
.RenderAllForMastodonAsync(noteRenderer, user);
|
||||
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
[Authorize("read:lists")]
|
||||
[HttpGet("list/{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<StatusEntity>))]
|
||||
|
|
|
@ -408,6 +408,20 @@ public static class QueryableExtensions
|
|||
return query;
|
||||
}
|
||||
|
||||
public static IQueryable<Note> FilterByHashtagTimelineRequest(
|
||||
this IQueryable<Note> query, TimelineSchemas.HashtagTimelineRequest request
|
||||
)
|
||||
{
|
||||
if (request.Any.Count > 0)
|
||||
query = query.Where(p => request.Any.Any(t => p.Tags.Contains(t)));
|
||||
if (request.All.Count > 0)
|
||||
query = query.Where(p => request.All.All(t => p.Tags.Contains(t)));
|
||||
if (request.None.Count > 0)
|
||||
query = query.Where(p => request.None.All(t => !p.Tags.Contains(t)));
|
||||
|
||||
return query.FilterByPublicTimelineRequest(request);
|
||||
}
|
||||
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
// Justification: in the context of nullable EF navigation properties, null values are ignored and therefore irrelevant.
|
||||
// Source: https://learn.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types#navigating-and-including-nullable-relationships
|
||||
|
|
Loading…
Add table
Reference in a new issue