From 5990c090dcd8aa76862cfc65405338ce75d73a78 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 18 Oct 2023 12:42:37 +0200 Subject: [PATCH] schedule Accept Activity --- includes/class-activity-dispatcher.php | 16 ++++++++++++++++ includes/collection/class-followers.php | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/includes/class-activity-dispatcher.php b/includes/class-activity-dispatcher.php index 462a75a..d3c1203 100644 --- a/includes/class-activity-dispatcher.php +++ b/includes/class-activity-dispatcher.php @@ -2,6 +2,7 @@ namespace Activitypub; use WP_Post; +use Activitypub\Http; use Activitypub\Activity\Activity; use Activitypub\Collection\Users; use Activitypub\Collection\Followers; @@ -25,6 +26,8 @@ class Activity_Dispatcher { public static function init() { \add_action( 'activitypub_send_activity', array( self::class, 'send_activity' ), 10, 2 ); \add_action( 'activitypub_send_activity', array( self::class, 'send_activity_or_announce' ), 10, 2 ); + + \add_action( 'activitypub_send_accept_activity', array( self::class, 'send_accept_activity' ), 10, 3 ); } /** @@ -122,4 +125,17 @@ class Activity_Dispatcher { safe_remote_post( $inbox, $json, $wp_post->post_author ); } } + + /** + * Send Accept Activities. + * + * @param string $inbox The inbox url. + * @param array $activity The Activity Array + * @param int $user_id The user id. + * + * @return void + */ + public static function send_accept_activity( $inbox, $activity, $user_id ) { + Http::post( $inbox, $activity, $user_id ); + } } diff --git a/includes/collection/class-followers.php b/includes/collection/class-followers.php index a9fe298..e1425f4 100644 --- a/includes/collection/class-followers.php +++ b/includes/collection/class-followers.php @@ -294,6 +294,18 @@ class Followers { $activity = $activity->to_json(); + // schedule Accept Activity so that we can get sure it will be sent... + \wp_schedule_single_event( + \strtotime( '+60 seconds' ), + 'activitypub_send_accept_activity', + array( + $inbox, + $activity, + $user_id, + ) + ); + + // ...and send it directly Http::post( $inbox, $activity, $user_id ); }