Matthias Pfefferle 2023-08-11 09:23:49 +02:00
parent bc7e173fe0
commit 30eb07ba17

View file

@ -4,6 +4,7 @@ namespace Activitypub\Rest;
use WP_REST_Server; use WP_REST_Server;
use WP_REST_Response; use WP_REST_Response;
use Activitypub\Transformer\Post; use Activitypub\Transformer\Post;
use Activitypub\Activity\Activity;
use function Activitypub\esc_hashtag; use function Activitypub\esc_hashtag;
use function Activitypub\get_rest_url_by_path; use function Activitypub\get_rest_url_by_path;
@ -80,13 +81,9 @@ class Collection {
} }
$response = array( $response = array(
'@context' => array( '@context' => Activity::CONTEXT,
'https://www.w3.org/ns/activitystreams',
array(
'Hashtag' => 'as:Hashtag',
),
),
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user_id ) ), 'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user_id ) ),
'type' => 'Collection',
'totalItems' => count( $tags ), 'totalItems' => count( $tags ),
'items' => array(), 'items' => array(),
); );
@ -124,23 +121,15 @@ class Collection {
$posts = \get_posts( $args ); $posts = \get_posts( $args );
$response = array( $response = array(
'@context' => 'https://www.w3.org/ns/activitystreams', '@context' => Activity::CONTEXT,
array( 'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $user_id ) ),
'ostatus' => 'http://ostatus.org#', 'type' => 'OrderedCollection',
'atomUri' => 'ostatus:atomUri', 'totalItems' => count( $posts ),
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri', 'orderedItems' => array(),
'conversation' => 'ostatus:conversation',
'sensitive' => 'as:sensitive',
'toot' => 'http://joinmastodon.org/ns#',
'votersCount' => 'toot:votersCount',
),
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $user_id ) ),
'totalItems' => count( $posts ),
'items' => array(),
); );
foreach ( $posts as $post ) { foreach ( $posts as $post ) {
$response['items'][] = Post::transform( $post )->to_object()->to_array(); $response['orderedItems'][] = Post::transform( $post )->to_object()->to_array();
} }
return new WP_REST_Response( $response, 200 ); return new WP_REST_Response( $response, 200 );