Send accept activities after the follow request has been handled

This commit is contained in:
Jeremy Dormitzer 2018-10-18 07:34:27 -04:00
parent 17766a154d
commit 8d2d75da40
6 changed files with 91 additions and 7 deletions

View File

@ -1,5 +1,6 @@
{
"require": {
"singpolyma/openpgp-php": "0.3.*"
"singpolyma/openpgp-php": "0.3.*",
"techcrunch/wp-async-task": "dev-master"
}
}

57
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f89229825d6a5fb0c6b4631f153ace78",
"content-hash": "639c41ba8fc796bb88630bf51bb0ce38",
"packages": [
{
"name": "phpseclib/phpseclib",
@ -140,12 +140,65 @@
],
"description": "Pure-PHP implementation of the OpenPGP Message Format (RFC 4880)",
"time": "2017-04-12T21:23:15+00:00"
},
{
"name": "techcrunch/wp-async-task",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/techcrunch/wp-async-task.git",
"reference": "9bdbbf9df4ff5179711bb58b9a2451296f6753dc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/techcrunch/wp-async-task/zipball/9bdbbf9df4ff5179711bb58b9a2451296f6753dc",
"reference": "9bdbbf9df4ff5179711bb58b9a2451296f6753dc",
"shasum": ""
},
"require-dev": {
"10up/wp_mock": "dev-master",
"phpunit/phpunit": "*@stable"
},
"type": "wordpress-plugin",
"autoload": {
"classmap": [
"wp-async-task.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alex Khadiwala",
"role": "developer"
},
{
"name": "Nicolas Vincent",
"role": "developer"
},
{
"name": "Eric Mann",
"email": "eric.mann@10up.com",
"role": "developer"
},
{
"name": "John P. Bloch",
"email": "john.bloch@10up.com",
"role": "developer"
}
],
"description": "Run asynchronous tasks for long-running operations in WordPress",
"time": "2016-03-10T17:37:13+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"stability-flags": {
"techcrunch/wp-async-task": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],

View File

@ -7,6 +7,7 @@ require_once plugin_dir_path( __FILE__ ) . 'server/actors.php';
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__ ) . 'server/async.php';
add_action( 'rest_api_init', function() {
\api\register_routes();
@ -27,6 +28,7 @@ add_action( 'pterotype_init', function() {
add_action( 'pterotype_load', function() {
\schema\run_migrations();
\async\init_tasks();
} );
add_action( 'generate_rewrite_rules', '\webfinger\generate_rewrite_rules', 111 );

View File

@ -43,10 +43,7 @@ function handle_inbox( $actor_slug, $activity ) {
if ( is_wp_error( $accept ) ) {
return $accept;
}
$res = \outbox\handle_activity( $actor_slug, $accept );
if ( is_wp_error( $res ) ) {
return $res;
}
do_action( 'pterotype_send_accept', $actor_slug, $accept );
}
return $activity;
}

28
includes/server/async.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace async;
require_once plugin_dir_path( __FILE__ ) . 'outbox.php';
class Send_Accept_Task extends \WP_Async_Task {
protected $action = 'pterotype_send_accept';
protected function prepare_data( $data ) {
$actor_slug = $data[0];
$accept = $data[1];
return array( 'actor_slug' => $actor_slug, 'accept' => $accept );
}
protected function run_action() {
$actor_slug = $_POST['actor_slug'];
$accept = $_POST['accept'];
if ( $actor_slug && $accept ) {
sleep( 5 );
\outbox\handle_activity( $actor_slug, $accept );
}
}
}
function init_tasks() {
new Send_Accept_Task();
}
?>

View File

@ -24,6 +24,9 @@ require_once plugin_dir_path( __FILE__ ) . 'activities/undo.php';
require_once plugin_dir_path( __FILE__ ) . '../util.php';
function handle_activity( $actor_slug, $activity ) {
\util\log( 'outbox.html', 'Got outbox request', false );
\util\log_var( 'outbox.html', $actor_slug );
\util\log_var( 'outbox.html', $activity );
// TODO handle authentication/authorization
$activity = \util\dereference_object( $activity );
if ( is_wp_error( $activity ) ) {