From d5c440dca120fe2cf30c024e79725e339347a2f1 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 11 Dec 2024 17:11:45 +0100 Subject: [PATCH] Use the ActivityPub blog user as an actor if set to blog profile only --- .../class-feed-parser-activitypub.php | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/feed-parsers/class-feed-parser-activitypub.php b/feed-parsers/class-feed-parser-activitypub.php index dbb82ce7..2e4c6269 100644 --- a/feed-parsers/class-feed-parser-activitypub.php +++ b/feed-parsers/class-feed-parser-activitypub.php @@ -686,6 +686,19 @@ private function disable_polling( User_Feed $user_feed ) { $user_feed->update_metadata( 'next-poll', gmdate( 'Y-m-d H:i:s', time() + YEAR_IN_SECONDS ) ); } + public function get_activitypub_actor_userid( $user_id ) { + if ( null === $user_id ) { + $user_id = Friends::get_main_friend_user_id(); + if ( class_exists( '\ActivityPub\Collection\Followers' ) ) { + $activitypub_actor_mode = \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ); + if ( ACTIVITYPUB_BLOG_MODE === $activitypub_actor_mode ) { + $user_id = \Activitypub\Collection\Actors::BLOG_USER_ID; + } + } + } + return $user_id; + } + /** * Gets the external mentions user. * @@ -1073,9 +1086,7 @@ private function handle_incoming_announce( $url, $user_id, $published_date = nul return false; } $this->log( 'Received announce for ' . $url ); - if ( null === $user_id ) { - $user_id = Friends::get_main_friend_user_id(); - } + $user_id = $this->get_activitypub_actor_userid( $user_id ); $response = \Activitypub\safe_remote_get( $url, $user_id ); if ( \is_wp_error( $response ) ) { return $response; @@ -1251,10 +1262,7 @@ public function queue_follow_user( User_Feed $user_feed ) { * @param int $user_id The current user id. */ public function activitypub_follow_user( $url, $user_id = null ) { - if ( null === $user_id ) { - $user_id = Friends::get_main_friend_user_id(); - } - + $user_id = $this->get_activitypub_actor_userid( $user_id ); $meta = $this->get_metadata( $url ); $user_feed = User_Feed::get_by_url( $url ); if ( is_wp_error( $meta ) ) { @@ -1330,9 +1338,7 @@ public function queue_unfollow_user( User_Feed $user_feed ) { * @param int $user_id The current user id. */ public function activitypub_unfollow_user( $url, $user_id = null ) { - if ( null === $user_id ) { - $user_id = Friends::get_main_friend_user_id(); - } + $user_id = $this->get_activitypub_actor_userid( $user_id ); $meta = $this->get_metadata( $url ); $user_feed = User_Feed::get_by_url( $url ); if ( is_wp_error( $meta ) ) {