@@ -42,7 +42,7 @@ public static function init() {
42
42
\add_filter ( 'mastodon_api_search ' , array ( self ::class, 'api_search_by_url ' ), 40 , 2 );
43
43
\add_filter ( 'mastodon_api_get_posts_query_args ' , array ( self ::class, 'api_get_posts_query_args ' ) );
44
44
\add_filter ( 'mastodon_api_statuses ' , array ( self ::class, 'api_statuses_external ' ), 10 , 2 );
45
- \add_filter ( 'mastodon_api_status_context ' , array ( self ::class, 'api_get_replies ' ), 10 , 23 );
45
+ \add_filter ( 'mastodon_api_status_context ' , array ( self ::class, 'api_get_replies ' ), 10 , 3 );
46
46
\add_action ( 'mastodon_api_update_credentials ' , array ( self ::class, 'api_update_credentials ' ), 10 , 2 );
47
47
}
48
48
@@ -800,20 +800,37 @@ public static function api_get_replies( $context, $post_id, $url ) {
800
800
return $ context ;
801
801
}
802
802
803
- $ replies_url = $ meta ['replies ' ]['first ' ]['next ' ];
804
- $ replies = Http::get_remote_object ( $ replies_url , true );
805
- if ( is_wp_error ( $ replies ) || ! isset ( $ replies ['items ' ] ) ) {
803
+ if ( ! empty ( $ meta ['replies ' ]['first ' ]['items ' ] ) ) {
804
+ $ replies = $ meta ['replies ' ]['first ' ];
805
+ } elseif ( isset ( $ meta ['replies ' ]['first ' ]['next ' ] ) ) {
806
+ $ replies_url = $ meta ['replies ' ]['first ' ]['next ' ];
807
+ $ replies = Http::get_remote_object ( $ replies_url , true );
808
+ if ( is_wp_error ( $ replies ) || ! isset ( $ replies ['items ' ] ) ) {
809
+ return $ context ;
810
+ }
811
+ } else {
806
812
return $ context ;
807
813
}
808
814
809
- foreach ( $ replies ['items ' ] as $ url ) {
810
- $ response = Http::get ( $ url , true );
811
- if ( is_wp_error ( $ response ) || wp_remote_retrieve_response_code ( $ response ) !== 200 ) {
812
- continue ;
813
- }
814
- $ status = json_decode ( wp_remote_retrieve_body ( $ response ), true );
815
- if ( ! $ status || is_wp_error ( $ status ) ) {
816
- continue ;
815
+ foreach ( $ replies ['items ' ] as $ reply ) {
816
+ if ( isset ( $ reply ['id ' ] ) && is_string ( $ reply ['id ' ] ) && isset ( $ reply ['content ' ] ) && is_string ( $ reply ['content ' ] ) ) {
817
+ $ status = $ reply ;
818
+ } else {
819
+ if ( is_string ( $ reply ) ) {
820
+ $ url = $ reply ;
821
+ } elseif ( isset ( $ reply ['url ' ] ) && is_string ( $ reply ['url ' ] ) ) {
822
+ $ url = $ reply ['url ' ];
823
+ } else {
824
+ continue ;
825
+ }
826
+ $ response = Http::get ( $ url , true );
827
+ if ( is_wp_error ( $ response ) || wp_remote_retrieve_response_code ( $ response ) !== 200 ) {
828
+ continue ;
829
+ }
830
+ $ status = json_decode ( wp_remote_retrieve_body ( $ response ), true );
831
+ if ( ! $ status || is_wp_error ( $ status ) ) {
832
+ continue ;
833
+ }
817
834
}
818
835
819
836
$ account = self ::get_account_for_actor ( $ status ['attributedTo ' ] );
0 commit comments