Decode followers/following json

This commit is contained in:
Jeremy Dormitzer 2018-10-11 07:20:46 -04:00
parent 073d597afa
commit 03f171a8fd
3 changed files with 15 additions and 3 deletions

View File

@ -89,12 +89,17 @@ function get_followers_collection( $actor_slug ) {
",
$actor_id
),
ARRAY_N
ARRAY_A
);
if ( !$followers ) {
$followers = array();
}
$collection = \collections\make_ordered_collection( $followers );
$collection = \collections\make_ordered_collection( array_map(
function ( $result ) {
return json_decode( $result['object'], true );
},
$followers
) );
$collection['id'] = get_rest_url( null, sprintf(
'/pterotype/v1/actor/%s/followers', $actor_slug
) );

View File

@ -62,7 +62,12 @@ function get_following_collection( $actor_slug ) {
if ( !$objects ) {
$objects = array();
}
$collection = \collections\make_ordered_collection( $objects );
$collection = \collections\make_ordered_collection( array_map(
function( $result ) {
return json_decode( $result['object'], true );
},
$objects
) );
$collection['id'] = get_rest_url( null, sprintf(
'/pterotype/v1/actor/%s/following', $actor_slug
) );

View File

@ -25,6 +25,8 @@ require_once plugin_dir_path( __FILE__ ) . '../util.php';
function handle_activity( $actor_slug, $activity ) {
// TODO how should I handle duplicate activities getting posted here and in the outbox?
// Is it okay to just drop them if I already have the activity id in the objects table?
// A good strategy would just be to make sure all activities are idempotent, e.g.
// don't create multiple Accepts of the same Follow
// TODO verify the authenticity of the activity
$activity = \util\dereference_object( $activity );
if ( !array_key_exists( 'type', $activity ) ) {