From cd451131fa7f19cd693507917a762fa01d374ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sun, 15 Dec 2024 13:42:57 +0100 Subject: [PATCH] use blog actor --- .../collection/class-event-sources.php | 4 +-- includes/activitypub/handler/class-accept.php | 3 +- includes/activitypub/handler/class-create.php | 2 +- includes/activitypub/handler/class-delete.php | 2 +- includes/activitypub/handler/class-update.php | 4 +-- .../transmogrifier/class-gatherpress.php | 5 ++-- includes/class-event-sources.php | 28 ++++++++++++++++--- includes/class-setup.php | 5 +++- 8 files changed, 36 insertions(+), 17 deletions(-) diff --git a/includes/activitypub/collection/class-event-sources.php b/includes/activitypub/collection/class-event-sources.php index 6710fb0..24a2a74 100644 --- a/includes/activitypub/collection/class-event-sources.php +++ b/includes/activitypub/collection/class-event-sources.php @@ -374,7 +374,7 @@ class Event_Sources { $activity->set_object( $to ); $activity->set_id( $application->get_id() . '#follow-' . \preg_replace( '~^https?://~', '', $to ) ); $activity = $activity->to_json(); - \Activitypub\safe_remote_post( $inbox, $activity, \Activitypub\Collection\Actors::APPLICATION_USER_ID ); + \Activitypub\safe_remote_post( $inbox, $activity, \Activitypub\Collection\Actors::BLOG_USER_ID ); } /** @@ -436,7 +436,7 @@ class Event_Sources { ); $activity->set_id( $actor . '#unfollow-' . \preg_replace( '~^https?://~', '', $to ) ); $activity = $activity->to_json(); - \Activitypub\safe_remote_post( $inbox, $activity, \Activitypub\Collection\Actors::APPLICATION_USER_ID ); + \Activitypub\safe_remote_post( $inbox, $activity, \Activitypub\Collection\Actors::BLOG_USER_ID ); } /** diff --git a/includes/activitypub/handler/class-accept.php b/includes/activitypub/handler/class-accept.php index 4a86ae5..c246df9 100644 --- a/includes/activitypub/handler/class-accept.php +++ b/includes/activitypub/handler/class-accept.php @@ -8,7 +8,6 @@ namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler; -use Activitypub\Notification; use Activitypub\Collection\Actors; /** @@ -43,7 +42,7 @@ class Accept { } // We only expect `Accept` activities being answers to follow requests by the application actor. - if ( Actors::APPLICATION_USER_ID !== $object->get__id() ) { + if ( Actors::BLOG_USER_ID !== $object->get__id() ) { return; } } diff --git a/includes/activitypub/handler/class-create.php b/includes/activitypub/handler/class-create.php index ff75359..e1d48db 100644 --- a/includes/activitypub/handler/class-create.php +++ b/includes/activitypub/handler/class-create.php @@ -45,7 +45,7 @@ class Create { */ public static function handle_create( $activity, $user_id ) { // We only process activities that are target to the application user. - if ( Actors::APPLICATION_USER_ID !== $user_id ) { + if ( Actors::BLOG_USER_ID !== $user_id ) { return; } diff --git a/includes/activitypub/handler/class-delete.php b/includes/activitypub/handler/class-delete.php index ec4cd17..88558f2 100644 --- a/includes/activitypub/handler/class-delete.php +++ b/includes/activitypub/handler/class-delete.php @@ -34,7 +34,7 @@ class Delete { */ public static function handle_delete( $activity, $user_id ) { // We only process activities that are target to the application user. - if ( Actors::APPLICATION_USER_ID !== $user_id ) { + if ( Actors::BLOG_USER_ID !== $user_id ) { return; } diff --git a/includes/activitypub/handler/class-update.php b/includes/activitypub/handler/class-update.php index a4de6eb..a08f3a9 100644 --- a/includes/activitypub/handler/class-update.php +++ b/includes/activitypub/handler/class-update.php @@ -7,9 +7,7 @@ namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler; -use Activitypub\Notification; use Activitypub\Collection\Actors; -use Activitypub\Http; use Event_Bridge_For_ActivityPub\Setup; use function Activitypub\is_activity_public; @@ -38,7 +36,7 @@ class Update { */ public static function handle_update( $activity, $user_id ) { // We only process activities that are target the application user. - if ( Actors::APPLICATION_USER_ID !== $user_id ) { + if ( Actors::BLOG_USER_ID !== $user_id ) { return; } diff --git a/includes/activitypub/transmogrifier/class-gatherpress.php b/includes/activitypub/transmogrifier/class-gatherpress.php index 9af4b19..a0d0db4 100644 --- a/includes/activitypub/transmogrifier/class-gatherpress.php +++ b/includes/activitypub/transmogrifier/class-gatherpress.php @@ -16,7 +16,6 @@ use DateTime; use Exception; use WP_Error; -use function Activitypub\object_to_uri; use function Activitypub\sanitize_url; // Exit if accessed directly. @@ -406,9 +405,9 @@ class GatherPress { $venue_information = array(); - $address = $this->address_to_string(); + $address_string = isset( $location['address'] ) ? $this->address_to_string( $location['address'] ) : ''; - $venue_information['fullAddress'] = $address; + $venue_information['fullAddress'] = $address_string; $venue_information['phone_number'] = ''; $venue_information['website'] = ''; $venue_information['permalink'] = ''; diff --git a/includes/class-event-sources.php b/includes/class-event-sources.php index 82591d0..633e4ff 100644 --- a/includes/class-event-sources.php +++ b/includes/class-event-sources.php @@ -9,12 +9,9 @@ namespace Event_Bridge_For_ActivityPub; -use Activitypub\Activity\Extended_Object\Event; -use Activitypub\Collection\Actors; +use Activitypub\Model\Blog; use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources as Event_Sources_Collection; -use Event_Bridge_For_ActivityPub\Activitypub\Transformer\GatherPress as TransformerGatherPress; use Event_Bridge_For_ActivityPub\Activitypub\Transmogrifier\GatherPress; -use Event_Bridge_For_ActivityPub\Integrations\GatherPress as IntegrationsGatherPress; use function Activitypub\get_remote_metadata_by_actor; use function Activitypub\is_activitypub_request; @@ -159,4 +156,27 @@ class Event_Sources { wp_delete_post( $post_id, true ); } } + + /** + * Add the Blog Authors to the following list of the Blog Actor + * if Blog not in single mode. + * + * @param array $follow_list The array of following urls. + * @param \Activitypub\Model\User $user The user object. + * + * @return array The array of following urls. + */ + public static function add_event_sources_to_following_collection( $follow_list, $user ) { + if ( ! $user instanceof Blog ) { + return $follow_list; + } + + $event_sources = Event_Sources_Collection::get_event_sources_ids(); + + if ( ! is_array( $event_sources ) ) { + return $follow_list; + } + + return array_merge( $follow_list, $event_sources ); + } } diff --git a/includes/class-setup.php b/includes/class-setup.php index cbe568e..3a34351 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -24,6 +24,8 @@ use Event_Bridge_For_ActivityPub\Admin\Settings_Page; use Event_Bridge_For_ActivityPub\Admin\User_Interface; use Event_Bridge_For_ActivityPub\Integrations\Event_Plugin; +use function Activitypub\is_user_type_disabled; + require_once ABSPATH . 'wp-admin/includes/plugin.php'; /** @@ -238,7 +240,7 @@ class Setup { return; } - if ( get_option( 'event_bridge_for_activitypub_event_sources_active' ) ) { + if ( ! is_user_type_disabled( 'blog' ) && get_option( 'event_bridge_for_activitypub_event_sources_active' ) ) { add_action( 'init', array( Event_Sources_Collection::class, 'init' ) ); add_action( 'activitypub_register_handlers', array( Handler::class, 'register_handlers' ) ); add_action( 'admin_init', array( User_Interface::class, 'init' ) ); @@ -249,6 +251,7 @@ class Setup { } add_action( 'event_bridge_for_activitypub_event_sources_clear_cache', array( Event_Sources::class, 'clear_cache' ) ); + add_filter( 'activitypub_rest_following', array( Event_Sources::class, 'add_event_sources_to_following_collection' ), 10, 2 ); add_filter( 'gatherpress_force_online_event_link', function ( $force_online_event_link ) {