diff --git a/includes/client/identity.php b/includes/client/identity.php new file mode 100644 index 0000000..74b9ba2 --- /dev/null +++ b/includes/client/identity.php @@ -0,0 +1,27 @@ +set_method( 'POST' ); + $request->set_body( wp_json_encode( $update ) ); + $request->add_header( 'Content-Type', 'application/ld+json' ); + $server->dispatch( $request ); +} +?> diff --git a/includes/init.php b/includes/init.php index b53dd37..37e9985 100644 --- a/includes/init.php +++ b/includes/init.php @@ -8,6 +8,7 @@ require_once plugin_dir_path( __FILE__ ) . 'schema.php'; require_once plugin_dir_path( __FILE__ ) . 'server/webfinger.php'; require_once plugin_dir_path( __FILE__ ) . 'client/posts.php'; require_once plugin_dir_path( __FILE__ ) . 'client/comments.php'; +require_once plugin_dir_path( __FILE__ ) . 'client/identity.php'; require_once plugin_dir_path( __FILE__ ) . 'server/async.php'; require_once plugin_dir_path( __FILE__ ) . 'pgp.php'; @@ -51,4 +52,13 @@ add_action( add_action( 'comment_post', '\pterotype\comments\handle_comment_post', 10, 2 ); add_action( 'edit_comment', '\pterotype\comments\handle_edit_comment', 10, 1 ); add_action( 'template_redirect', '\pterotype\api\handle_non_api_requests' ); +add_action( 'update_option_blogname', function() { + \pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG ); +}); +add_action( 'update_option_blogdescription', function() { + \pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG ); +}); +add_action( 'update_option_site_icon', function() { + \pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG ); +}); ?> diff --git a/includes/server/inbox.php b/includes/server/inbox.php index 378656e..934e666 100644 --- a/includes/server/inbox.php +++ b/includes/server/inbox.php @@ -37,10 +37,11 @@ function handle_activity( $actor_slug, $activity ) { ); } forward_activity( $actor_slug, $activity ); - $activity = persist_activity( $actor_slug, $activity ); - if ( is_wp_error( $activity ) ) { - return $activity; + $persisted = persist_activity( $actor_slug, $activity ); + if ( is_wp_error( $persisted ) ) { + return $persisted; } + $activity['id'] = $persisted['id']; switch ( $activity['type'] ) { case 'Create': $activity = \pterotype\activities\create\handle_inbox( $actor_slug, $activity ); diff --git a/includes/server/outbox.php b/includes/server/outbox.php index 8923bcb..60485e8 100644 --- a/includes/server/outbox.php +++ b/includes/server/outbox.php @@ -36,10 +36,12 @@ function handle_activity( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $activity = persist_activity( $actor_slug, $activity ); - if ( is_wp_error( $activity ) ) { - return $activity; + // Don't overwrite the activity to prevent compacting from deleting data + $persisted = persist_activity( $actor_slug, $activity ); + if ( is_wp_error( $persisted ) ) { + return $persisted; } + $activity['id'] = $persisted['id']; switch ( $activity['type'] ) { case 'Create': $activity = \pterotype\activities\create\handle_outbox( $actor_slug, $activity );