mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-06 18:31:05 +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
|
// Send activity to all followers
|
||||||
foreach ($scheduledActivities as $scheduledActivity) {
|
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 all actor followers
|
||||||
send_activity_to_followers(
|
send_activity_to_followers(
|
||||||
$scheduledActivity->actor,
|
$scheduledActivity->actor,
|
||||||
json_encode($scheduledActivity->payload, JSON_THROW_ON_ERROR),
|
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;
|
|||||||
* @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')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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')) {
|
|||||||
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
|
|||||||
->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
|
|||||||
->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
|
|||||||
->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
|
|||||||
->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(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user