schedule Accept Activity

This commit is contained in:
Matthias Pfefferle 2023-10-18 12:42:37 +02:00
parent e6bb085354
commit 5990c090dc
2 changed files with 28 additions and 0 deletions

View file

@ -2,6 +2,7 @@
namespace Activitypub; namespace Activitypub;
use WP_Post; use WP_Post;
use Activitypub\Http;
use Activitypub\Activity\Activity; use Activitypub\Activity\Activity;
use Activitypub\Collection\Users; use Activitypub\Collection\Users;
use Activitypub\Collection\Followers; use Activitypub\Collection\Followers;
@ -25,6 +26,8 @@ class Activity_Dispatcher {
public static function init() { 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' ), 10, 2 );
\add_action( 'activitypub_send_activity', array( self::class, 'send_activity_or_announce' ), 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 ); 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 );
}
} }

View file

@ -294,6 +294,18 @@ class Followers {
$activity = $activity->to_json(); $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 ); Http::post( $inbox, $activity, $user_id );
} }