[backend/masto-client] Return hashtags on search (ISH-14)
This commit is contained in:
parent
995cee1d18
commit
a611495d84
4 changed files with 41 additions and 5 deletions
|
@ -0,0 +1,11 @@
|
||||||
|
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
|
||||||
|
|
||||||
|
namespace Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
|
||||||
|
|
||||||
|
public class TagEntity
|
||||||
|
{
|
||||||
|
[J("name")] public required string Name { get; set; }
|
||||||
|
[J("url")] public required string Url { get; set; }
|
||||||
|
[J("following")] public required bool Following { get; set; }
|
||||||
|
[J("history")] public object? History => null;
|
||||||
|
}
|
|
@ -22,6 +22,6 @@ public abstract class SearchSchemas
|
||||||
{
|
{
|
||||||
[J("accounts")] public required List<AccountEntity> Accounts { get; set; }
|
[J("accounts")] public required List<AccountEntity> Accounts { get; set; }
|
||||||
[J("statuses")] public required List<StatusEntity> Statuses { get; set; }
|
[J("statuses")] public required List<StatusEntity> Statuses { get; set; }
|
||||||
[J("hashtags")] public List<object> Hashtags => []; //TODO: implement this
|
[J("hashtags")] public required List<TagEntity> Hashtags { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,14 +6,17 @@ using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
|
||||||
using Iceshrimp.Backend.Controllers.Mastodon.Renderers;
|
using Iceshrimp.Backend.Controllers.Mastodon.Renderers;
|
||||||
using Iceshrimp.Backend.Controllers.Mastodon.Schemas;
|
using Iceshrimp.Backend.Controllers.Mastodon.Schemas;
|
||||||
using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
|
using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
|
||||||
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Database;
|
using Iceshrimp.Backend.Core.Database;
|
||||||
using Iceshrimp.Backend.Core.Extensions;
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
|
using Iceshrimp.Backend.Core.Helpers;
|
||||||
using Iceshrimp.Backend.Core.Middleware;
|
using Iceshrimp.Backend.Core.Middleware;
|
||||||
using Iceshrimp.Backend.Core.Services;
|
using Iceshrimp.Backend.Core.Services;
|
||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.RateLimiting;
|
using Microsoft.AspNetCore.RateLimiting;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Controllers.Mastodon;
|
namespace Iceshrimp.Backend.Controllers.Mastodon;
|
||||||
|
|
||||||
|
@ -27,7 +30,8 @@ public class SearchController(
|
||||||
NoteRenderer noteRenderer,
|
NoteRenderer noteRenderer,
|
||||||
UserRenderer userRenderer,
|
UserRenderer userRenderer,
|
||||||
NoteService noteSvc,
|
NoteService noteSvc,
|
||||||
ActivityPub.UserResolver userResolver
|
ActivityPub.UserResolver userResolver,
|
||||||
|
IOptions<Config.InstanceSection> config
|
||||||
) : ControllerBase
|
) : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet("/api/v2/search")]
|
[HttpGet("/api/v2/search")]
|
||||||
|
@ -43,8 +47,8 @@ public class SearchController(
|
||||||
var result = new SearchSchemas.SearchResponse
|
var result = new SearchSchemas.SearchResponse
|
||||||
{
|
{
|
||||||
Accounts = search.Type is null or "accounts" ? await SearchUsersAsync(search, pagination) : [],
|
Accounts = search.Type is null or "accounts" ? await SearchUsersAsync(search, pagination) : [],
|
||||||
Statuses = search.Type is null or "statuses" ? await SearchNotesAsync(search, pagination) : []
|
Statuses = search.Type is null or "statuses" ? await SearchNotesAsync(search, pagination) : [],
|
||||||
//TODO: implement hashtags
|
Hashtags = search.Type is null or "hashtags" ? await SearchTagsAsync(search, pagination) : []
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
|
@ -188,4 +192,25 @@ public class SearchController(
|
||||||
.PrecomputeVisibilities(user)
|
.PrecomputeVisibilities(user)
|
||||||
.RenderAllForMastodonAsync(noteRenderer, user);
|
.RenderAllForMastodonAsync(noteRenderer, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "EntityFramework.UnsupportedServerSideFunctionCall",
|
||||||
|
Justification = "Inspection doesn't know about the Projectable attribute")]
|
||||||
|
private async Task<List<TagEntity>> SearchTagsAsync(
|
||||||
|
SearchSchemas.SearchRequest search,
|
||||||
|
MastodonPaginationQuery pagination
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return await db.Hashtags
|
||||||
|
.Where(p => EF.Functions.ILike(p.Name, "%" + EfHelpers.EscapeLikeQuery(search.Query!) + "%"))
|
||||||
|
.Paginate(pagination, ControllerContext)
|
||||||
|
.OrderByDescending(p => p.Id)
|
||||||
|
.Skip(pagination.Offset ?? 0)
|
||||||
|
.Select(p => new TagEntity
|
||||||
|
{
|
||||||
|
Name = p.Name,
|
||||||
|
Url = $"https://{config.Value.WebDomain}/tags/{p.Name}",
|
||||||
|
Following = false, //TODO
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ namespace Iceshrimp.Backend.Core.Database.Tables;
|
||||||
[Index("Name", IsUnique = true)]
|
[Index("Name", IsUnique = true)]
|
||||||
[Index("MentionedRemoteUsersCount")]
|
[Index("MentionedRemoteUsersCount")]
|
||||||
[Index("AttachedUsersCount")]
|
[Index("AttachedUsersCount")]
|
||||||
public class Hashtag
|
public class Hashtag : IEntity
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
|
|
Loading…
Add table
Reference in a new issue