Build / Build (push) Successful in 36s
- ObjectRecord, one per stored remote object: the raw JSON (up to 256 KB, always hashed), delivered or fetched, refetched from origin or not, the activity that brought it (or caused the fetch), shared or personal inbox, the signature's key, algorithm and signed headers, received time, published and updated, the delivering activity's @context, and up to ten later revisions from Update. - Delivery details travel from InboxReceiver through the inbox job to the handlers as Arrival.Current. - A host is described from its NodeInfo when we first hear from it, at most weekly (DescribeInstance job), never when someone opens the details view. - GET /api/privapub/v1/statuses/:id/provenance and /api/privapub/v1/instances/:host, with the extensions an object used detected from its raw form (044f quotes, interaction policies, contexts, proofs, Misskey fields, MFM, FEP-8967 links, emoji, polls, language maps, url variants, Markdown content). Checked live: a GoToSocial reply shows as delivered to the shared inbox, signed hs2019 with GoToSocial's fragment-less key id, with its interaction policy detected, and gts.test is described as gotosocial 0.22.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012CzABvBkbcFqoHdmi8b9WB
64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using PrivaPub.Federation.Actors;
|
|
using PrivaPub.Infrastructure.Jobs;
|
|
using PrivaPub.Models.Jobs;
|
|
using PrivaPub.Models.User;
|
|
|
|
using System.Text.Json;
|
|
using System.Text.Json.Nodes;
|
|
|
|
using static PrivaPub.Federation.Objects.ActivityJson;
|
|
|
|
namespace PrivaPub.Federation.Inbox
|
|
{
|
|
public interface IActivityHandler
|
|
{
|
|
string Type { get; }
|
|
Task Handle(JsonNode activity, ForeignAvatar actor, CancellationToken token);
|
|
}
|
|
|
|
public class InboxProcessor : IJobHandler
|
|
{
|
|
readonly IRemoteActorService _remoteActors;
|
|
readonly IReadOnlyDictionary<string, IActivityHandler> _handlers;
|
|
readonly ILogger<InboxProcessor> _logger;
|
|
|
|
public InboxProcessor(IRemoteActorService remoteActors, IEnumerable<IActivityHandler> handlers, ILogger<InboxProcessor> logger)
|
|
{
|
|
_remoteActors = remoteActors;
|
|
_handlers = handlers.ToDictionary(h => h.Type, StringComparer.Ordinal);
|
|
_logger = logger;
|
|
}
|
|
|
|
public JobKind Kind => JobKind.ProcessInbox;
|
|
public int Concurrency => 2;
|
|
public int MaxAttempts => 8;
|
|
public int PerHostLimit => 2;
|
|
|
|
public async Task<JobOutcome> Handle(Job job, CancellationToken token)
|
|
{
|
|
var payload = JsonSerializer.Deserialize<InboxPayload>(job.Payload);
|
|
var activity = payload == default ? default : JsonNode.Parse(payload.Activity);
|
|
var type = Value(activity, "type");
|
|
if (type == default || !_handlers.TryGetValue(type, out var handler))
|
|
return JobOutcome.Done;
|
|
|
|
var actor = await _remoteActors.GetActor(payload.ActorURI, refresh: false, token);
|
|
if (actor == default)
|
|
return JobOutcome.Retry("the actor could not be loaded");
|
|
|
|
Arrival.Current = new Arrival(Id(activity), type, actor.ActorURI, payload.Inbox, payload.KeyId, payload.Algorithm,
|
|
payload.SignedHeaders ?? Array.Empty<string>(), payload.ReceivedAt ?? job.CreatedAt, activity["@context"]?.ToJsonString());
|
|
try
|
|
{
|
|
await handler.Handle(activity, actor, token);
|
|
}
|
|
finally
|
|
{
|
|
Arrival.Current = default;
|
|
}
|
|
_logger.LogInformation("Processed {Type} {Id} from {Actor}", type, Id(activity), actor.ActorURI);
|
|
return JobOutcome.Done;
|
|
}
|
|
}
|
|
}
|