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,19 +16,11 @@ using PostEntity = PrivaPub.Models.Post.Post;
|
||||
|
||||
namespace PrivaPub.Federation.Inbox.Handlers
|
||||
{
|
||||
public class UndoHandler : IActivityHandler
|
||||
public class UndoHandler(
|
||||
DbEntities dbEntities,
|
||||
ILocalActorService localActors,
|
||||
IReactions reactions) : IActivityHandler
|
||||
{
|
||||
readonly IReactions _reactions;
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly ILocalActorService _localActors;
|
||||
|
||||
public UndoHandler(DbEntities dbEntities, ILocalActorService localActors, IReactions reactions)
|
||||
{
|
||||
_reactions = reactions;
|
||||
_dbEntities = dbEntities;
|
||||
_localActors = localActors;
|
||||
}
|
||||
|
||||
public string Type => "Undo";
|
||||
|
||||
public async Task Handle(JsonNode activity, ForeignAvatar actor, CancellationToken token)
|
||||
@@ -48,11 +40,11 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
if (innerType is null or "Dislike")
|
||||
undone |= await UndoDislike(inner, innerId, actor, token);
|
||||
if (innerType is null or "Block")
|
||||
undone |= await BlockHandler.Undo(inner, innerId, actor, _localActors, token);
|
||||
undone |= await BlockHandler.Undo(inner, innerId, actor, localActors, token);
|
||||
if (innerType == "Lock")
|
||||
undone |= await LockHandler.Set(_dbEntities, Id(inner["object"]), actor, locked: false, token);
|
||||
undone |= await LockHandler.Set(dbEntities, Id(inner["object"]), actor, locked: false, token);
|
||||
if (innerType is null or "Like" or "EmojiReact")
|
||||
undone |= await _reactions.Withdraw(actor, innerId, inner is JsonObject ? Id(inner["object"]) : default,
|
||||
undone |= await reactions.Withdraw(actor, innerId, inner is JsonObject ? Id(inner["object"]) : default,
|
||||
inner is JsonObject ? Value(inner, "_misskey_reaction") ?? Value(inner, "content") : default, token);
|
||||
if (undone)
|
||||
Arrival.Accept("undone");
|
||||
@@ -67,7 +59,7 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
: await DB.Default.Find<Downvote>().Match(d => d.ActivityURI == innerId && d.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
if (downvote == default && inner is JsonObject && Id(inner["object"]) is { } objectUri)
|
||||
{
|
||||
var post = await _dbEntities.Posts.Match(p => p.ObjectURI == objectUri).ExecuteFirstAsync(token);
|
||||
var post = await dbEntities.Posts.Match(p => p.ObjectURI == objectUri).ExecuteFirstAsync(token);
|
||||
downvote = post == default
|
||||
? default
|
||||
: await DB.Default.Find<Downvote>().Match(d => d.PostId == post.ID && d.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
@@ -81,9 +73,9 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
|
||||
async Task<bool> UndoFollow(JsonNode inner, string innerId, ForeignAvatar actor, CancellationToken token)
|
||||
{
|
||||
var followers = await _dbEntities.Followers.Match(f => f.ActorURI == actor.ActorURI).ExecuteAsync(token);
|
||||
var followers = await dbEntities.Followers.Match(f => f.ActorURI == actor.ActorURI).ExecuteAsync(token);
|
||||
var targetUri = inner is JsonObject ? Id(inner["object"]) : default;
|
||||
var target = targetUri == default ? default : await _localActors.FindByAddress(targetUri, token);
|
||||
var target = targetUri == default ? default : await localActors.FindByAddress(targetUri, token);
|
||||
var undone = false;
|
||||
foreach (var follower in followers)
|
||||
{
|
||||
@@ -104,13 +96,13 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
{
|
||||
var favourite = innerId == default
|
||||
? default
|
||||
: await _dbEntities.Favourites.Match(f => f.ActivityURI == innerId && f.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
: await dbEntities.Favourites.Match(f => f.ActivityURI == innerId && f.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
if (favourite == default && inner is JsonObject && Id(inner["object"]) is { } objectUri)
|
||||
{
|
||||
var post = await _dbEntities.Posts.Match(p => p.ObjectURI == objectUri).ExecuteFirstAsync(token);
|
||||
var post = await dbEntities.Posts.Match(p => p.ObjectURI == objectUri).ExecuteFirstAsync(token);
|
||||
favourite = post == default
|
||||
? default
|
||||
: await _dbEntities.Favourites.Match(f => f.PostId == post.ID && f.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
: await dbEntities.Favourites.Match(f => f.PostId == post.ID && f.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
}
|
||||
if (favourite == default)
|
||||
return false;
|
||||
@@ -123,7 +115,7 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
{
|
||||
if (innerId == default)
|
||||
return false;
|
||||
var reblog = await _dbEntities.Posts
|
||||
var reblog = await dbEntities.Posts
|
||||
.Match(p => p.ObjectURI == innerId && p.ActorURI == actor.ActorURI && p.ReblogOfPostId != null)
|
||||
.ExecuteFirstAsync(token);
|
||||
if (reblog == default)
|
||||
|
||||
Reference in new issue
Block a user