Skip to content
Snippets Groups Projects
Commit 962dd305 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(activitypub): add target actor id to like / announce activities to send...

fix(activitypub): add target actor id to like / announce activities to send directly to note's actor
parent 9c4f60e0
No related branches found
No related tags found
No related merge requests found
...@@ -27,11 +27,20 @@ class SchedulerController extends Controller ...@@ -27,11 +27,20 @@ class SchedulerController extends Controller
// Send activity to all followers // Send activity to all followers
foreach ($scheduledActivities as $scheduledActivity) { foreach ($scheduledActivities as $scheduledActivity) {
// send activity to all actor followers if ($scheduledActivity->target_actor_id !== null) {
send_activity_to_followers( // send activity to targeted actor
$scheduledActivity->actor, send_activity_to_actor(
json_encode($scheduledActivity->payload, JSON_THROW_ON_ERROR), $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 // set activity post to delivered
model('ActivityModel') model('ActivityModel')
......
...@@ -22,7 +22,7 @@ use RuntimeException; ...@@ -22,7 +22,7 @@ use RuntimeException;
* @property string|null $summary * @property string|null $summary
* @property string|null $private_key * @property string|null $private_key
* @property string|null $public_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_url
* @property string|null $avatar_image_mimetype * @property string|null $avatar_image_mimetype
* @property string|null $cover_image_url * @property string|null $cover_image_url
......
...@@ -97,6 +97,25 @@ if (! function_exists('accept_follow')) { ...@@ -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')) { if (! function_exists('send_activity_to_followers')) {
/** /**
* Sends an activity to all actor followers * Sends an activity to all actor followers
...@@ -104,14 +123,7 @@ if (! function_exists('send_activity_to_followers')) { ...@@ -104,14 +123,7 @@ if (! function_exists('send_activity_to_followers')) {
function send_activity_to_followers(Actor $actor, string $activityPayload): void function send_activity_to_followers(Actor $actor, string $activityPayload): void
{ {
foreach ($actor->followers as $follower) { foreach ($actor->followers as $follower) {
try { send_activity_to_actor($actor, $follower, $activityPayload);
$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());
}
} }
} }
} }
......
...@@ -68,7 +68,7 @@ class FavouriteModel extends BaseUuidModel ...@@ -68,7 +68,7 @@ class FavouriteModel extends BaseUuidModel
->newActivity( ->newActivity(
'Like', 'Like',
$actor->id, $actor->id,
null, $post->actor_id,
$post->id, $post->id,
$likeActivity->toJSON(), $likeActivity->toJSON(),
$post->published_at, $post->published_at,
...@@ -134,7 +134,7 @@ class FavouriteModel extends BaseUuidModel ...@@ -134,7 +134,7 @@ class FavouriteModel extends BaseUuidModel
->newActivity( ->newActivity(
'Undo', 'Undo',
$actor->id, $actor->id,
null, $post->actor_id,
$post->id, $post->id,
$undoActivity->toJSON(), $undoActivity->toJSON(),
$post->published_at, $post->published_at,
......
...@@ -499,7 +499,7 @@ class PostModel extends BaseUuidModel ...@@ -499,7 +499,7 @@ class PostModel extends BaseUuidModel
->newActivity( ->newActivity(
'Announce', 'Announce',
$actor->id, $actor->id,
null, $post->actor_id,
$post->id, $post->id,
$announceActivity->toJSON(), $announceActivity->toJSON(),
$reblog->published_at, $reblog->published_at,
...@@ -559,7 +559,7 @@ class PostModel extends BaseUuidModel ...@@ -559,7 +559,7 @@ class PostModel extends BaseUuidModel
->newActivity( ->newActivity(
'Undo', 'Undo',
$reblogPost->actor_id, $reblogPost->actor_id,
null, $reblogPost->reblog_of_post->actor_id,
$reblogPost->reblog_of_id, $reblogPost->reblog_of_id,
$undoActivity->toJSON(), $undoActivity->toJSON(),
Time::now(), Time::now(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment