💄 Optimize Like activity delivery
This commit is contained in:
@@ -341,7 +341,8 @@ public class ActivityPubDeliveryService(
|
|||||||
|
|
||||||
public async Task<bool> SendLikeActivityToLocalPostAsync(
|
public async Task<bool> SendLikeActivityToLocalPostAsync(
|
||||||
SnFediverseActor actor,
|
SnFediverseActor actor,
|
||||||
Guid postId
|
Guid postId,
|
||||||
|
SnFediverseActor postSenderActor
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var actorUrl = actor.Uri;
|
var actorUrl = actor.Uri;
|
||||||
@@ -356,12 +357,13 @@ public class ActivityPubDeliveryService(
|
|||||||
["actor"] = actor.Uri,
|
["actor"] = actor.Uri,
|
||||||
["object"] = postUrl,
|
["object"] = postUrl,
|
||||||
["to"] = new[] { "https://www.w3.org/ns/activitystreams#Public" },
|
["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 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;
|
if (follower.InboxUri == null) continue;
|
||||||
await EnqueueActivityDeliveryAsync("Like", activity, actorUrl, follower.InboxUri, activityId);
|
await EnqueueActivityDeliveryAsync("Like", activity, actorUrl, follower.InboxUri, activityId);
|
||||||
@@ -372,7 +374,8 @@ public class ActivityPubDeliveryService(
|
|||||||
|
|
||||||
public async Task<bool> SendUndoLikeActivityAsync(
|
public async Task<bool> SendUndoLikeActivityAsync(
|
||||||
SnFediverseActor actor,
|
SnFediverseActor actor,
|
||||||
Guid postId
|
Guid postId,
|
||||||
|
SnFediverseActor postSenderActor
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var actorUrl = actor.Uri;
|
var actorUrl = actor.Uri;
|
||||||
@@ -391,12 +394,13 @@ public class ActivityPubDeliveryService(
|
|||||||
["object"] = postUrl
|
["object"] = postUrl
|
||||||
},
|
},
|
||||||
["to"] = new[] { "https://www.w3.org/ns/activitystreams#Public" },
|
["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 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;
|
if (follower.InboxUri == null) continue;
|
||||||
await EnqueueActivityDeliveryAsync("Undo", activity, actorUrl, follower.InboxUri, activityId);
|
await EnqueueActivityDeliveryAsync("Undo", activity, actorUrl, follower.InboxUri, activityId);
|
||||||
|
|||||||
@@ -647,8 +647,9 @@ public partial class PostService(
|
|||||||
var accountActor = accountPublisher is null
|
var accountActor = accountPublisher is null
|
||||||
? null
|
? null
|
||||||
: await objFactory.GetLocalActorAsync(accountPublisher.Id);
|
: 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)
|
if (!isRemoving)
|
||||||
{
|
{
|
||||||
@@ -662,7 +663,8 @@ public partial class PostService(
|
|||||||
.GetRequiredService<ActivityPubDeliveryService>();
|
.GetRequiredService<ActivityPubDeliveryService>();
|
||||||
await deliveryService.SendLikeActivityToLocalPostAsync(
|
await deliveryService.SendLikeActivityToLocalPostAsync(
|
||||||
accountActor,
|
accountActor,
|
||||||
post.Id
|
post.Id,
|
||||||
|
publisherActor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -683,7 +685,8 @@ public partial class PostService(
|
|||||||
.GetRequiredService<ActivityPubDeliveryService>();
|
.GetRequiredService<ActivityPubDeliveryService>();
|
||||||
await deliveryService.SendUndoLikeActivityAsync(
|
await deliveryService.SendUndoLikeActivityAsync(
|
||||||
accountActor,
|
accountActor,
|
||||||
post.Id
|
post.Id,
|
||||||
|
publisherActor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user