Likes and boosts arrive, count, notify, and can be taken back
- Like: a Favourite per account and post (unique), the post's counter, a Favourite notification for a local author; only on posts the liker could see (public and unlisted, or followers-only and direct when they were addressed). - Announce: the original is always refetched from its own origin (or is ours), and must be public or unlisted. A boost of a local post counts and notifies; a boost by an account a persona follows is stored as a reblog row and fanned out to its followers' home timelines (as a reblog, where reblogs are wanted). A boost by a stranger of a stranger's post is ignored. FEP-1b12 group announces of activities wait for P4. - Undo of a Like or an Announce reverses each of them; an Undo naming only an id is matched against follows, likes and boosts in turn. 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
e99b76dbd7
commit
b34c71775c
7 files changed
+351
-22
No files matched your search
@@ -1,12 +1,8 @@
|
||||
using MongoDB.Entities;
|
||||
|
||||
using PrivaPub.Federation.Actors;
|
||||
using PrivaPub.Federation.Objects;
|
||||
using PrivaPub.Federation.Outbox;
|
||||
using PrivaPub.Federation.Rendering;
|
||||
using PrivaPub.Models.Federation;
|
||||
using PrivaPub.Models.Group;
|
||||
using PrivaPub.Models.Post;
|
||||
using PrivaPub.Models.Social;
|
||||
using PrivaPub.Models.User;
|
||||
using PrivaPub.StaticServices;
|
||||
|
||||
@@ -23,38 +19,37 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
{
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly IRemoteActorService _remoteActors;
|
||||
readonly IDeliveryService _delivery;
|
||||
|
||||
public UndoHandler(DbEntities dbEntities, ILocalActorService localActors, IRemoteActorService remoteActors, IDeliveryService delivery)
|
||||
public UndoHandler(DbEntities dbEntities, ILocalActorService localActors)
|
||||
{
|
||||
_dbEntities = dbEntities;
|
||||
_localActors = localActors;
|
||||
_remoteActors = remoteActors;
|
||||
_delivery = delivery;
|
||||
}
|
||||
|
||||
public string Type => "Undo";
|
||||
|
||||
public async Task Handle(JsonNode activity, ForeignAvatar actor, CancellationToken token)
|
||||
{
|
||||
var undo = activity;
|
||||
|
||||
var inner = undo["object"];
|
||||
var inner = activity["object"];
|
||||
var innerType = inner is JsonObject ? Value(inner, "type") : default;
|
||||
var innerId = Id(inner);
|
||||
|
||||
if (inner is JsonObject && Id(inner["actor"]) != actor.ActorURI)
|
||||
return;
|
||||
if (innerType is not (null or "Follow"))
|
||||
return;
|
||||
if (innerType is null or "Follow")
|
||||
await UndoFollow(inner, innerId, actor, token);
|
||||
if (innerType is null or "Like")
|
||||
await UndoLike(inner, innerId, actor, token);
|
||||
if (innerType is null or "Announce")
|
||||
await UndoAnnounce(innerId, actor, token);
|
||||
}
|
||||
|
||||
async Task UndoFollow(JsonNode inner, string innerId, ForeignAvatar actor, CancellationToken token)
|
||||
{
|
||||
var followers = await _dbEntities.Followers.Match(f => f.ActorURI == actor.ActorURI).ExecuteAsync(token);
|
||||
var targetUri = inner is JsonObject ? Id(inner["object"]) : default;
|
||||
var target = targetUri == default ? default : await _localActors.FindByUri(targetUri, token);
|
||||
foreach (var follower in followers)
|
||||
{
|
||||
var matchesActivity = innerId != default && follower.FollowActivityURI == innerId;
|
||||
var target = targetUri == default ? default : await _localActors.FindByUri(targetUri, token);
|
||||
var matchesTarget = target != default && target.Id == follower.LocalActorId && target.Kind == follower.LocalActorKind;
|
||||
if (!matchesActivity && !matchesTarget)
|
||||
continue;
|
||||
@@ -63,7 +58,38 @@ namespace PrivaPub.Federation.Inbox.Handlers
|
||||
if (follower.LocalActorKind == LocalActorKind.Group)
|
||||
await RemoveForeignMember(follower.LocalActorId, actor.ActorURI, token);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async Task UndoLike(JsonNode inner, string innerId, ForeignAvatar actor, CancellationToken token)
|
||||
{
|
||||
var favourite = innerId == default
|
||||
? default
|
||||
: await _dbEntities.Favourites.Match(f => f.ActivityURI == innerId && f.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
if (favourite == default && inner is JsonObject && Id(inner["object"]) is { } objectUri)
|
||||
{
|
||||
var post = await _dbEntities.Posts.Match(p => p.ObjectURI == objectUri).ExecuteFirstAsync(token);
|
||||
favourite = post == default
|
||||
? default
|
||||
: await _dbEntities.Favourites.Match(f => f.PostId == post.ID && f.ActorURI == actor.ActorURI).ExecuteFirstAsync(token);
|
||||
}
|
||||
if (favourite == default)
|
||||
return;
|
||||
await DB.Default.DeleteAsync<Favourite>(favourite.ID);
|
||||
await DB.Default.Update<PostEntity>().MatchID(favourite.PostId).Modify(b => b.Inc(p => p.FavouritesCount, -1)).ExecuteAsync(token);
|
||||
}
|
||||
|
||||
async Task UndoAnnounce(string innerId, ForeignAvatar actor, CancellationToken token)
|
||||
{
|
||||
if (innerId == default)
|
||||
return;
|
||||
var reblog = await _dbEntities.Posts
|
||||
.Match(p => p.ObjectURI == innerId && p.ActorURI == actor.ActorURI && p.ReblogOfPostId != null)
|
||||
.ExecuteFirstAsync(token);
|
||||
if (reblog == default)
|
||||
return;
|
||||
await DB.Default.DeleteAsync<PostEntity>(reblog.ID);
|
||||
await DB.Default.DeleteAsync<TimelineEntry>(e => e.PostId == reblog.ID);
|
||||
await DB.Default.Update<PostEntity>().MatchID(reblog.ReblogOfPostId).Modify(b => b.Inc(p => p.ReblogsCount, -1)).ExecuteAsync(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user