The API's JSON is generated at build time, and no answer is an anonymous object
Build / Build (push) Successful in 36s
Build / Build (push) Successful in 36s
Every answer of the Mastodon API and the client API now has its JSON shape generated when the server is built, instead of worked out by reflection while it runs; the bytes sent are unchanged. The small answers that were anonymous objects (the instance documents, notification policies, reports, lists, tags, trends, errors and the empty answers) are named types. A type without generated metadata fails at once in development and on the pasture, and in production is logged and still answered. Three lists that were sent as lazy sequences (moderation reports, the published domain blocks and the languages) are now built first. 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
8a1e4e419b
commit
f3fdeaf038
41 files changed
+1333
-266
No files matched your search
@@ -3,6 +3,12 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Entities;
|
||||
|
||||
using EmptyEntity = PrivaPub.Api.Mastodon.Entities.EmptyEntity;
|
||||
using MergedEntity = PrivaPub.Api.Mastodon.Entities.MergedEntity;
|
||||
using NotificationPolicyEntity = PrivaPub.Api.Mastodon.Entities.NotificationPolicyEntity;
|
||||
using NotificationPolicySummaryEntity = PrivaPub.Api.Mastodon.Entities.NotificationPolicySummaryEntity;
|
||||
using NotificationPolicyV1Entity = PrivaPub.Api.Mastodon.Entities.NotificationPolicyV1Entity;
|
||||
using NotificationRequestEntity = PrivaPub.Api.Mastodon.Entities.NotificationRequestEntity;
|
||||
using PrivaPub.Api.Mastodon.Infrastructure;
|
||||
using PrivaPub.Api.Mastodon.Mappers;
|
||||
using PrivaPub.Domain.Social;
|
||||
@@ -33,30 +39,30 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
_ => null
|
||||
};
|
||||
|
||||
async Task<object> Summary(CancellationToken token) => new
|
||||
async Task<object> Summary(CancellationToken token) => new NotificationPolicySummaryEntity
|
||||
{
|
||||
pending_requests_count = await DB.Default.CountAsync<NotificationRequest>(r => r.AvatarId == MyId, token),
|
||||
pending_notifications_count = await DB.Default.CountAsync<Notification>(n => n.AvatarId == MyId && n.Filtered, token)
|
||||
PendingRequestsCount = await DB.Default.CountAsync<NotificationRequest>(r => r.AvatarId == MyId, token),
|
||||
PendingNotificationsCount = await DB.Default.CountAsync<Notification>(n => n.AvatarId == MyId && n.Filtered, token)
|
||||
};
|
||||
|
||||
async Task<object> V2(NotificationPolicy policy, CancellationToken token) => new
|
||||
async Task<object> V2(NotificationPolicy policy, CancellationToken token) => new NotificationPolicyEntity
|
||||
{
|
||||
for_not_following = Name(policy.ForNotFollowing),
|
||||
for_not_followers = Name(policy.ForNotFollowers),
|
||||
for_new_accounts = Name(policy.ForNewAccounts),
|
||||
for_private_mentions = Name(policy.ForPrivateMentions),
|
||||
for_limited_accounts = Name(policy.ForLimitedAccounts),
|
||||
summary = await Summary(token)
|
||||
ForNotFollowing = Name(policy.ForNotFollowing),
|
||||
ForNotFollowers = Name(policy.ForNotFollowers),
|
||||
ForNewAccounts = Name(policy.ForNewAccounts),
|
||||
ForPrivateMentions = Name(policy.ForPrivateMentions),
|
||||
ForLimitedAccounts = Name(policy.ForLimitedAccounts),
|
||||
Summary = await Summary(token)
|
||||
};
|
||||
|
||||
// the first version spoke of filtering only: dropped is filtered for it
|
||||
async Task<object> V1(NotificationPolicy policy, CancellationToken token) => new
|
||||
async Task<object> V1(NotificationPolicy policy, CancellationToken token) => new NotificationPolicyV1Entity
|
||||
{
|
||||
filter_not_following = policy.ForNotFollowing != NotificationAction.Accept,
|
||||
filter_not_followers = policy.ForNotFollowers != NotificationAction.Accept,
|
||||
filter_new_accounts = policy.ForNewAccounts != NotificationAction.Accept,
|
||||
filter_private_mentions = policy.ForPrivateMentions != NotificationAction.Accept,
|
||||
summary = await Summary(token)
|
||||
FilterNotFollowing = policy.ForNotFollowing != NotificationAction.Accept,
|
||||
FilterNotFollowers = policy.ForNotFollowers != NotificationAction.Accept,
|
||||
FilterNewAccounts = policy.ForNewAccounts != NotificationAction.Accept,
|
||||
FilterPrivateMentions = policy.ForPrivateMentions != NotificationAction.Accept,
|
||||
Summary = await Summary(token)
|
||||
};
|
||||
|
||||
[HttpGet(ApiPaths.NotificationRequests.GET_Policy), Scope("read:notifications")]
|
||||
@@ -99,14 +105,14 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return default;
|
||||
var post = string.IsNullOrEmpty(request.LastPostId) ? default
|
||||
: await dbEntities.Posts.Match(p => p.ID == request.LastPostId && !p.DeletedAt.HasValue).ExecuteFirstAsync(token);
|
||||
return new
|
||||
return new NotificationRequestEntity
|
||||
{
|
||||
id = request.ID,
|
||||
created_at = MastodonJson.Time(request.CreatedAt),
|
||||
updated_at = MastodonJson.Time(request.UpdatedAt),
|
||||
notifications_count = request.NotificationsCount.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
account,
|
||||
last_status = post == default ? default : await mapper.Status(post, MyId, token)
|
||||
Id = request.ID,
|
||||
CreatedAt = MastodonJson.Time(request.CreatedAt),
|
||||
UpdatedAt = MastodonJson.Time(request.UpdatedAt),
|
||||
NotificationsCount = request.NotificationsCount.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
Account = account,
|
||||
LastStatus = post == default ? default : await mapper.Status(post, MyId, token)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -126,7 +132,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
DB.Default.Find<NotificationRequest>().Match(r => r.ID == id && r.AvatarId == MyId).ExecuteFirstAsync(token);
|
||||
|
||||
[HttpGet(ApiPaths.NotificationRequests.GET_Merged), Scope("read:notifications")]
|
||||
public IActionResult Merged() => Json(new { merged = true });
|
||||
public IActionResult Merged() => Json(new MergedEntity { Merged = true });
|
||||
|
||||
[HttpGet(ApiPaths.NotificationRequests.GET_M_Request), Scope("read:notifications")]
|
||||
public async Task<IActionResult> Request(string id, CancellationToken token) =>
|
||||
@@ -138,7 +144,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
if (await Mine(id, token) is not { } request)
|
||||
return NotFoundError();
|
||||
await NotificationPolicies.Accept(request, token);
|
||||
return Json(new { });
|
||||
return Json(new EmptyEntity());
|
||||
}
|
||||
|
||||
[HttpPost(ApiPaths.NotificationRequests.POST_M_Dismiss), Scope("write:notifications")]
|
||||
@@ -147,7 +153,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
if (await Mine(id, token) is not { } request)
|
||||
return NotFoundError();
|
||||
await NotificationPolicies.Dismiss(request, token);
|
||||
return Json(new { });
|
||||
return Json(new EmptyEntity());
|
||||
}
|
||||
|
||||
[HttpPost(ApiPaths.NotificationRequests.POST_AcceptMany), Scope("write:notifications")]
|
||||
@@ -156,7 +162,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
foreach (var id in Params.List("id").Take(100))
|
||||
if (await Mine(id, token) is { } request)
|
||||
await NotificationPolicies.Accept(request, token);
|
||||
return Json(new { });
|
||||
return Json(new EmptyEntity());
|
||||
}
|
||||
|
||||
[HttpPost(ApiPaths.NotificationRequests.POST_DismissMany), Scope("write:notifications")]
|
||||
@@ -165,7 +171,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
foreach (var id in Params.List("id").Take(100))
|
||||
if (await Mine(id, token) is { } request)
|
||||
await NotificationPolicies.Dismiss(request, token);
|
||||
return Json(new { });
|
||||
return Json(new EmptyEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user