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
@@ -16,29 +16,15 @@ using PostEntity = PrivaPub.Models.Post.Post;
|
||||
|
||||
namespace PrivaPub.Federation.Inbox.Handlers
|
||||
{
|
||||
public class UpdateHandler : IActivityHandler
|
||||
public class UpdateHandler(
|
||||
DbEntities dbEntities,
|
||||
ILocalActorService localActors,
|
||||
IRemoteActorService remoteActors,
|
||||
IGroupDistributor groups,
|
||||
IObjectRecords records,
|
||||
IQuoteService quotes,
|
||||
IDeliveryService delivery = default) : IActivityHandler
|
||||
{
|
||||
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly IRemoteActorService _remoteActors;
|
||||
readonly IGroupDistributor _groups;
|
||||
readonly IObjectRecords _records;
|
||||
readonly IQuoteService _quotes;
|
||||
readonly IDeliveryService _delivery;
|
||||
|
||||
public UpdateHandler(DbEntities dbEntities, ILocalActorService localActors, IRemoteActorService remoteActors, IGroupDistributor groups,
|
||||
IObjectRecords records, IQuoteService quotes, IDeliveryService delivery = default)
|
||||
{
|
||||
_delivery = delivery;
|
||||
_quotes = quotes;
|
||||
_records = records;
|
||||
_groups = groups;
|
||||
_dbEntities = dbEntities;
|
||||
_localActors = localActors;
|
||||
_remoteActors = remoteActors;
|
||||
}
|
||||
|
||||
public string Type => "Update";
|
||||
|
||||
public async Task Handle(JsonNode activity, ForeignAvatar actor, CancellationToken token)
|
||||
@@ -46,7 +32,7 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
var inner = activity["object"];
|
||||
if (Id(inner) == actor.ActorURI)
|
||||
{
|
||||
await _remoteActors.GetActor(actor.ActorURI, refresh: true, token);
|
||||
await remoteActors.GetActor(actor.ActorURI, refresh: true, token);
|
||||
Arrival.Accept("actor-refresh");
|
||||
Arrival.About(actor.AvatarType.ToString());
|
||||
return;
|
||||
@@ -61,7 +47,7 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
// as that server has it now
|
||||
if (note != default && note.AttributedTo != actor.ActorURI && Origin.Same(note.AttributedTo, actor.ActorURI))
|
||||
{
|
||||
using var fetched = await _remoteActors.FetchObject(note.Id, token);
|
||||
using var fetched = await remoteActors.FetchObject(note.Id, token);
|
||||
var current = fetched == default ? default : NoteParser.Parse(JsonNode.Parse(fetched.Root.GetRawText()));
|
||||
if (current == default || current.Id != note.Id || current.AttributedTo != note.AttributedTo)
|
||||
{
|
||||
@@ -69,7 +55,7 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
return;
|
||||
}
|
||||
note = current;
|
||||
actor = await _remoteActors.GetActor(note.AttributedTo, refresh: false, token);
|
||||
actor = await remoteActors.GetActor(note.AttributedTo, refresh: false, token);
|
||||
if (actor == default)
|
||||
{
|
||||
Arrival.Drop("author-unavailable");
|
||||
@@ -82,7 +68,7 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
return;
|
||||
}
|
||||
|
||||
var post = await _dbEntities.Posts.Match(p => p.ObjectURI == note.Id && p.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
var post = await dbEntities.Posts.Match(p => p.ObjectURI == note.Id && p.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
if (post == default || post.DeletedAt.HasValue)
|
||||
{
|
||||
Arrival.Drop("unknown-object");
|
||||
@@ -90,12 +76,12 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
}
|
||||
Arrival.About(note.Type, post.Visibility, post.CreationDate);
|
||||
|
||||
var edited = await RemoteEdits.Apply(post, note, Id(activity), _localActors, _records, _quotes, token);
|
||||
var edited = await RemoteEdits.Apply(post, note, Id(activity), localActors, records, quotes, token);
|
||||
Arrival.Accept(edited ? "edit" : "refresh");
|
||||
if (edited)
|
||||
await ReplyRelay.Pass(post, _dbEntities, _localActors, _delivery, token);
|
||||
if (edited && !string.IsNullOrEmpty(post.GroupId) && await _localActors.FindById(Models.Federation.LocalActorKind.Group, post.GroupId, token) is { IsCircle: false } community)
|
||||
await _groups.Announce(community, activity.AsObject(), post.ObjectURI, isNewPost: false, token);
|
||||
await ReplyRelay.Pass(post, dbEntities, localActors, delivery, token);
|
||||
if (edited && !string.IsNullOrEmpty(post.GroupId) && await localActors.FindById(Models.Federation.LocalActorKind.Group, post.GroupId, token) is { IsCircle: false } community)
|
||||
await groups.Announce(community, activity.AsObject(), post.ObjectURI, isNewPost: false, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user