diff --git a/CHANGELOG.md b/CHANGELOG.md index 19569eaaf..6097d2748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed * Undefined array key warnings in various places +* Fetching replies from the same instance for Enable Mastodon Apps * Image captions not being included in the ActivityPub representation when the image is attached to the post ## [4.6.0] - 2024-12-20 diff --git a/includes/constants.php b/includes/constants.php index f00582368..e12450205 100644 --- a/includes/constants.php +++ b/includes/constants.php @@ -34,9 +34,13 @@ 'ACTIVITYPUB_MASTODON_HTML_SANITIZER', array( 'p' => array(), - 'span' => array( 'class' ), + 'span' => array( 'class' => true ), 'br' => array(), - 'a' => array( 'href', 'rel', 'class' ), + 'a' => array( + 'href' => true, + 'rel' => true, + 'class' => true, + ), 'del' => array(), 'pre' => array(), 'code' => array(), @@ -46,8 +50,11 @@ 'i' => array(), 'u' => array(), 'ul' => array(), - 'ol' => array( 'start', 'reversed' ), - 'li' => array( 'value' ), + 'ol' => array( + 'start' => true, + 'reversed' => true, + ), + 'li' => array( 'value' => true ), 'blockquote' => array(), 'h1' => array(), 'h2' => array(), diff --git a/integration/class-enable-mastodon-apps.php b/integration/class-enable-mastodon-apps.php index a412e4315..6bffa949e 100644 --- a/integration/class-enable-mastodon-apps.php +++ b/integration/class-enable-mastodon-apps.php @@ -42,7 +42,7 @@ public static function init() { \add_filter( 'mastodon_api_search', array( self::class, 'api_search_by_url' ), 40, 2 ); \add_filter( 'mastodon_api_get_posts_query_args', array( self::class, 'api_get_posts_query_args' ) ); \add_filter( 'mastodon_api_statuses', array( self::class, 'api_statuses_external' ), 10, 2 ); - \add_filter( 'mastodon_api_status_context', array( self::class, 'api_get_replies' ), 10, 23 ); + \add_filter( 'mastodon_api_status_context', array( self::class, 'api_get_replies' ), 10, 3 ); \add_action( 'mastodon_api_update_credentials', array( self::class, 'api_update_credentials' ), 10, 2 ); } @@ -800,20 +800,37 @@ public static function api_get_replies( $context, $post_id, $url ) { return $context; } - $replies_url = $meta['replies']['first']['next']; - $replies = Http::get_remote_object( $replies_url, true ); - if ( is_wp_error( $replies ) || ! isset( $replies['items'] ) ) { + if ( ! empty( $meta['replies']['first']['items'] ) ) { + $replies = $meta['replies']['first']; + } elseif ( isset( $meta['replies']['first']['next'] ) ) { + $replies_url = $meta['replies']['first']['next']; + $replies = Http::get_remote_object( $replies_url, true ); + if ( is_wp_error( $replies ) || ! isset( $replies['items'] ) ) { + return $context; + } + } else { return $context; } - foreach ( $replies['items'] as $url ) { - $response = Http::get( $url, true ); - if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) { - continue; - } - $status = json_decode( wp_remote_retrieve_body( $response ), true ); - if ( ! $status || is_wp_error( $status ) ) { - continue; + foreach ( $replies['items'] as $reply ) { + if ( isset( $reply['id'] ) && is_string( $reply['id'] ) && isset( $reply['content'] ) && is_string( $reply['content'] ) ) { + $status = $reply; + } else { + if ( is_string( $reply ) ) { + $url = $reply; + } elseif ( isset( $reply['url'] ) && is_string( $reply['url'] ) ) { + $url = $reply['url']; + } else { + continue; + } + $response = Http::get( $url, true ); + if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) { + continue; + } + $status = json_decode( wp_remote_retrieve_body( $response ), true ); + if ( ! $status || is_wp_error( $status ) ) { + continue; + } } $account = self::get_account_for_actor( $status['attributedTo'] ); diff --git a/readme.txt b/readme.txt index a34d273a3..88bd189a3 100644 --- a/readme.txt +++ b/readme.txt @@ -137,6 +137,7 @@ For reasons of data protection, it is not possible to see the followers of other * Added: A filter to make custom comment types manageable in WP.com Calypso * Changed: Hide ActivityPub post meta keys from the custom Fields UI * Fixed: Undefined array key warnings in various places +* Fixed: Fetching replies from the same instance for Enable Mastodon Apps * Fixed: Image captions not being included in the ActivityPub representation when the image is attached to the post = 4.6.0 =