From d64ed7323a189f4e2eaec7dc8f12a3371b8ad5d6 Mon Sep 17 00:00:00 2001 From: Django Doucet Date: Wed, 8 Nov 2023 12:37:35 -0700 Subject: [PATCH] Add a server dispatch activity --- includes/class-activity-dispatcher.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/class-activity-dispatcher.php b/includes/class-activity-dispatcher.php index fe31d37..6c2cad4 100644 --- a/includes/class-activity-dispatcher.php +++ b/includes/class-activity-dispatcher.php @@ -26,6 +26,7 @@ class Activity_Dispatcher { \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_update_profile_activity', array( self::class, 'send_profile_update' ), 10, 1 ); + \add_action( 'activitypub_send_server_activity', array( self::class, 'send_server_activity' ), 10, 1 ); } /** @@ -160,4 +161,19 @@ class Activity_Dispatcher { safe_remote_post( $inbox, $json, $user_id ); } } + + /** + * Send an Activity to all known (shared_)inboxes. + * + * @param Activity $activity The ActivityPub Activity. + * + * @return void + */ + private static function send_server_activity( $activity ) { + $json = $activity->to_json(); + $inboxes = Server::known_inboxes(); + foreach ( $inboxes as $inbox ) { + safe_remote_post( $inbox, $json, -1 ); + } + } }