diff --git a/includes/class-user.php b/includes/class-user.php index 0ab6345f..a1d52be4 100644 --- a/includes/class-user.php +++ b/includes/class-user.php @@ -1469,13 +1469,21 @@ public static function mastodon_api_get_posts_query_args( $args ) { } public static function mastodon_entity_relationship( $relationship, $user_id ) { + if ( ! class_exists( 'Friends\Feed_Parser_ActivityPub' ) ) { + return $relationship; + } $user = Feed_Parser_ActivityPub::determine_mastodon_api_user( $user_id ); if ( $user instanceof self ) { if ( ! $relationship instanceof \Enable_Mastodon_Apps\Entity\Relationship ) { $relationship = new \Enable_Mastodon_Apps\Entity\Relationship(); } + foreach ( $user->get_active_feeds() as $feed ) { + if ( Feed_Parser_ActivityPub::SLUG === $feed->get_parser() ) { + $relationship->following = true; + break; + } + } - $relationship->following = true; if ( $user->has_cap( 'friend' ) ) { $relationship->followed_by = true; } diff --git a/integrations/class-enable-mastodon-apps.php b/integrations/class-enable-mastodon-apps.php index acd21c61..a21d4025 100644 --- a/integrations/class-enable-mastodon-apps.php +++ b/integrations/class-enable-mastodon-apps.php @@ -16,14 +16,34 @@ public static function init() { add_filter( 'mastodon_api_account', array( 'Friends\User', 'mastodon_api_account' ), 8, 4 ); add_filter( 'mastodon_api_get_posts_query_args', array( 'Friends\User', 'mastodon_api_get_posts_query_args' ) ); add_filter( 'mastodon_entity_relationship', array( 'Friends\User', 'mastodon_entity_relationship' ), 10, 2 ); - add_action( 'mastodon_api_account_follow', array( get_called_class(), 'mastodon_api_account_follow' ), 10, 1 ); + add_filter( 'mastodon_api_account_follow', array( get_called_class(), 'mastodon_api_account_follow' ), 10, 1 ); + add_action( 'mastodon_api_account_unfollow', array( get_called_class(), 'mastodon_api_account_unfollow' ), 10, 1 ); add_filter( 'mastodon_api_timelines_args', array( get_called_class(), 'mastodon_api_timelines_args' ) ); add_filter( 'mastodon_api_account_statuses_args', array( get_called_class(), 'mastodon_api_timelines_args' ) ); add_filter( 'mastodon_api_view_post_types', array( get_called_class(), 'mastodon_api_view_post_types' ) ); } public static function mastodon_api_account_follow( $user_id ) { - return apply_filters( 'friends_create_and_follow', null, $user_id ); + $user = User::get_user_by_id( $user_id ); + if ( ! $user ) { + return apply_filters( 'friends_create_and_follow', null, $user_id ); + } + foreach ( $user->get_feeds() as $feed ) { + if ( $feed->is_active() ) { + continue; + } + if ( class_exists( 'Friends\Feed_Parser_ActivityPub' ) && Feed_Parser_ActivityPub::SLUG === $feed->get_parser() ) { + $feed->activate(); + } + } + return $user_id; + } + + public static function mastodon_api_account_unfollow( $user_id ) { + $user = User::get_user_by_id( $user_id ); + foreach ( $user->get_active_feeds() as $feed ) { + $feed->deactivate(); + } } public static function mastodon_api_timelines_args( $args ) {