Skip to content

Commit

Permalink
Use the ActivityPub blog user as an actor if set to blog profile only
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Dec 11, 2024
1 parent 199af50 commit d5c440d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -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 ) ) {
Expand Down

0 comments on commit d5c440d

Please sign in to comment.