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
@@ -27,18 +27,12 @@ namespace PrivaPub.Domain.Social
|
||||
Task<bool> Unreact(LocalActor me, PostEntity post, string emoji, CancellationToken token);
|
||||
}
|
||||
|
||||
public class Reactions : IReactions
|
||||
public class Reactions(
|
||||
DbEntities dbEntities,
|
||||
IDeliveryService delivery) : IReactions
|
||||
{
|
||||
static readonly string[] Hearts = { "❤", "❤️", "♥", "♥️" };
|
||||
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly IDeliveryService _delivery;
|
||||
|
||||
public Reactions(DbEntities dbEntities, IDeliveryService delivery)
|
||||
{
|
||||
_dbEntities = dbEntities;
|
||||
_delivery = delivery;
|
||||
}
|
||||
|
||||
public static bool IsHeart(string content) => content == default || Hearts.Contains(content.Trim());
|
||||
|
||||
@@ -64,7 +58,7 @@ namespace PrivaPub.Domain.Social
|
||||
}
|
||||
Arrival.Accept("reaction");
|
||||
if (!post.IsFederatedCopy)
|
||||
await Notifications.Add(post.GroupUserId, NotificationType.Reaction, actor.ID, actor.ActorURI, post.ID, token, emoji.Name, emoji.Url);
|
||||
await Notifications.Add(post.GroupUserId, NotificationType.Reaction, actor.ID, actor.ActorURI, post.ID, emoji.Name, emoji.Url, token: token);
|
||||
}
|
||||
|
||||
public async Task<bool> Withdraw(ForeignAvatar actor, string activityId, string objectUri, string content, CancellationToken token)
|
||||
@@ -74,7 +68,7 @@ namespace PrivaPub.Domain.Social
|
||||
: await DB.Default.Find<Reaction>().Match(r => r.ActivityURI == activityId && r.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
if (reaction == default && objectUri != default && Normalise(content, new()) is { } emoji)
|
||||
{
|
||||
var post = await _dbEntities.Posts.Match(p => p.ObjectURI == objectUri).ExecuteFirstAsync(token);
|
||||
var post = await dbEntities.Posts.Match(p => p.ObjectURI == objectUri).ExecuteFirstAsync(token);
|
||||
reaction = post == default
|
||||
? default
|
||||
: await DB.Default.Find<Reaction>().Match(r => r.PostId == post.ID && r.ActorURI == actor.ActorURI && r.Emoji == emoji.Name).ExecuteFirstAsync(token);
|
||||
@@ -114,7 +108,7 @@ namespace PrivaPub.Domain.Social
|
||||
return true;
|
||||
}
|
||||
if (!post.IsFederatedCopy)
|
||||
await Notifications.Add(post.GroupUserId, NotificationType.Reaction, me.Id, me.Uri, post.ID, token, picked.Name, picked.Url);
|
||||
await Notifications.Add(post.GroupUserId, NotificationType.Reaction, me.Id, me.Uri, post.ID, picked.Name, picked.Url, token: token);
|
||||
else
|
||||
await Tell(me, post, Activity(me, post, reaction), token);
|
||||
return true;
|
||||
@@ -169,9 +163,9 @@ namespace PrivaPub.Domain.Social
|
||||
|
||||
async Task Tell(LocalActor me, PostEntity post, JsonObject activity, CancellationToken token)
|
||||
{
|
||||
var author = await _dbEntities.ForeignAvatars.Match(f => f.ActorURI == post.ActorURI).ExecuteFirstAsync(token);
|
||||
var author = await dbEntities.ForeignAvatars.Match(f => f.ActorURI == post.ActorURI).ExecuteFirstAsync(token);
|
||||
if (!string.IsNullOrEmpty(author?.InboxURL))
|
||||
await _delivery.Enqueue(me, new[] { author.InboxURL }, activity, token);
|
||||
await delivery.Enqueue(me, new[] { author.InboxURL }, activity, token: token);
|
||||
}
|
||||
|
||||
public sealed record Picked(string Name, string Url);
|
||||
|
||||
Reference in new issue
Block a user