💄 Optimize Like activity delivery

This commit is contained in:
2026-01-03 01:43:16 +08:00
parent 1596897a5b
commit 82b517ed2c
2 changed files with 16 additions and 9 deletions

View File

@@ -341,7 +341,8 @@ public class ActivityPubDeliveryService(
public async Task<bool> SendLikeActivityToLocalPostAsync(
SnFediverseActor actor,
Guid postId
Guid postId,
SnFediverseActor postSenderActor
)
{
var actorUrl = actor.Uri;
@@ -356,12 +357,13 @@ public class ActivityPubDeliveryService(
["actor"] = actor.Uri,
["object"] = postUrl,
["to"] = new[] { "https://www.w3.org/ns/activitystreams#Public" },
["cc"] = new[] { $"{actorUrl}/followers" }
["cc"] = new[] { $"{actorUrl}/followers", postSenderActor.Uri, postSenderActor.FollowersUri }
};
var followers = await GetRemoteFollowersAsync(actor.Id);
var ogFollowers = await GetRemoteFollowersAsync(postSenderActor.Id);
foreach (var follower in followers)
foreach (var follower in followers.Concat(ogFollowers))
{
if (follower.InboxUri == null) continue;
await EnqueueActivityDeliveryAsync("Like", activity, actorUrl, follower.InboxUri, activityId);
@@ -372,7 +374,8 @@ public class ActivityPubDeliveryService(
public async Task<bool> SendUndoLikeActivityAsync(
SnFediverseActor actor,
Guid postId
Guid postId,
SnFediverseActor postSenderActor
)
{
var actorUrl = actor.Uri;
@@ -391,12 +394,13 @@ public class ActivityPubDeliveryService(
["object"] = postUrl
},
["to"] = new[] { "https://www.w3.org/ns/activitystreams#Public" },
["cc"] = new[] { $"{actorUrl}/followers" }
["cc"] = new[] { $"{actorUrl}/followers", postSenderActor.Uri, postSenderActor.FollowersUri }
};
var followers = await GetRemoteFollowersAsync(actor.Id);
var ogFollowers = await GetRemoteFollowersAsync(postSenderActor.Id);
foreach (var follower in followers)
foreach (var follower in followers.Concat(ogFollowers))
{
if (follower.InboxUri == null) continue;
await EnqueueActivityDeliveryAsync("Undo", activity, actorUrl, follower.InboxUri, activityId);

View File

@@ -647,8 +647,9 @@ public partial class PostService(
var accountActor = accountPublisher is null
? null
: await objFactory.GetLocalActorAsync(accountPublisher.Id);
var publisherActor = await objFactory.GetLocalActorAsync(post.PublisherId.Value);
if (accountActor != null && reaction.Attitude == Shared.Models.PostReactionAttitude.Positive)
if (accountActor != null && publisherActor != null && reaction.Attitude == Shared.Models.PostReactionAttitude.Positive)
{
if (!isRemoving)
{
@@ -662,7 +663,8 @@ public partial class PostService(
.GetRequiredService<ActivityPubDeliveryService>();
await deliveryService.SendLikeActivityToLocalPostAsync(
accountActor,
post.Id
post.Id,
publisherActor
);
}
catch (Exception ex)
@@ -683,7 +685,8 @@ public partial class PostService(
.GetRequiredService<ActivityPubDeliveryService>();
await deliveryService.SendUndoLikeActivityAsync(
accountActor,
post.Id
post.Id,
publisherActor
);
}
catch (Exception ex)