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
@@ -191,7 +191,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return NotFoundError();
|
||||
await ConversationStates.Hide(MyId, group.ID, group.LastPostId, token);
|
||||
await ConversationStates.Read(MyId, group.ID, group.LastPostId, token);
|
||||
return Json(new { });
|
||||
return Json(new EmptyEntity());
|
||||
}
|
||||
|
||||
[HttpGet(ApiPaths.Timelines.GET_Markers), Scope("read:statuses")]
|
||||
@@ -332,27 +332,27 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
var newest = mapped[group.First().ID];
|
||||
var total = group.Key.StartsWith("ungrouped-", StringComparison.Ordinal) ? 1
|
||||
: await DB.Default.CountAsync(Builders<NotificationEntity>.Filter.And(Builders<NotificationEntity>.Filter.Where(InGroup(group.Key)), NotFiltered), token);
|
||||
groups.Add(new
|
||||
groups.Add(new NotificationGroupEntity
|
||||
{
|
||||
group_key = group.Key,
|
||||
notifications_count = Math.Max(total, group.Count()),
|
||||
type = newest.Type,
|
||||
most_recent_notification_id = newest.Id,
|
||||
page_min_id = group.Last().ID,
|
||||
page_max_id = group.First().ID,
|
||||
latest_page_notification_at = newest.CreatedAt,
|
||||
sample_account_ids = group.Select(n => mapped[n.ID].Account.Id).Distinct().Take(8).ToList(),
|
||||
status_id = newest.Status?.Id,
|
||||
emoji = newest.Emoji,
|
||||
emoji_url = newest.EmojiUrl,
|
||||
moderation_warning = newest.ModerationWarning
|
||||
GroupKey = group.Key,
|
||||
NotificationsCount = Math.Max(total, group.Count()),
|
||||
Type = newest.Type,
|
||||
MostRecentNotificationId = newest.Id,
|
||||
PageMinId = group.Last().ID,
|
||||
PageMaxId = group.First().ID,
|
||||
LatestPageNotificationAt = newest.CreatedAt,
|
||||
SampleAccountIds = group.Select(n => mapped[n.ID].Account.Id).Distinct().Take(8).ToList(),
|
||||
StatusId = newest.Status?.Id,
|
||||
Emoji = newest.Emoji,
|
||||
EmojiUrl = newest.EmojiUrl,
|
||||
ModerationWarning = newest.ModerationWarning
|
||||
});
|
||||
}
|
||||
return new
|
||||
return new GroupedNotificationsEntity
|
||||
{
|
||||
accounts = mapped.Values.Select(n => n.Account).DistinctBy(a => a.Id).ToList(),
|
||||
statuses = mapped.Values.Where(n => n.Status != default).Select(n => n.Status).DistinctBy(s => s.Id).ToList(),
|
||||
notification_groups = groups
|
||||
Accounts = mapped.Values.Select(n => n.Account).DistinctBy(a => a.Id).ToList(),
|
||||
Statuses = mapped.Values.Where(n => n.Status != default).Select(n => n.Status).DistinctBy(s => s.Id).ToList(),
|
||||
NotificationGroups = groups
|
||||
};
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
.Limit(Math.Clamp(Params.Int("limit") ?? 100, 1, 1000)).ExecuteAsync(token);
|
||||
var shown = (await Map(unread, token)).Select(n => n.Id).ToHashSet();
|
||||
var grouped = Grouped();
|
||||
return Json(new { count = unread.Where(n => shown.Contains(n.ID)).Select(n => GroupKey(n, grouped)).Distinct().Count() });
|
||||
return Json(new UnreadCountEntity { Count = unread.Where(n => shown.Contains(n.ID)).Select(n => GroupKey(n, grouped)).Distinct().Count() });
|
||||
}
|
||||
|
||||
[HttpGet(ApiPaths.Notifications.GET_M_Group), Scope("read:notifications")]
|
||||
@@ -398,7 +398,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
if (InGroup(groupKey) is not { } filter)
|
||||
return NotFoundError();
|
||||
await DB.Default.DeleteAsync(filter);
|
||||
return Json(new { });
|
||||
return Json(new EmptyEntity());
|
||||
}
|
||||
|
||||
[HttpGet(ApiPaths.Notifications.GET_M_Get), Scope("read:notifications")]
|
||||
@@ -413,14 +413,14 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
public async Task<IActionResult> Clear(CancellationToken token)
|
||||
{
|
||||
await DB.Default.DeleteAsync<NotificationEntity>(n => n.AvatarId == MyId);
|
||||
return Json(new { });
|
||||
return Json(new EmptyEntity());
|
||||
}
|
||||
|
||||
[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);
|
||||
return Json(new { });
|
||||
return Json(new EmptyEntity());
|
||||
}
|
||||
|
||||
// counts what the list would show (Map drops notifications from gone accounts and about hidden posts), at most
|
||||
@@ -430,7 +430,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
{
|
||||
var unread = await DB.Default.Find<NotificationEntity>().Match(n => n.AvatarId == MyId && !n.IsRead).Match(NotFiltered)
|
||||
.Sort(n => n.ID, Order.Descending).Limit(Math.Clamp(Params.Int("limit") ?? 100, 1, 1000)).ExecuteAsync(token);
|
||||
return Json(new { count = (await Map(unread, token)).Count });
|
||||
return Json(new UnreadCountEntity { Count = (await Map(unread, token)).Count });
|
||||
}
|
||||
|
||||
Task<List<Entities.Notification>> Map(List<NotificationEntity> notifications, CancellationToken token) =>
|
||||
|
||||
Reference in new issue
Block a user