Skip to content

Commit

Permalink
Fix unfollowing in Enable Mastodon Apps
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Feb 13, 2025
1 parent 401ecef commit 2fefcd1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 9 additions & 1 deletion includes/class-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 22 additions & 2 deletions integrations/class-enable-mastodon-apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit 2fefcd1

Please sign in to comment.