House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s

- Services, controllers and jobs take their dependencies through primary
  constructors and use them directly; where a method already named a local
  after a dependency, the dependency takes its type's name.
- Every async method takes a CancellationToken last and passes it down to
  MongoDB, HTTP and the job queue. The setup claim is still given back when
  a request is cancelled.
- The federation and media options are read through IOptionsMonitor.
- The Mastodon entities keep sending "" for empty strings, and every model
  field where null means something says so.
- The inbox's 503 with Retry-After, which other servers retry, is the one
  server error left, and says why.
- Arasaka.HouseRules.Analyzers checks all of this in every build, here and in
  PrivaPub.ClientModels as decePubClient builds it.

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:
thepraandClaude Opus 5.5 committed 2026-11-10 01:24:43 +01:00
1 parent f0a14c737f
commit 0f73f69239
176 files changed
+2789 -3974

No files matched your search

+19 -28
View File
@@ -23,21 +23,12 @@ namespace PrivaPub.Federation.Outbox
Task PublishFeatured(string personaId, PostEntity post, bool featured, CancellationToken token);
}
public class OutboxPublisher : IOutboxPublisher
public class OutboxPublisher(
DbEntities dbEntities,
ILocalActorService localActors,
IDeliveryService delivery,
Relays.IRelays relays = default) : IOutboxPublisher
{
readonly DbEntities _dbEntities;
readonly ILocalActorService _localActors;
readonly IDeliveryService _delivery;
readonly Relays.IRelays _relays;
public OutboxPublisher(DbEntities dbEntities, ILocalActorService localActors, IDeliveryService delivery, Relays.IRelays relays = default)
{
_relays = relays;
_dbEntities = dbEntities;
_localActors = localActors;
_delivery = delivery;
}
public async Task<IReadOnlyList<string>> Audience(LocalActor author, PostEntity post, CancellationToken token)
{
if (post.Visibility == PostVisibility.LocalGeo || post.IsLocalOnly)
@@ -47,7 +38,7 @@ namespace PrivaPub.Federation.Outbox
var inboxes = new List<string>();
if (post.Visibility is PostVisibility.Public or PostVisibility.Unlisted or PostVisibility.FollowersOnly)
inboxes.AddRange(await _delivery.FollowerInboxes(author, token));
inboxes.AddRange(await delivery.FollowerInboxes(author, token));
//nothing is addressed to an account that blocked the author (it would refuse it, and Mastodon counts on that)
var blockers = (await DB.Default.Find<BlockedBy>().Match(b => b.AvatarId == author.Id).ExecuteAsync(token))
@@ -61,23 +52,23 @@ namespace PrivaPub.Federation.Outbox
.ToList();
foreach (var uri in addressed)
{
var actor = await _dbEntities.ForeignAvatars.Match(a => a.ActorURI == uri).ExecuteFirstAsync(token);
var actor = await dbEntities.ForeignAvatars.Match(a => a.ActorURI == uri).ExecuteFirstAsync(token);
if (Preferred(actor) is { } inbox)
inboxes.Add(inbox);
}
if (post.Visibility != PostVisibility.Direct && !string.IsNullOrEmpty(post.InReplyToAccountId))
{
var parentAuthor = await _dbEntities.ForeignAvatars.MatchID(post.InReplyToAccountId).ExecuteFirstAsync(token);
var parentAuthor = await dbEntities.ForeignAvatars.MatchID(post.InReplyToAccountId).ExecuteFirstAsync(token);
if (Preferred(parentAuthor) is { } inbox && !blockers.Contains(parentAuthor.ActorURI) && !parentAuthor.SuspendedAt.HasValue)
inboxes.Add(inbox);
}
if (post.Visibility is PostVisibility.Public or PostVisibility.Unlisted && !string.IsNullOrEmpty(post.QuotedPostId))
{
var quoted = await _dbEntities.Posts.MatchID(post.QuotedPostId).ExecuteFirstAsync(token);
var quoted = await dbEntities.Posts.MatchID(post.QuotedPostId).ExecuteFirstAsync(token);
var quotedAuthor = quoted is { IsFederatedCopy: true }
? await _dbEntities.ForeignAvatars.Match(a => a.ActorURI == quoted.ActorURI).ExecuteFirstAsync(token)
? await dbEntities.ForeignAvatars.Match(a => a.ActorURI == quoted.ActorURI).ExecuteFirstAsync(token)
: default;
if (Preferred(quotedAuthor) is { } inbox && !quotedAuthor.SuspendedAt.HasValue)
inboxes.Add(inbox);
@@ -86,9 +77,9 @@ namespace PrivaPub.Federation.Outbox
// a persona's own public post, outside any group, also goes to the relays we subscribe to (owner decision
// 2026-10-06), its edits and deletion with it; a silenced persona's never does (R6): the relays are where strangers
// read
if (_relays != default && post.Visibility == PostVisibility.Public && author.Kind == LocalActorKind.Person
if (relays != default && post.Visibility == PostVisibility.Public && author.Kind == LocalActorKind.Person
&& string.IsNullOrEmpty(post.ReblogOfPostId) && string.IsNullOrEmpty(post.GroupId) && !post.AuthorLimited && !author.Silenced)
inboxes.AddRange(await _relays.Inboxes(token));
inboxes.AddRange(await relays.Inboxes(token));
return inboxes.Where(i => !string.IsNullOrEmpty(i)).Distinct(StringComparer.Ordinal).ToList();
}
@@ -104,13 +95,13 @@ namespace PrivaPub.Federation.Outbox
async Task<IReadOnlyList<ForeignAvatar>> CircleRecipients(string groupId, CancellationToken token)
{
var circle = string.IsNullOrEmpty(groupId) ? default : await _dbEntities.Groups.MatchID(groupId).ExecuteFirstAsync(token);
var circle = string.IsNullOrEmpty(groupId) ? default : await dbEntities.Groups.MatchID(groupId).ExecuteFirstAsync(token);
if (circle == default)
return Array.Empty<ForeignAvatar>();
var remote = circle.Members.Where(m => m.IsForeign).Select(m => m.AvatarId).ToList();
if (remote.Count == 0)
return Array.Empty<ForeignAvatar>();
return (await _dbEntities.ForeignAvatars.Match(a => remote.Contains(a.ActorURI)).ExecuteAsync(token))
return (await dbEntities.ForeignAvatars.Match(a => remote.Contains(a.ActorURI)).ExecuteAsync(token))
.Where(a => !string.IsNullOrEmpty(a.InboxURL))
.ToList();
}
@@ -120,19 +111,19 @@ namespace PrivaPub.Federation.Outbox
if (post.Visibility == PostVisibility.Circle)
{
foreach (var member in await CircleRecipients(post.GroupId, token))
await _delivery.Enqueue(author, new[] { member.InboxURL }, Naming(activity, new[] { member }), token);
await delivery.Enqueue(author, new[] { member.InboxURL }, Naming(activity, new[] { member }), token: token);
return;
}
var inboxes = await Audience(author, post, token);
if (inboxes.Count > 0)
await _delivery.Enqueue(author, inboxes, activity, token);
await delivery.Enqueue(author, inboxes, activity, token: token);
}
// a persona pins its post or unpins it: Add or Remove on its featured collection (/trophies, which serves the same
// pins), told to the post's audience as Mastodon tells it
public async Task PublishFeatured(string personaId, PostEntity post, bool featured, CancellationToken token)
{
var author = await _localActors.FindById(LocalActorKind.Person, personaId, token);
var author = await localActors.FindById(LocalActorKind.Person, personaId, token);
if (author is not { IsFederated: true } || post.IsLocalOnly)
return;
await Publish(author, post, new JsonObject
@@ -150,7 +141,7 @@ namespace PrivaPub.Federation.Outbox
public async Task PublishUpdate(LocalActor author, PostEntity post, string reason, CancellationToken token)
{
var group = string.IsNullOrEmpty(post.GroupId) ? default : await _localActors.FindById(LocalActorKind.Group, post.GroupId, token);
var group = string.IsNullOrEmpty(post.GroupId) ? default : await localActors.FindById(LocalActorKind.Group, post.GroupId, token);
await Publish(author, post, ActivityPubRenderer.UpdateOf(post, author, group, reason), token);
}
@@ -206,7 +197,7 @@ namespace PrivaPub.Federation.Outbox
["cc"] = new JsonArray(actor.Followers),
["object"] = document
};
await _delivery.EnqueueToFollowers(actor, update, token);
await delivery.EnqueueToFollowers(actor, update, token: token);
}
}
}