Files
SocialPub/PrivaPub/Federation/Inbox/ReplyRelay.cs
T
thepraandClaude Opus 5.5 0f73f69239
Build / Build (push) Successful in 30s
House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
- 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
2026-11-10 01:24:43 +01:00

44 lines
2.3 KiB
C#

using MongoDB.Entities;
using PrivaPub.Federation.Actors;
using PrivaPub.Federation.Outbox;
using PrivaPub.Infrastructure.Statistics;
using PrivaPub.Models.Federation;
using PrivaPub.Models.Post;
using PrivaPub.StaticServices;
using System.Text.Json.Nodes;
using PostEntity = PrivaPub.Models.Post.Post;
namespace PrivaPub.Federation.Inbox
{
// ActivityPub's inbox forwarding of replies (owner decision 2026-10-05): a public or unlisted reply to one of our
// personas' own posts reaches the persona's followers as its author sent it, and so do its edits and its deletion, as
// Mastodon forwards the replies to its accounts' posts. The author's server sends a reply to its own followers and to
// the persona, never to the persona's followers, who would otherwise see half of the thread. It goes as it came (an
// LD signature in it stays good), signed by the persona; never to the replier's own server, never once more when it
// reached us forwarded, and never for a followers-only reply or a DM, which were not for the persona's followers.
public static class ReplyRelay
{
public static async Task Pass(PostEntity reply, DbEntities db, ILocalActorService localActors, IDeliveryService delivery, CancellationToken token)
{
var raw = Arrival.Current?.Raw;
if (raw == default || delivery == default || localActors == default || reply is not { IsFederatedCopy: true }
|| reply.Visibility is not (PostVisibility.Public or PostVisibility.Unlisted) || string.IsNullOrEmpty(reply.AnsweringToPostId))
return;
var parent = await db.Posts.MatchID(reply.AnsweringToPostId).ExecuteFirstAsync(token);
if (parent is not { IsFederatedCopy: false, IsLocalOnly: false } || !string.IsNullOrEmpty(parent.GroupId)
|| parent.Visibility is not (PostVisibility.Public or PostVisibility.Unlisted or PostVisibility.FollowersOnly))
return;
var owner = await localActors.FindById(LocalActorKind.Person, parent.GroupUserId, token);
if (owner is not { IsFederated: true } || JsonNode.Parse(raw) is not JsonObject activity)
return;
var replier = Interactions.HostOf(reply.ActorURI);
var inboxes = (await delivery.FollowerInboxes(owner, token)).Where(i => Interactions.HostOf(i) != replier).ToList();
if (inboxes.Count > 0)
await delivery.Enqueue(owner, inboxes, activity, token: token);
}
}
}