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
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -27,11 +27,20 @@ class SchedulerController extends Controller

        // Send activity to all followers
        foreach ($scheduledActivities as $scheduledActivity) {
            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')
+1 −1
Original line number Diff line number Diff line
@@ -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
+20 −8
Original line number Diff line number Diff line
@@ -97,16 +97,17 @@ if (! function_exists('accept_follow')) {
    }
}

if (! function_exists('send_activity_to_followers')) {
if (! function_exists('send_activity_to_actor')) {
    /**
     * Sends an activity to all actor followers
     */
    function send_activity_to_followers(Actor $actor, string $activityPayload): void
    function send_activity_to_actor(Actor $actor, Actor $targetActor, string $activityPayload): void
    {
        foreach ($actor->followers as $follower) {
        try {
                $acceptRequest = new ActivityRequest($follower->inbox_url, $activityPayload);
            $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
@@ -114,6 +115,17 @@ if (! function_exists('send_activity_to_followers')) {
        }
    }
}

if (! function_exists('send_activity_to_followers')) {
    /**
     * Sends an activity to all actor followers
     */
    function send_activity_to_followers(Actor $actor, string $activityPayload): void
    {
        foreach ($actor->followers as $follower) {
            send_activity_to_actor($actor, $follower, $activityPayload);
        }
    }
}

if (! function_exists('extract_urls_from_message')) {
+2 −2
Original line number Diff line number Diff line
@@ -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,
+2 −2
Original line number Diff line number Diff line
@@ -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(),