mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-19 13:01:19 +00:00
fix(activitypub): add target actor id to like / announce activities to send directly to note's actor
This commit is contained in:
parent
9c4f60e00b
commit
962dd305f5
@ -27,11 +27,20 @@ class SchedulerController extends Controller
|
||||
|
||||
// Send activity to all followers
|
||||
foreach ($scheduledActivities as $scheduledActivity) {
|
||||
// send activity to all actor followers
|
||||
send_activity_to_followers(
|
||||
$scheduledActivity->actor,
|
||||
json_encode($scheduledActivity->payload, JSON_THROW_ON_ERROR),
|
||||
);
|
||||
if ($scheduledActivity->target_actor_id !== null) {
|
||||
// send activity to targeted actor
|
||||
send_activity_to_actor(
|
||||
$scheduledActivity->actor,
|
||||
$scheduledActivity->targetActor,
|
||||
json_encode($scheduledActivity->payload, JSON_THROW_ON_ERROR)
|
||||
);
|
||||
} else {
|
||||
// send activity to all actor followers
|
||||
send_activity_to_followers(
|
||||
$scheduledActivity->actor,
|
||||
json_encode($scheduledActivity->payload, JSON_THROW_ON_ERROR),
|
||||
);
|
||||
}
|
||||
|
||||
// set activity post to delivered
|
||||
model('ActivityModel')
|
||||
|
@ -22,7 +22,7 @@ use RuntimeException;
|
||||
* @property string|null $summary
|
||||
* @property string|null $private_key
|
||||
* @property string|null $public_key
|
||||
* @property string|null $public_key_id
|
||||
* @property string $public_key_id
|
||||
* @property string|null $avatar_image_url
|
||||
* @property string|null $avatar_image_mimetype
|
||||
* @property string|null $cover_image_url
|
||||
|
@ -97,6 +97,25 @@ if (! function_exists('accept_follow')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('send_activity_to_actor')) {
|
||||
/**
|
||||
* Sends an activity to all actor followers
|
||||
*/
|
||||
function send_activity_to_actor(Actor $actor, Actor $targetActor, string $activityPayload): void
|
||||
{
|
||||
try {
|
||||
$acceptRequest = new ActivityRequest($targetActor->inbox_url, $activityPayload);
|
||||
if ($actor->private_key !== null) {
|
||||
$acceptRequest->sign($actor->public_key_id, $actor->private_key);
|
||||
}
|
||||
$acceptRequest->post();
|
||||
} catch (Exception $exception) {
|
||||
// log error
|
||||
log_message('critical', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('send_activity_to_followers')) {
|
||||
/**
|
||||
* Sends an activity to all actor followers
|
||||
@ -104,14 +123,7 @@ if (! function_exists('send_activity_to_followers')) {
|
||||
function send_activity_to_followers(Actor $actor, string $activityPayload): void
|
||||
{
|
||||
foreach ($actor->followers as $follower) {
|
||||
try {
|
||||
$acceptRequest = new ActivityRequest($follower->inbox_url, $activityPayload);
|
||||
$acceptRequest->sign($actor->public_key_id, $actor->private_key);
|
||||
$acceptRequest->post();
|
||||
} catch (Exception $exception) {
|
||||
// log error
|
||||
log_message('critical', $exception->getMessage());
|
||||
}
|
||||
send_activity_to_actor($actor, $follower, $activityPayload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class FavouriteModel extends BaseUuidModel
|
||||
->newActivity(
|
||||
'Like',
|
||||
$actor->id,
|
||||
null,
|
||||
$post->actor_id,
|
||||
$post->id,
|
||||
$likeActivity->toJSON(),
|
||||
$post->published_at,
|
||||
@ -134,7 +134,7 @@ class FavouriteModel extends BaseUuidModel
|
||||
->newActivity(
|
||||
'Undo',
|
||||
$actor->id,
|
||||
null,
|
||||
$post->actor_id,
|
||||
$post->id,
|
||||
$undoActivity->toJSON(),
|
||||
$post->published_at,
|
||||
|
@ -499,7 +499,7 @@ class PostModel extends BaseUuidModel
|
||||
->newActivity(
|
||||
'Announce',
|
||||
$actor->id,
|
||||
null,
|
||||
$post->actor_id,
|
||||
$post->id,
|
||||
$announceActivity->toJSON(),
|
||||
$reblog->published_at,
|
||||
@ -559,7 +559,7 @@ class PostModel extends BaseUuidModel
|
||||
->newActivity(
|
||||
'Undo',
|
||||
$reblogPost->actor_id,
|
||||
null,
|
||||
$reblogPost->reblog_of_post->actor_id,
|
||||
$reblogPost->reblog_of_id,
|
||||
$undoActivity->toJSON(),
|
||||
Time::now(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user