10000 Augment bookmarks and favourites endpoints in EMA by akirk · Pull Request #474 · akirk/friends · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Augment bookmarks and favourites endpoints in EMA #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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