Arrival carries a verdict that handlers set with one line before an existing return (Arrival.Drop, Reject, Accept, About), so no handler signature changes. InboxProcessor records it as an 'in' event, with the time taken, the wait since the inbox accepted it, the attempt, the audience (from the post's visibility, or else the activity's addressing), the local actor kind, the object's age for updates, deletes and reactions, and the FEP features of a delivered object. It also records types nothing handles (unknown-type), actors that cannot be loaded (deferred) and handler failures. Drop reasons: fetch-failed, unparseable, misattributed, duplicate, deleted, not-addressed, not-followed, not-public, not-visible, not-deleted, unknown-object, unknown-recipient, cross-origin, unsupported. Accepted sub-reasons: stored, poll-vote, edit, refresh, actor-refresh, actor-delete, removed, tombstone-only, auto-accepted, pending, follow-answer, quote-answer, quote-granted, undone, reaction, reported. Rejected: blocked, ignored, quote-refused. A circle's traffic is private and kindless, and a stranger posting into one is just not-addressed, so the event store cannot reveal a circle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ELjqpznMFMNrJoJUj6K5p2
71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
using MongoDB.Entities;
|
|
|
|
using PrivaPub.Federation.Actors;
|
|
using PrivaPub.Models.Federation;
|
|
using PrivaPub.Models.Social;
|
|
using PrivaPub.Models.User;
|
|
using PrivaPub.StaticServices;
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
using static PrivaPub.Federation.Objects.ActivityJson;
|
|
|
|
namespace PrivaPub.Federation.Inbox.Handlers
|
|
{
|
|
public class FlagHandler : IActivityHandler
|
|
{
|
|
readonly DbEntities _dbEntities;
|
|
readonly ILocalActorService _localActors;
|
|
|
|
public FlagHandler(DbEntities dbEntities, ILocalActorService localActors)
|
|
{
|
|
_dbEntities = dbEntities;
|
|
_localActors = localActors;
|
|
}
|
|
|
|
public string Type => "Flag";
|
|
|
|
public async Task Handle(JsonNode activity, ForeignAvatar actor, CancellationToken token)
|
|
{
|
|
var objects = activity["object"] switch
|
|
{
|
|
JsonArray array => array.Select(Id).Where(i => i != default).ToList(),
|
|
JsonNode single when Id(single) is { } id => new List<string> { id },
|
|
_ => new List<string>()
|
|
};
|
|
|
|
LocalActor target = default;
|
|
var postUris = new List<string>();
|
|
foreach (var uri in objects.Take(50))
|
|
{
|
|
var local = await _localActors.FindByUri(uri, token);
|
|
if (local is { Kind: LocalActorKind.Person } && uri.TrimEnd('/') == local.Uri)
|
|
target ??= local;
|
|
else
|
|
postUris.Add(uri);
|
|
}
|
|
var posts = postUris.Count == 0
|
|
? new List<Models.Post.Post>()
|
|
: await _dbEntities.Posts.Match(p => postUris.Contains(p.ObjectURI) && !p.IsFederatedCopy).ExecuteAsync(token);
|
|
if (target == default && posts.Count > 0)
|
|
target = await _localActors.FindById(LocalActorKind.Person, posts[0].GroupUserId, token);
|
|
if (target == default)
|
|
{
|
|
Arrival.Drop("unknown-object");
|
|
return;
|
|
}
|
|
Arrival.Accept("reported");
|
|
|
|
await DB.Default.SaveAsync(new Report
|
|
{
|
|
ReporterActorURI = actor.ActorURI,
|
|
TargetAccountId = target.Id,
|
|
TargetActorURI = target.Uri,
|
|
PostIds = posts.Where(p => p.GroupUserId == target.Id).Select(p => p.ID).ToList(),
|
|
ObjectURIs = posts.Where(p => p.GroupUserId == target.Id).Select(p => p.ObjectURI).ToList(),
|
|
Comment = Value(activity, "content")
|
|
}, token);
|
|
}
|
|
}
|
|
}
|