2026-10-01 11:12:34 +02:00
|
|
|
using MongoDB.Entities;
|
|
|
|
|
|
|
|
|
|
using PrivaPub.Federation.Actors;
|
2026-10-01 18:53:28 +02:00
|
|
|
using PrivaPub.Domain.Statuses;
|
2026-10-01 11:12:34 +02:00
|
|
|
using PrivaPub.Federation.Objects;
|
2026-10-01 12:30:57 +02:00
|
|
|
using PrivaPub.Federation.Outbox;
|
2026-10-01 11:12:34 +02:00
|
|
|
using PrivaPub.Models.Post;
|
|
|
|
|
using PrivaPub.Models.User;
|
|
|
|
|
using PrivaPub.StaticServices;
|
|
|
|
|
|
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
|
|
|
|
|
|
using static PrivaPub.Federation.Objects.ActivityJson;
|
|
|
|
|
|
|
|
|
|
using PostEntity = PrivaPub.Models.Post.Post;
|
|
|
|
|
|
|
|
|
|
namespace PrivaPub.Federation.Inbox.Handlers
|
|
|
|
|
{
|
2026-11-10 01:24:43 +01:00
|
|
|
public class UpdateHandler(
|
|
|
|
|
DbEntities dbEntities,
|
|
|
|
|
ILocalActorService localActors,
|
|
|
|
|
IRemoteActorService remoteActors,
|
|
|
|
|
IGroupDistributor groups,
|
|
|
|
|
IObjectRecords records,
|
|
|
|
|
IQuoteService quotes,
|
|
|
|
|
IDeliveryService delivery = default) : IActivityHandler
|
2026-10-01 11:12:34 +02:00
|
|
|
{
|
|
|
|
|
public string Type => "Update";
|
|
|
|
|
|
|
|
|
|
public async Task Handle(JsonNode activity, ForeignAvatar actor, CancellationToken token)
|
|
|
|
|
{
|
2026-10-01 11:17:14 +02:00
|
|
|
var inner = activity["object"];
|
2026-10-01 11:12:34 +02:00
|
|
|
if (Id(inner) == actor.ActorURI)
|
|
|
|
|
{
|
2026-11-10 01:24:43 +01:00
|
|
|
await remoteActors.GetActor(actor.ActorURI, refresh: true, token);
|
2026-10-03 11:04:42 +02:00
|
|
|
Arrival.Accept("actor-refresh");
|
|
|
|
|
Arrival.About(actor.AvatarType.ToString());
|
2026-10-01 11:12:34 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2026-10-01 11:17:14 +02:00
|
|
|
if (inner is not JsonObject || !Origin.Same(Id(inner), actor.ActorURI))
|
2026-10-03 11:04:42 +02:00
|
|
|
{
|
|
|
|
|
Arrival.Drop("cross-origin");
|
2026-10-01 11:17:14 +02:00
|
|
|
return;
|
2026-10-03 11:04:42 +02:00
|
|
|
}
|
2026-10-01 11:17:14 +02:00
|
|
|
var note = NoteParser.Parse(inner);
|
2026-10-05 10:54:32 +02:00
|
|
|
// edited by another account of the author's own server (Mobilizon's organiser edits the group's event): applied
|
|
|
|
|
// as that server has it now
|
|
|
|
|
if (note != default && note.AttributedTo != actor.ActorURI && Origin.Same(note.AttributedTo, actor.ActorURI))
|
|
|
|
|
{
|
2026-11-10 01:24:43 +01:00
|
|
|
using var fetched = await remoteActors.FetchObject(note.Id, token);
|
2026-10-05 10:54:32 +02:00
|
|
|
var current = fetched == default ? default : NoteParser.Parse(JsonNode.Parse(fetched.Root.GetRawText()));
|
|
|
|
|
if (current == default || current.Id != note.Id || current.AttributedTo != note.AttributedTo)
|
|
|
|
|
{
|
|
|
|
|
Arrival.Drop("fetch-failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
note = current;
|
2026-11-10 01:24:43 +01:00
|
|
|
actor = await remoteActors.GetActor(note.AttributedTo, refresh: false, token);
|
2026-10-05 10:54:32 +02:00
|
|
|
if (actor == default)
|
|
|
|
|
{
|
|
|
|
|
Arrival.Drop("author-unavailable");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-01 11:17:14 +02:00
|
|
|
if (note == default || note.AttributedTo != actor.ActorURI)
|
2026-10-03 11:04:42 +02:00
|
|
|
{
|
|
|
|
|
Arrival.Drop(note == default ? "unparseable" : "misattributed");
|
2026-10-01 11:12:34 +02:00
|
|
|
return;
|
2026-10-03 11:04:42 +02:00
|
|
|
}
|
2026-10-01 11:12:34 +02:00
|
|
|
|
2026-11-10 01:24:43 +01:00
|
|
|
var post = await dbEntities.Posts.Match(p => p.ObjectURI == note.Id && p.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
2026-10-01 11:17:14 +02:00
|
|
|
if (post == default || post.DeletedAt.HasValue)
|
2026-10-03 11:04:42 +02:00
|
|
|
{
|
|
|
|
|
Arrival.Drop("unknown-object");
|
2026-10-01 11:17:14 +02:00
|
|
|
return;
|
2026-10-03 11:04:42 +02:00
|
|
|
}
|
|
|
|
|
Arrival.About(note.Type, post.Visibility, post.CreationDate);
|
2026-10-01 11:17:14 +02:00
|
|
|
|
2026-11-10 01:24:43 +01:00
|
|
|
var edited = await RemoteEdits.Apply(post, note, Id(activity), localActors, records, quotes, token);
|
2026-10-03 11:15:21 +02:00
|
|
|
Arrival.Accept(edited ? "edit" : "refresh");
|
2026-10-05 14:55:20 +02:00
|
|
|
if (edited)
|
2026-11-10 01:24:43 +01:00
|
|
|
await ReplyRelay.Pass(post, dbEntities, localActors, delivery, token);
|
|
|
|
|
if (edited && !string.IsNullOrEmpty(post.GroupId) && await localActors.FindById(Models.Federation.LocalActorKind.Group, post.GroupId, token) is { IsCircle: false } community)
|
|
|
|
|
await groups.Announce(community, activity.AsObject(), post.ObjectURI, isNewPost: false, token);
|
2026-10-01 11:17:14 +02:00
|
|
|
}
|
2026-10-01 11:12:34 +02:00
|
|
|
}
|
|
|
|
|
}
|