A community's moderators lock threads and ban members
Lemmy's moderation reached PrivaPub only as removals. Now a remote
community's lock and ban, relayed in its Announce, apply too:
- a lock (Announce{Lock}, or commentsEnabled false on the post) refuses
replies to the thread, ours included, until Undo{Lock}; statuses say so
in privapub.locked;
- a ban of a persona (Announce{Block} with the community as target, or the
moderator's own Block sent straight to us, which is the community's ban
and never the moderator's block of the persona) shows as blocked_by on
the community and refuses the persona's posts and replies there until
the Undo.
The Lemmy scenario's removal was an expected failure only because it gave
up before Lemmy's 30-second batch; it now waits, and checks the lock and
the ban live (Lemmy refuses a lock or an unban without a reason): 29
checks, none expected to fail. G-0003 and G-0006 are closed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
1 parent
4a9a3d3235
commit
34c0f696af
16 files changed
+231
-20
No files matched your search
@@ -2,6 +2,7 @@ using MongoDB.Driver;
|
||||
using MongoDB.Entities;
|
||||
|
||||
using PrivaPub.Federation.Actors;
|
||||
using PrivaPub.Federation.Objects;
|
||||
using PrivaPub.Models.Federation;
|
||||
using PrivaPub.Models.Social;
|
||||
using PrivaPub.Models.User;
|
||||
@@ -37,6 +38,11 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
Arrival.Drop("unknown-object");
|
||||
return;
|
||||
}
|
||||
if (Community(activity, actor) is { } community)
|
||||
{
|
||||
await Ban(activity, target, community, token);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
await DB.Default.SaveAsync(new BlockedBy { AvatarId = target.Id, ActorURI = actor.ActorURI, AccountId = actor.ID, ActivityURI = Id(activity) }, token);
|
||||
@@ -54,15 +60,44 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
await DB.Default.DeleteAsync<Notification>(n => n.AvatarId == target.Id && n.FromAccountId == actor.ID);
|
||||
}
|
||||
|
||||
// Undo{Block}: the block it names by id, or else the blocker's block of the persona the inner Block names
|
||||
// Lemmy also sends a community's ban to the banned account's own server, as its moderator's Block with the community
|
||||
// as `target`: a ban from that community, as the community's Announce brings it, never the moderator's own block. The
|
||||
// moderator must be on the community's server.
|
||||
static string Community(JsonNode block, ForeignAvatar actor) =>
|
||||
block is JsonObject && Id(block["target"]) is { } community && community != actor.ActorURI && Origin.Same(community, actor.ActorURI)
|
||||
? community
|
||||
: default;
|
||||
|
||||
async Task Ban(JsonNode activity, LocalActor persona, string communityUri, CancellationToken token)
|
||||
{
|
||||
var community = await _dbEntities.ForeignAvatars.Match(f => f.ActorURI == communityUri && f.AvatarType == AvatarType.Group).ExecuteFirstAsync(token);
|
||||
if (community == default)
|
||||
{
|
||||
Arrival.Drop("unknown-community");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
await DB.Default.SaveAsync(new BlockedBy { AvatarId = persona.Id, ActorURI = community.ActorURI, AccountId = community.ID, ActivityURI = Id(activity) }, token);
|
||||
Arrival.Accept("banned");
|
||||
}
|
||||
catch (MongoWriteException ex) when (ex.WriteError?.Category == ServerErrorCategory.DuplicateKey)
|
||||
{
|
||||
Arrival.Drop("duplicate");
|
||||
}
|
||||
}
|
||||
|
||||
// Undo{Block}: the block it names by id, or else the blocker's block of the persona the inner Block names; a
|
||||
// community's ban sent by its moderator is the community's
|
||||
public static async Task<bool> Undo(JsonNode inner, string innerId, ForeignAvatar actor, ILocalActorService localActors, CancellationToken token)
|
||||
{
|
||||
var by = Community(inner, actor) ?? actor.ActorURI;
|
||||
var block = innerId == default
|
||||
? default
|
||||
: await DB.Default.Find<BlockedBy>().Match(b => b.ActivityURI == innerId && b.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
: await DB.Default.Find<BlockedBy>().Match(b => b.ActivityURI == innerId && b.ActorURI == by).ExecuteFirstAsync(token);
|
||||
if (block == default && inner is JsonObject && Id(inner["object"]) is { } objectUri
|
||||
&& await localActors.FindByUri(objectUri, token) is { Kind: LocalActorKind.Person } persona)
|
||||
block = await DB.Default.Find<BlockedBy>().Match(b => b.AvatarId == persona.Id && b.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
block = await DB.Default.Find<BlockedBy>().Match(b => b.AvatarId == persona.Id && b.ActorURI == by).ExecuteFirstAsync(token);
|
||||
if (block == default)
|
||||
return false;
|
||||
await DB.Default.DeleteAsync<BlockedBy>(block.ID);
|
||||
|
||||
Reference in new issue
Block a user