All 384 routes, the Mastodon API, the client API and the frozen federation paths, are read from one class with one nested class per controller. Their values are unchanged, checked one by one against the old literals; decePubClient keeps its own APIs class. Checked against GoToSocial in the pasture: 64 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
1 parent
0f73f69239
commit
739a1603ca
47 files changed
+952
-373
No files matched your search
@@ -23,7 +23,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
MastodonMapper mastodonMapper,
|
||||
DbEntities db) : MastodonController
|
||||
{
|
||||
[HttpGet("/api/v1/timelines/home"), Scope("read:statuses")]
|
||||
[HttpGet(ApiPaths.Timelines.GET_Home), Scope("read:statuses")]
|
||||
public async Task<IActionResult> Home(CancellationToken token)
|
||||
{
|
||||
//an exclusive list's members are read in that list, not at home
|
||||
@@ -44,7 +44,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(statuses);
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/timelines/public"), Scope("read:statuses", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[HttpGet(ApiPaths.Timelines.GET_Public), Scope("read:statuses", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<IActionResult> Public(CancellationToken token)
|
||||
{
|
||||
var query = db.Posts.Match(p => p.Visibility == PostVisibility.Public && p.ReblogOfPostId == null).Match(VisibilityPolicy.IsPublic)
|
||||
@@ -60,7 +60,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
|
||||
// PrivaPub's own: a feed the persona reads (Lemmy's multi-community, PieFed's feed), its communities' threads,
|
||||
// newest first, as the server's reader of feeds brings them in (owner decision 2026-10-07)
|
||||
[HttpGet("/api/v1/timelines/feed/{id}"), Scope("read:statuses")]
|
||||
[HttpGet(ApiPaths.Timelines.GET_M_Feed), Scope("read:statuses")]
|
||||
public async Task<IActionResult> Feed(string id, CancellationToken token)
|
||||
{
|
||||
var feed = await db.ForeignAvatars.MatchID(id).ExecuteFirstAsync(token);
|
||||
@@ -78,7 +78,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return await Respond(query, $"/api/v1/timelines/feed/{id}", token);
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/timelines/tag/{hashtag}"), Scope("read:statuses", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[HttpGet(ApiPaths.Timelines.GET_M_Tag), Scope("read:statuses", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<IActionResult> Tag(string hashtag, CancellationToken token)
|
||||
{
|
||||
var tag = hashtag.TrimStart('#').ToLowerInvariant();
|
||||
@@ -89,7 +89,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return await Respond(query, $"/api/v1/timelines/tag/{hashtag}", token);
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/favourites"), Scope("read:favourites")]
|
||||
[HttpGet(ApiPaths.Timelines.GET_Favourites), Scope("read:favourites")]
|
||||
public async Task<IActionResult> Favourites(CancellationToken token)
|
||||
{
|
||||
var favourites = await Page.From(Params, Limit()).Fetch(db.Favourites.Match(f => f.AccountId == MyId), f => f.ID, token);
|
||||
@@ -106,7 +106,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
// the persona's direct conversations, by their newest post (paged like Mastodon's by that post's id), each with its
|
||||
// other members and whether its newest post, someone else's, is newer than what the persona read; the ones it took
|
||||
// off its list stay off until a newer message
|
||||
[HttpGet("/api/v1/conversations"), Scope("read:statuses")]
|
||||
[HttpGet(ApiPaths.Timelines.GET_Conversations), Scope("read:statuses")]
|
||||
public async Task<IActionResult> Conversations(CancellationToken token)
|
||||
{
|
||||
var groups = await Page.From(Params, Limit(20, 40)).Fetch(
|
||||
@@ -159,7 +159,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
await db.DmGroups.Match(g => g.ID == id && !g.DeletionAt.HasValue && g.Members.Any(m => !m.IsForeign && m.AvatarId == MyId))
|
||||
.ExecuteFirstAsync(token);
|
||||
|
||||
[HttpPost("/api/v1/conversations/{id}/read"), Scope("write:conversations")]
|
||||
[HttpPost(ApiPaths.Timelines.POST_M_ReadConversation), Scope("write:conversations")]
|
||||
public async Task<IActionResult> ReadConversation(string id, CancellationToken token)
|
||||
{
|
||||
var group = await MyConversation(id, token);
|
||||
@@ -171,7 +171,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
}
|
||||
|
||||
// Mastodon's unread (R9): shown unread again until it is read
|
||||
[HttpPost("/api/v1/conversations/{id}/unread"), Scope("write:conversations")]
|
||||
[HttpPost(ApiPaths.Timelines.POST_M_UnreadConversation), Scope("write:conversations")]
|
||||
public async Task<IActionResult> UnreadConversation(string id, CancellationToken token)
|
||||
{
|
||||
var group = await MyConversation(id, token);
|
||||
@@ -183,7 +183,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
}
|
||||
|
||||
// off the persona's list until a newer message; the messages themselves stay
|
||||
[HttpDelete("/api/v1/conversations/{id}"), Scope("write:conversations")]
|
||||
[HttpDelete(ApiPaths.Timelines.DELETE_M_RemoveConversation), Scope("write:conversations")]
|
||||
public async Task<IActionResult> RemoveConversation(string id, CancellationToken token)
|
||||
{
|
||||
var group = await MyConversation(id, token);
|
||||
@@ -194,7 +194,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(new { });
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/markers"), Scope("read:statuses")]
|
||||
[HttpGet(ApiPaths.Timelines.GET_Markers), Scope("read:statuses")]
|
||||
public async Task<IActionResult> Markers(CancellationToken token)
|
||||
{
|
||||
var wanted = Params.List("timeline");
|
||||
@@ -203,7 +203,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
.ToDictionary(m => m.Timeline, m => new Entities.Marker { LastReadId = m.LastReadId, Version = m.Version, UpdatedAt = MastodonJson.Time(m.UpdatedAt) }));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/markers"), Scope("write:statuses")]
|
||||
[HttpPost(ApiPaths.Timelines.POST_SaveMarkers), Scope("write:statuses")]
|
||||
public async Task<IActionResult> SaveMarkers(CancellationToken token)
|
||||
{
|
||||
var result = new Dictionary<string, Entities.Marker>();
|
||||
@@ -276,7 +276,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
// (notifications made before the policy have no Filtered at all)
|
||||
static readonly FilterDefinition<NotificationEntity> NotFiltered = Builders<NotificationEntity>.Filter.Ne(n => n.Filtered, true);
|
||||
|
||||
[HttpGet("/api/v1/notifications"), Scope("read:notifications")]
|
||||
[HttpGet(ApiPaths.Notifications.GET_List), Scope("read:notifications")]
|
||||
public async Task<IActionResult> List(CancellationToken token)
|
||||
{
|
||||
var notifications = await Page.From(Params, Limit(15, 30)).Fetch(Filtered(), n => n.ID, token);
|
||||
@@ -356,7 +356,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet("/api/v2/notifications"), Scope("read:notifications")]
|
||||
[HttpGet(ApiPaths.Notifications.GET_GroupedList), Scope("read:notifications")]
|
||||
public async Task<IActionResult> GroupedList(CancellationToken token)
|
||||
{
|
||||
var notifications = await Page.From(Params, Limit(40, 80)).Fetch(Filtered(), n => n.ID, token);
|
||||
@@ -364,7 +364,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await Groups(notifications, Grouped(), token));
|
||||
}
|
||||
|
||||
[HttpGet("/api/v2/notifications/unread_count"), Scope("read:notifications")]
|
||||
[HttpGet(ApiPaths.Notifications.GET_GroupedUnreadCount), Scope("read:notifications")]
|
||||
public async Task<IActionResult> GroupedUnreadCount(CancellationToken token)
|
||||
{
|
||||
var unread = await Filtered().Match(n => !n.IsRead).Sort(n => n.ID, Order.Descending)
|
||||
@@ -374,7 +374,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(new { count = unread.Where(n => shown.Contains(n.ID)).Select(n => GroupKey(n, grouped)).Distinct().Count() });
|
||||
}
|
||||
|
||||
[HttpGet("/api/v2/notifications/{groupKey}"), Scope("read:notifications")]
|
||||
[HttpGet(ApiPaths.Notifications.GET_M_Group), Scope("read:notifications")]
|
||||
public async Task<IActionResult> Group(string groupKey, CancellationToken token)
|
||||
{
|
||||
var members = await Members(groupKey, token);
|
||||
@@ -383,7 +383,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await Groups(members, new HashSet<string>(DefaultGrouped.Append(Names[members[0].Type])), token));
|
||||
}
|
||||
|
||||
[HttpGet("/api/v2/notifications/{groupKey}/accounts"), Scope("read:notifications")]
|
||||
[HttpGet(ApiPaths.Notifications.GET_M_GroupAccounts), Scope("read:notifications")]
|
||||
public async Task<IActionResult> GroupAccounts(string groupKey, CancellationToken token)
|
||||
{
|
||||
var members = await Members(groupKey, token);
|
||||
@@ -392,7 +392,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json((await Map(members, token)).Select(n => n.Account).DistinctBy(a => a.Id).ToList());
|
||||
}
|
||||
|
||||
[HttpPost("/api/v2/notifications/{groupKey}/dismiss"), Scope("write:notifications")]
|
||||
[HttpPost(ApiPaths.Notifications.POST_M_DismissGroup), Scope("write:notifications")]
|
||||
public async Task<IActionResult> DismissGroup(string groupKey, CancellationToken token)
|
||||
{
|
||||
if (InGroup(groupKey) is not { } filter)
|
||||
@@ -401,7 +401,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(new { });
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/notifications/{id}"), Scope("read:notifications")]
|
||||
[HttpGet(ApiPaths.Notifications.GET_M_Get), Scope("read:notifications")]
|
||||
public async Task<IActionResult> Get(string id, CancellationToken token)
|
||||
{
|
||||
var notification = await dbEntities.Notifications.Match(n => n.ID == id && n.AvatarId == MyId).ExecuteFirstAsync(token);
|
||||
@@ -409,14 +409,14 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return mapped == default ? NotFoundError() : Json(mapped);
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/notifications/clear"), HttpPost("/api/v2/notifications/clear"), Scope("write:notifications")]
|
||||
[HttpPost(ApiPaths.Notifications.POST_Clear), HttpPost(ApiPaths.Notifications.POST_ClearV2), Scope("write:notifications")]
|
||||
public async Task<IActionResult> Clear(CancellationToken token)
|
||||
{
|
||||
await DB.Default.DeleteAsync<NotificationEntity>(n => n.AvatarId == MyId);
|
||||
return Json(new { });
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/notifications/{id}/dismiss"), Scope("write:notifications")]
|
||||
[HttpPost(ApiPaths.Notifications.POST_M_Dismiss), Scope("write:notifications")]
|
||||
public async Task<IActionResult> Dismiss(string id, CancellationToken token)
|
||||
{
|
||||
await DB.Default.DeleteAsync<NotificationEntity>(n => n.ID == id && n.AvatarId == MyId);
|
||||
@@ -425,7 +425,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
|
||||
// counts what the list would show (Map drops notifications from gone accounts and about hidden posts), at most
|
||||
// `limit` of them, as Mastodon does
|
||||
[HttpGet("/api/v1/notifications/unread_count"), Scope("read:notifications")]
|
||||
[HttpGet(ApiPaths.Notifications.GET_UnreadCount), Scope("read:notifications")]
|
||||
public async Task<IActionResult> UnreadCount(CancellationToken token)
|
||||
{
|
||||
var unread = await DB.Default.Find<NotificationEntity>().Match(n => n.AvatarId == MyId && !n.IsRead).Match(NotFiltered)
|
||||
|
||||
Reference in new issue
Block a user