Communities follow FEP-1b12, circles federate to their members only
Communities: - a post addressed to a community (to, cc or audience) is accepted according to its posting policy - followers, anyone, or moderators - and GroupDistributor announces the whole activity with `audience` to the community's followers, plus the object for new posts so Mastodon shows them; updates and deletes of community content are announced too; - top-level posts are Pages with a name (the title, or a headline from the text); /flock counts members, /wardens lists moderators; - a Mastodon client posts into a community by mentioning it, or into a remote group, which sets `audience`; - an Announce of an activity from a remote group a persona follows (Lemmy) is followed through: the object is fetched from its own origin, kept with its AudienceURI, and fanned out to the group's local followers; updates are applied in place and deletes checked against the origin. Circles stop being local-only: an undiscoverable Group actor whose follows are all requests the owner approves; posts addressed to the circle and its /flock and delivered to members' own inboxes, never announced, never public; a remote member's post into the circle is accepted from members only. SignedFetchAuthorizer serves circle posts and collections only to a signed request from a member or a member server's instance actor - 404 for anyone else. Circles never surface in search, lookups, mentions, account ids or profile pages. Federation:SecureMode requires a valid signature on every GET under /peasants except the instance actor. Group forms take a posting policy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012CzABvBkbcFqoHdmi8b9WB
This commit is contained in:
1 parent
0ccbcd558f
commit
a5d9a89445
32 files changed
+652
-58
No files matched your search
@@ -26,9 +26,11 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly IRemotePosts _remotePosts;
|
||||
readonly IFanout _fanout;
|
||||
readonly IRemoteActorService _remoteActors;
|
||||
|
||||
public AnnounceHandler(DbEntities dbEntities, ILocalActorService localActors, IRemotePosts remotePosts, IFanout fanout)
|
||||
public AnnounceHandler(DbEntities dbEntities, ILocalActorService localActors, IRemotePosts remotePosts, IFanout fanout, IRemoteActorService remoteActors)
|
||||
{
|
||||
_remoteActors = remoteActors;
|
||||
_dbEntities = dbEntities;
|
||||
_localActors = localActors;
|
||||
_remotePosts = remotePosts;
|
||||
@@ -41,7 +43,10 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
{
|
||||
var inner = activity["object"];
|
||||
if (inner is JsonObject && Value(inner, "type") is "Create" or "Update" or "Delete" or "Like" or "Dislike" or "Undo" or "Add" or "Remove" or "Block")
|
||||
{
|
||||
await GroupActivity(inner, actor, token);
|
||||
return;
|
||||
}
|
||||
var objectUri = Id(inner);
|
||||
var announceId = Id(activity);
|
||||
if (objectUri == default || announceId == default)
|
||||
@@ -96,6 +101,66 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
await _fanout.Distribute(reblog, token);
|
||||
}
|
||||
|
||||
async Task GroupActivity(JsonNode inner, ForeignAvatar group, CancellationToken token)
|
||||
{
|
||||
if (group.AvatarType != AvatarType.Group
|
||||
|| !await _dbEntities.Followings.Match(f => f.TargetActorURI == group.ActorURI && f.State == FollowState.Accepted).ExecuteAnyAsync(token))
|
||||
return;
|
||||
var objectUri = Id(inner["object"]);
|
||||
switch (Value(inner, "type"))
|
||||
{
|
||||
case "Create" when objectUri != default:
|
||||
if (await _dbEntities.Posts.Match(p => p.ObjectURI == objectUri).ExecuteAnyAsync(token))
|
||||
return;
|
||||
var post = await _remotePosts.StoreContext(objectUri, 0, token);
|
||||
if (post == default)
|
||||
return;
|
||||
await DB.Default.Update<PostEntity>().MatchID(post.ID).Modify(p => p.AudienceURI, group.ActorURI).ExecuteAsync(token);
|
||||
post.AudienceURI = group.ActorURI;
|
||||
await _fanout.Distribute(post, token);
|
||||
break;
|
||||
case "Update" when objectUri != default:
|
||||
var stored = await _dbEntities.Posts.Match(p => p.ObjectURI == objectUri && p.AudienceURI == group.ActorURI && !p.DeletedAt.HasValue)
|
||||
.ExecuteFirstAsync(token);
|
||||
if (stored == default)
|
||||
return;
|
||||
using (var fetched = await _remoteActors.FetchObject(objectUri, token))
|
||||
{
|
||||
var note = fetched == default ? default : NoteParser.Parse(System.Text.Json.Nodes.JsonNode.Parse(fetched.Root.GetRawText()));
|
||||
if (note == default || note.AttributedTo != stored.ActorURI)
|
||||
return;
|
||||
stored.Revisions.Add(new PostRevision
|
||||
{
|
||||
Title = stored.Title,
|
||||
SpoilerText = stored.SpoilerText,
|
||||
ContentHtml = stored.ContentHtml,
|
||||
HasContentWarning = stored.HasContentWarning,
|
||||
EditedAt = stored.EditedAt ?? stored.CreationDate
|
||||
});
|
||||
stored.Title = note.Title;
|
||||
stored.SpoilerText = note.SpoilerText;
|
||||
stored.HasContentWarning = note.Sensitive;
|
||||
stored.Text = note.ContentHtml;
|
||||
stored.ContentHtml = note.ContentHtml;
|
||||
stored.Tags = note.Tags.ToList();
|
||||
stored.Media = note.Attachments.ToList();
|
||||
stored.EditedAt = note.Updated ?? DateTime.UtcNow;
|
||||
await DB.Default.SaveAsync(stored, token);
|
||||
}
|
||||
break;
|
||||
case "Delete" when objectUri != default:
|
||||
var deleted = await _dbEntities.Posts.Match(p => p.ObjectURI == objectUri && p.AudienceURI == group.ActorURI).ExecuteFirstAsync(token);
|
||||
if (deleted == default)
|
||||
return;
|
||||
using (var check = await _remoteActors.FetchObject(objectUri, token))
|
||||
if (check != default && Value(System.Text.Json.Nodes.JsonNode.Parse(check.Root.GetRawText()), "type") != "Tombstone")
|
||||
return;
|
||||
await DB.Default.DeleteAsync<PostEntity>(deleted.ID);
|
||||
await DB.Default.DeleteAsync<TimelineEntry>(e => e.PostId == deleted.ID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static List<string> Strings(JsonNode node) => node switch
|
||||
{
|
||||
JsonArray array => array.Select(Id).Where(id => id != default).ToList(),
|
||||
|
||||
Reference in new issue
Block a user