2026-10-05 22:48:57 +02:00
|
|
|
using PrivaPub.Federation.Actors;
|
|
|
|
|
using PrivaPub.Models.User;
|
|
|
|
|
|
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
|
|
|
|
|
|
namespace PrivaPub.Federation.Inbox.Handlers
|
|
|
|
|
{
|
|
|
|
|
// An account pins one of its posts (Add to its `featured` collection) or unpins it (Remove), as Mastodon and Akkoma
|
2026-10-18 08:38:11 +02:00
|
|
|
// send it; inside a community's announce, the community features a post made in it. A Hashtag added to or removed from
|
|
|
|
|
// its `featured` collection (as Mastodon sends it) or its `featuredTags` is a featured tag (R8). On its wall
|
|
|
|
|
// (Smithereen's, FEP-400e) it tells of a post someone wrote there, or takes it off. Any other target (a community's
|
|
|
|
|
// moderators) is not ours to keep.
|
2026-11-10 01:24:43 +01:00
|
|
|
public class FeaturedHandler(
|
|
|
|
|
IFeaturedPosts featuredPosts,
|
|
|
|
|
bool add,
|
|
|
|
|
IWalls walls = default,
|
|
|
|
|
IRemoteActorService remoteActors = default,
|
|
|
|
|
Infrastructure.Jobs.IJobQueue queue = default,
|
|
|
|
|
Domain.Social.IFeaturedTags tags = default) : IActivityHandler
|
2026-10-05 22:48:57 +02:00
|
|
|
{
|
2026-11-10 01:24:43 +01:00
|
|
|
public string Type => add ? "Add" : "Remove";
|
2026-10-05 22:48:57 +02:00
|
|
|
|
2026-10-06 08:17:10 +02:00
|
|
|
public async Task Handle(JsonNode activity, ForeignAvatar actor, CancellationToken token)
|
|
|
|
|
{
|
2026-11-10 01:24:43 +01:00
|
|
|
if (add && queue != default && await ConversationContainers.Unwrap(activity, actor, queue, token))
|
2026-10-06 10:03:44 +02:00
|
|
|
return;
|
2026-10-06 08:17:10 +02:00
|
|
|
var target = Objects.ActivityJson.Id(activity["target"]);
|
|
|
|
|
// a collection of its own we do not know of: its document read again, at most hourly, in case it was kept before
|
|
|
|
|
// we read that collection (a wall)
|
2026-11-10 01:24:43 +01:00
|
|
|
if (remoteActors != default && target != default && target != actor.FeaturedURL && target != actor.WallURL && target != actor.FeaturedTagsURL
|
2026-10-06 08:17:10 +02:00
|
|
|
&& Objects.Origin.Same(target, actor.ActorURI) && actor.UpdatedAt < DateTime.UtcNow.AddHours(-1))
|
2026-11-10 01:24:43 +01:00
|
|
|
actor = await remoteActors.GetActor(actor.ActorURI, refresh: true, token) ?? actor;
|
2026-10-18 08:38:11 +02:00
|
|
|
// a featured hashtag: an object of its own, with no id (its href is no post), so before anything reads it as one
|
|
|
|
|
if (Objects.ActivityJson.Value(activity["object"], "type") == "Hashtag")
|
|
|
|
|
{
|
2026-11-10 01:24:43 +01:00
|
|
|
if (tags != default && target != default && (target == actor.FeaturedURL || target == actor.FeaturedTagsURL))
|
|
|
|
|
await tags.Receive(activity, actor, add, token);
|
2026-10-18 08:38:11 +02:00
|
|
|
else
|
|
|
|
|
Arrival.Drop("unknown-target");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-11-10 01:24:43 +01:00
|
|
|
if (walls != default && !string.IsNullOrEmpty(actor.WallURL) && target == actor.WallURL)
|
|
|
|
|
await walls.Receive(activity, actor, add, token);
|
2026-10-06 08:17:10 +02:00
|
|
|
else
|
2026-11-10 01:24:43 +01:00
|
|
|
await featuredPosts.Receive(activity, actor, add, token);
|
2026-10-06 08:17:10 +02:00
|
|
|
}
|
2026-10-05 22:48:57 +02:00
|
|
|
}
|
|
|
|
|
}
|