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
@@ -32,42 +32,33 @@ namespace PrivaPub.Federation.Actors
|
||||
// the persona and its followers, and told to its followers' servers with Add{Note}. The persona may take it off again
|
||||
// (Remove, which Smithereen takes for a deletion, as it is on its walls). Another server's account that tells its
|
||||
// followers here of a post on its wall (Add) has it shown to them as on its wall.
|
||||
public class Walls : IWalls
|
||||
public class Walls(
|
||||
DbEntities dbEntities,
|
||||
ILocalActorService localActors,
|
||||
IRemotePosts remotePosts,
|
||||
IDeliveryService delivery,
|
||||
IFanout fanout) : IWalls
|
||||
{
|
||||
public const string Path = "graffiti";
|
||||
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly IRemotePosts _remotePosts;
|
||||
readonly IDeliveryService _delivery;
|
||||
readonly IFanout _fanout;
|
||||
|
||||
public Walls(DbEntities dbEntities, ILocalActorService localActors, IRemotePosts remotePosts, IDeliveryService delivery, IFanout fanout)
|
||||
{
|
||||
_dbEntities = dbEntities;
|
||||
_localActors = localActors;
|
||||
_remotePosts = remotePosts;
|
||||
_delivery = delivery;
|
||||
_fanout = fanout;
|
||||
}
|
||||
|
||||
public async Task<LocalActor> OwnerOf(string wallUri, CancellationToken token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(wallUri) || !wallUri.EndsWith("/" + Path, StringComparison.Ordinal))
|
||||
return default;
|
||||
var owner = await _localActors.FindByUri(wallUri[..^(Path.Length + 1)], token);
|
||||
var owner = await localActors.FindByUri(wallUri[..^(Path.Length + 1)], token);
|
||||
return owner is { HasWall: true } && owner.Wall == wallUri ? owner : default;
|
||||
}
|
||||
|
||||
// its followers, as the actor says to Smithereen (wallPosting), unless the persona hides them
|
||||
public async Task<bool> MayWrite(LocalActor owner, ForeignAvatar author, CancellationToken token) =>
|
||||
await _dbEntities.Followers.Match(f => f.LocalActorId == owner.Id && f.LocalActorKind == owner.Kind && f.ActorURI == author.ActorURI && f.IsAccepted)
|
||||
await dbEntities.Followers.Match(f => f.LocalActorId == owner.Id && f.LocalActorKind == owner.Kind && f.ActorURI == author.ActorURI && f.IsAccepted)
|
||||
.ExecuteAnyAsync(token)
|
||||
&& !(await Domain.Relationships.Hidden.RecipientsHiding(new[] { owner.Id }, author.ActorURI, token)).Contains(owner.Id);
|
||||
|
||||
public async Task Hosted(PostEntity post, LocalActor owner, CancellationToken token)
|
||||
{
|
||||
await Notifications.Add(owner.Id, NotificationType.Mention, post.AuthorAccountId, post.ActorURI, post.ID, token);
|
||||
await Notifications.Add(owner.Id, NotificationType.Mention, post.AuthorAccountId, post.ActorURI, post.ID, token: token);
|
||||
var add = new JsonObject
|
||||
{
|
||||
["@context"] = ActivityPubRenderer.Context(),
|
||||
@@ -78,7 +69,7 @@ namespace PrivaPub.Federation.Actors
|
||||
["target"] = new JsonObject { ["type"] = "OrderedCollection", ["id"] = owner.Wall, ["attributedTo"] = owner.Uri },
|
||||
["to"] = new JsonArray(ActivityPubRenderer.Public, owner.Followers, post.ActorURI)
|
||||
};
|
||||
await _delivery.EnqueueToFollowers(owner, add, token, await AuthorInbox(post, token));
|
||||
await delivery.EnqueueToFollowers(owner, add, await AuthorInbox(post, token), token);
|
||||
}
|
||||
|
||||
public async Task Receive(JsonNode activity, ForeignAvatar owner, bool add, CancellationToken token)
|
||||
@@ -91,7 +82,7 @@ namespace PrivaPub.Federation.Actors
|
||||
}
|
||||
if (!add)
|
||||
{
|
||||
var walled = await _dbEntities.Posts.Match(p => p.ObjectURI == objectUri && p.WallOwnerURI == owner.ActorURI).ExecuteFirstAsync(token);
|
||||
var walled = await dbEntities.Posts.Match(p => p.ObjectURI == objectUri && p.WallOwnerURI == owner.ActorURI).ExecuteFirstAsync(token);
|
||||
if (walled == default)
|
||||
{
|
||||
Arrival.Drop("unknown-object");
|
||||
@@ -102,8 +93,8 @@ namespace PrivaPub.Federation.Actors
|
||||
return;
|
||||
}
|
||||
|
||||
var post = await _dbEntities.Posts.Match(p => p.ObjectURI == objectUri && !p.DeletedAt.HasValue).ExecuteFirstAsync(token)
|
||||
?? await _remotePosts.StoreContext(objectUri, 0, token);
|
||||
var post = await dbEntities.Posts.Match(p => p.ObjectURI == objectUri && !p.DeletedAt.HasValue).ExecuteFirstAsync(token)
|
||||
?? await remotePosts.StoreContext(objectUri, 0, token);
|
||||
if (post is not { IsFederatedCopy: true, ReblogOfPostId: null, Visibility: PostVisibility.Public or PostVisibility.Unlisted } || !string.IsNullOrEmpty(post.InReplyToURI))
|
||||
{
|
||||
Arrival.Drop("unknown-object");
|
||||
@@ -123,7 +114,7 @@ namespace PrivaPub.Federation.Actors
|
||||
.Modify(p => p.WallOwnerURI, post.WallOwnerURI)
|
||||
.Modify(p => p.WallOwnerAccountId, post.WallOwnerAccountId)
|
||||
.ExecuteAsync(token);
|
||||
await _fanout.Distribute(post, token);
|
||||
await fanout.Distribute(post, token);
|
||||
Arrival.Accept("walled");
|
||||
}
|
||||
|
||||
@@ -142,14 +133,14 @@ namespace PrivaPub.Federation.Actors
|
||||
["target"] = owner.Wall,
|
||||
["to"] = new JsonArray(ActivityPubRenderer.Public, owner.Followers, post.ActorURI)
|
||||
};
|
||||
await _delivery.EnqueueToFollowers(owner, remove, token, await AuthorInbox(post, token));
|
||||
await delivery.EnqueueToFollowers(owner, remove, await AuthorInbox(post, token), token);
|
||||
await RemoteDeletes.Remove(post, post.ObjectURI, token);
|
||||
return true;
|
||||
}
|
||||
|
||||
async Task<IEnumerable<string>> AuthorInbox(PostEntity post, CancellationToken token)
|
||||
{
|
||||
var author = await _dbEntities.ForeignAvatars.Match(a => a.ActorURI == post.ActorURI).ExecuteFirstAsync(token);
|
||||
var author = await dbEntities.ForeignAvatars.Match(a => a.ActorURI == post.ActorURI).ExecuteFirstAsync(token);
|
||||
var inbox = string.IsNullOrEmpty(author?.SharedInboxURL) ? author?.InboxURL : author.SharedInboxURL;
|
||||
return inbox == default ? Array.Empty<string>() : new[] { inbox };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user