Differentiate inbox/outbox handle functions
This commit is contained in:
parent
4e3f17155c
commit
f7351ae7f3
@ -4,7 +4,7 @@ namespace activities\block;
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../blocks.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../actors.php';
|
||||
|
||||
function handle( $actor, $activity ) {
|
||||
function handle_outbox( $actor, $activity ) {
|
||||
if ( !array_key_exists( 'object', $activity ) ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
|
@ -11,7 +11,7 @@ to the object and vice-versa.
|
||||
|
||||
Returns either the modified $activity or a WP_Error.
|
||||
*/
|
||||
function handle( $actor, $activity ) {
|
||||
function handle_outbox( $actor, $activity ) {
|
||||
if ( !(array_key_exists( 'type', $activity ) && $activity['type'] === 'Create') ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity', __( 'Expecting a Create activity', 'activitypub' )
|
||||
|
@ -3,7 +3,7 @@ namespace activities\delete;
|
||||
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../objects.php';
|
||||
|
||||
function handle( $actor, $activity ) {
|
||||
function handle_outbox( $actor, $activity ) {
|
||||
if ( !array_key_exists( 'object', $activity ) ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
|
@ -4,7 +4,7 @@ namespace activities\follow;
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../following.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../actors.php';
|
||||
|
||||
function handle( $actor, $activity ) {
|
||||
function handle_outbox( $actor, $activity ) {
|
||||
if ( !array_key_exists( 'object', $activity ) ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
|
@ -4,7 +4,7 @@ namespace activities\like;
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../likes.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../actors.php';
|
||||
|
||||
function handle( $actor, $activity ) {
|
||||
function handle_outbox( $actor, $activity ) {
|
||||
if ( !array_key_exists( 'object', $activity ) ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
|
@ -3,7 +3,7 @@ namespace activities\update;
|
||||
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../objects.php';
|
||||
|
||||
function handle( $actor, $activity ) {
|
||||
function handle_outbox( $actor, $activity ) {
|
||||
if ( !(array_key_exists( 'type', $activity ) && $activity['type'] === 'Update') ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
|
@ -11,7 +11,7 @@ function get_actor( $request ) {
|
||||
return \actors\get_actor_by_slug( $actor );
|
||||
}
|
||||
|
||||
function handle_activity( $request ) {
|
||||
function handle_outbox( $request ) {
|
||||
$actor = $request['actor'];
|
||||
$activity = json_decode( $request->get_body(), true );
|
||||
return \outbox\handle_activity( $actor, $activity );
|
||||
@ -30,7 +30,7 @@ function get_activity( $request ) {
|
||||
function register_routes() {
|
||||
register_rest_route( 'activitypub/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)/outbox', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => __NAMESPACE__ . '\handle_activity',
|
||||
'callback' => __NAMESPACE__ . '\handle_outbox',
|
||||
) );
|
||||
register_rest_route( 'activitypub/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)', array(
|
||||
'methods' => 'GET',
|
||||
|
@ -32,16 +32,16 @@ function handle_activity( $actor, $activity ) {
|
||||
}
|
||||
switch ( $activity['type'] ) {
|
||||
case 'Create':
|
||||
$activity = \activities\create\handle( $actor, $activity );
|
||||
$activity = \activities\create\handle_outbox( $actor, $activity );
|
||||
break;
|
||||
case 'Update':
|
||||
$activity = \activities\update\handle( $actor, $activity );
|
||||
$activity = \activities\update\handle_outbox( $actor, $activity );
|
||||
break;
|
||||
case 'Delete':
|
||||
$activity = \activities\delete\handle( $actor, $activity );
|
||||
$activity = \activities\delete\handle_outbox( $actor, $activity );
|
||||
break;
|
||||
case 'Follow':
|
||||
$activity = \activities\follow\handle( $actor, $activity );
|
||||
$activity = \activities\follow\handle_outbox( $actor, $activity );
|
||||
break;
|
||||
case 'Add':
|
||||
return new \WP_Error(
|
||||
@ -58,10 +58,10 @@ function handle_activity( $actor, $activity ) {
|
||||
);
|
||||
break;
|
||||
case 'Like':
|
||||
$activity = \activities\like\handle( $actor, $activity );
|
||||
$activity = \activities\like\handle_outbox( $actor, $activity );
|
||||
break;
|
||||
case 'Block':
|
||||
$activity = \activities\block\handle( $actor, $activity );
|
||||
$activity = \activities\block\handle_outbox( $actor, $activity );
|
||||
break;
|
||||
case 'Undo':
|
||||
return new \WP_Error(
|
||||
@ -75,7 +75,7 @@ function handle_activity( $actor, $activity ) {
|
||||
if ( is_wp_error( $create_activity ) ) {
|
||||
return $create_activity;
|
||||
}
|
||||
$activity = \activities\create\handle( $actor, $create_activity );
|
||||
$activity = \activities\create\handle_outbox( $actor, $create_activity );
|
||||
break;
|
||||
}
|
||||
if ( is_wp_error( $activity ) ) {
|
||||
@ -86,6 +86,16 @@ function handle_activity( $actor, $activity ) {
|
||||
}
|
||||
}
|
||||
|
||||
function get_outbox( $actor_id ) {
|
||||
global $wpdb;
|
||||
$activities = $wpdb->get_results( $wpdb->prepare(
|
||||
"
|
||||
SELECT * FROM activitypub_outbox WHERE
|
||||
"
|
||||
) );
|
||||
// $wpdb->num_rows will hold the number of results, once this implements paging
|
||||
}
|
||||
|
||||
function deliver_activity( $activity ) {
|
||||
\deliver\deliver_activity( $activity );
|
||||
$activity = \activities\strip_private_fields( $activity );
|
||||
@ -127,10 +137,10 @@ function create_outbox_table() {
|
||||
"
|
||||
CREATE TABLE IF NOT EXISTS activitypub_outbox (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
actor VARCHAR(128) NOT NULL,
|
||||
actor_id UNSIGNED INT NOT NULL,
|
||||
activity_id INT UNSIGNED NOT NULL,
|
||||
FOREIGN KEY activity_fk(activity_id)
|
||||
REFERENCES activitypub_activities(id)
|
||||
REFERENCES activitypub_activities(id),
|
||||
);
|
||||
"
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user