Skip to content

Commit

Permalink
Add args for EMA (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk authored Feb 19, 2025
1 parent 70cec2d commit bb6d04d
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions integrations/class-enable-mastodon-apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static function init() {
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' ) );
add_filter( 'mastodon_api_favourites_args', array( get_called_class(), 'mastodon_api_favourites_args' ), 10, 2 );
add_filter( 'mastodon_api_bookmarks_args', array( get_called_class(), 'mastodon_api_bookmarks_args' ), 10, 2 );
}

public static function mastodon_api_account_follow( $user_id ) {
Expand Down Expand Up @@ -55,4 +57,47 @@ public static function mastodon_api_view_post_types( $view_post_types ) {
$view_post_types[] = Friends::CPT;
return $view_post_types;
}

public static function mastodon_api_favourites_args( $args, $user_id ) {
return self::mastodon_api_reaction_args(
apply_filters( 'friends_favourites_emoji', '2764' ), // ❤️
$args,
$user_id
);
}
public static function mastodon_api_bookmarks_args( $args, $user_id ) {
return self::mastodon_api_reaction_args(
apply_filters( 'friends_bookmarks_emoji', '2b50' ), // ⭐
$args,
$user_id
);
}

protected static function mastodon_api_reaction_args( $reaction, $args, $user_id ) {
$tax_query = array();
if ( isset( $args['tax_query'] ) ) {
$tax_query = $args['tax_query'];
}

if ( ! empty( $tax_query ) ) {
$tax_query['relation'] = 'AND';
}
Reactions::register_user_taxonomy( $user_id );

$reaction_query = array(
'taxonomy' => 'friend-reaction-' . $user_id,
'field' => 'slug',
'terms' => array( strval( $reaction ) ),
);

if ( ! empty( $tax_query ) ) {
$tax_query[] = $reaction_query;
} else {
$tax_query = array( $reaction_query );
}

$args['tax_query'] = $tax_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query

return $args;
}
}

0 comments on commit bb6d04d

Please sign in to comment.