House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s
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:
1 parent
f0a14c737f
commit
0f73f69239
176 files changed
+2789
-3974
No files matched your search
@@ -23,25 +23,15 @@ namespace PrivaPub.Federation.Actors
|
||||
// only PrivaPub remembers ends, a request it answered without our knowing is accepted, and a follow only it remembers
|
||||
// is undone by the persona, as Mastodon does, or kept within RestoreRecord.FollowersGrace of a restore, which may have
|
||||
// lost it. A follow ends only when the list is the one the digest describes.
|
||||
public class FollowingSynchronization : IJobHandler
|
||||
public class FollowingSynchronization(
|
||||
DbEntities dbEntities,
|
||||
ILocalActorService localActors,
|
||||
IRemoteActorService remoteActors,
|
||||
IFollowService follows,
|
||||
IDeliveryService deliveryService) : IJobHandler
|
||||
{
|
||||
const int MaxPages = 10;
|
||||
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly IRemoteActorService _remoteActors;
|
||||
readonly IFollowService _follows;
|
||||
readonly IDeliveryService _delivery;
|
||||
|
||||
public FollowingSynchronization(DbEntities dbEntities, ILocalActorService localActors, IRemoteActorService remoteActors, IFollowService follows,
|
||||
IDeliveryService delivery)
|
||||
{
|
||||
_dbEntities = dbEntities;
|
||||
_localActors = localActors;
|
||||
_remoteActors = remoteActors;
|
||||
_follows = follows;
|
||||
_delivery = delivery;
|
||||
}
|
||||
|
||||
public JobKind Kind => JobKind.SynchronizeFollowing;
|
||||
public int Concurrency => 1;
|
||||
@@ -55,14 +45,14 @@ namespace PrivaPub.Federation.Actors
|
||||
public async Task<JobOutcome> Handle(Job job, CancellationToken token)
|
||||
{
|
||||
var claim = JsonSerializer.Deserialize<SynchronizationClaim>(job.Payload);
|
||||
var actor = claim == default ? default : await _dbEntities.ForeignAvatars.Match(a => a.ActorURI == claim.Actor && !a.DeletionAt.HasValue).ExecuteFirstAsync(token);
|
||||
var actor = claim == default ? default : await dbEntities.ForeignAvatars.Match(a => a.ActorURI == claim.Actor && !a.DeletionAt.HasValue).ExecuteFirstAsync(token);
|
||||
if (actor == default || string.IsNullOrEmpty(actor.FollowersURL) || claim.CollectionId != actor.FollowersURL || !Origin.Same(claim.Url, actor.ActorURI))
|
||||
return JobOutcome.Done;
|
||||
|
||||
var followings = await _dbEntities.Followings.Match(f => f.TargetActorURI == actor.ActorURI && !f.TargetIsLocal).ExecuteAsync(token);
|
||||
var followings = await dbEntities.Followings.Match(f => f.TargetActorURI == actor.ActorURI && !f.TargetIsLocal).ExecuteAsync(token);
|
||||
var personas = new Dictionary<string, (LocalActor Persona, Following Following)>(StringComparer.Ordinal);
|
||||
foreach (var following in followings)
|
||||
if (await _localActors.FindById(LocalActorKind.Person, following.AvatarId, token) is { } persona)
|
||||
if (await localActors.FindById(LocalActorKind.Person, following.AvatarId, token) is { } persona)
|
||||
personas[persona.Uri] = (persona, following);
|
||||
var accepted = personas.Values.Where(p => p.Following.State == FollowState.Accepted).Select(p => p.Persona.Uri).ToList();
|
||||
if (FollowersSynchronization.Digest(accepted) == claim.Digest)
|
||||
@@ -76,7 +66,7 @@ namespace PrivaPub.Federation.Actors
|
||||
var named = listed.ToHashSet(StringComparer.Ordinal);
|
||||
if (complete)
|
||||
foreach (var uri in accepted.Where(uri => !named.Contains(uri)))
|
||||
await _follows.UnfollowAs(personas[uri].Persona, actor.ActorURI, token);
|
||||
await follows.UnfollowAs(personas[uri].Persona, actor.ActorURI, token);
|
||||
|
||||
foreach (var uri in named)
|
||||
{
|
||||
@@ -86,7 +76,7 @@ namespace PrivaPub.Federation.Actors
|
||||
await DB.Default.Update<Following>().MatchID(known.Following.ID).Modify(f => f.State, FollowState.Accepted).ExecuteAsync(token);
|
||||
continue;
|
||||
}
|
||||
if (await _localActors.FindByUri(uri, token) is not { Kind: LocalActorKind.Person } stranger)
|
||||
if (await localActors.FindByUri(uri, token) is not { Kind: LocalActorKind.Person } stranger)
|
||||
continue;
|
||||
// a follow the restore lost: kept, not undone
|
||||
if (await Infrastructure.Backup.RestoreRecord.InFollowersGrace(token))
|
||||
@@ -110,7 +100,7 @@ namespace PrivaPub.Federation.Actors
|
||||
["actor"] = stranger.Uri,
|
||||
["object"] = new JsonObject { ["type"] = "Follow", ["actor"] = stranger.Uri, ["object"] = actor.ActorURI }
|
||||
};
|
||||
await _delivery.Enqueue(stranger, new[] { string.IsNullOrEmpty(actor.InboxURL) ? actor.SharedInboxURL : actor.InboxURL }, undo, token);
|
||||
await deliveryService.Enqueue(stranger, new[] { string.IsNullOrEmpty(actor.InboxURL) ? actor.SharedInboxURL : actor.InboxURL }, undo, token: token);
|
||||
}
|
||||
return JobOutcome.Done;
|
||||
}
|
||||
@@ -123,7 +113,7 @@ namespace PrivaPub.Federation.Actors
|
||||
var next = url;
|
||||
for (var page = 0; page < MaxPages && next != default; page++)
|
||||
{
|
||||
using var fetched = await _remoteActors.FetchObject(next, token);
|
||||
using var fetched = await remoteActors.FetchObject(next, token);
|
||||
if (fetched == default || fetched.Root.ValueKind != JsonValueKind.Object)
|
||||
return page == 0 ? default : items;
|
||||
var root = fetched.Root;
|
||||
|
||||
Reference in new issue
Block a user