| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Activitypub\Rest; |
| 9 | 9 | |
| 10 | 10 | use Activitypub\Activity\Base_Object; |
| 11 | +use Activitypub\Collection\Actors; | |
| 11 | 12 | use Activitypub\Collection\Following; |
| 12 | 13 | use Activitypub\Collection\Remote_Actors; |
| 13 | 14 | |
| 14 | 15 | use function Activitypub\get_masked_wp_version; |
| @@ -42,9 +43,9 @@ | ||
| 42 | 43 | ), |
| 43 | 44 | array( |
| 44 | 45 | 'methods' => \WP_REST_Server::READABLE, |
| 45 | 46 | 'callback' => array( $this, 'get_items' ), |
| 46 | - 'permission_callback' => array( $this, 'verify_signature' ), | |
| 47 | + 'permission_callback' => array( 'Activitypub\Rest\Server', 'verify_signature' ), | |
| 47 | 48 | 'args' => array( |
| 48 | 49 | 'page' => array( |
| 49 | 50 | 'description' => 'Current page of the collection.', |
| 50 | 51 | 'type' => 'integer', |
| @@ -84,8 +85,12 @@ | ||
| 84 | 85 | * @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure. |
| 85 | 86 | */ |
| 86 | 87 | public function get_items( $request ) { |
| 87 | 88 | $user_id = $request->get_param( 'user_id' ); |
| 89 | + $user = null; | |
| 90 | + if ( \has_filter( 'activitypub_rest_following' ) ) { | |
| 91 | + $user = Actors::get_by_id( $user_id ); | |
| 92 | + } | |
| 88 | 93 | |
| 89 | 94 | /** |
| 90 | 95 | * Action triggered prior to the ActivityPub profile being created and sent to the client. |
| 91 | 96 | */ |
| @@ -109,9 +114,9 @@ | ||
| 109 | 114 | // Ensure the context is the first element in the response. |
| 110 | 115 | $response = array( '@context' => Base_Object::JSON_LD_CONTEXT ) + $response; |
| 111 | 116 | } |
| 112 | 117 | |
| 113 | - if ( $this->show_social_graph( $request ) ) { | |
| 118 | + if ( Actors::show_social_graph( $user_id ) ) { | |
| 114 | 119 | $response['orderedItems'] = \array_filter( |
| 115 | 120 | \array_map( |
| 116 | 121 | static function ( $item ) use ( $context ) { |
| 117 | 122 | if ( 'full' === $context ) { |
| @@ -125,8 +130,23 @@ | ||
| 125 | 130 | }, |
| 126 | 131 | $data['following'] |
| 127 | 132 | ) |
| 128 | 133 | ); |
| 134 | + } | |
| 135 | + | |
| 136 | + /** | |
| 137 | + * Filter the list of following urls | |
| 138 | + * | |
| 139 | + * @param array $items The array of following urls. | |
| 140 | + * @param \Activitypub\Model\User $user The user object. | |
| 141 | + * | |
| 142 | + * @deprecated 7.1.0 Please migrate your Followings to the new internal Following structure. | |
| 143 | + */ | |
| 144 | + $items = \apply_filters_deprecated( 'activitypub_rest_following', array( array(), $user ), '7.1.0', 'Please migrate your Followings to the new internal Following structure.' ); | |
| 145 | + | |
| 146 | + if ( ! empty( $items ) ) { | |
| 147 | + $response['totalItems'] = count( $items ); | |
| 148 | + $response['orderedItems'] = $items; | |
| 129 | 149 | } |
| 130 | 150 | |
| 131 | 151 | $response = $this->prepare_collection_response( $response, $request ); |
| 132 | 152 | if ( \is_wp_error( $response ) ) { |