Implement reject for inbox

This commit is contained in:
Jeremy Dormitzer 2018-09-23 20:30:31 -04:00
parent 5e76224f04
commit 124bf8b4ac
3 changed files with 62 additions and 0 deletions

39
inc/activities/reject.php Normal file
View File

@ -0,0 +1,39 @@
<?php
namespace activities\reject;
require_once plugin_dir_path( __FILE__ ) . '/../following.php';
require_once plugin_dir_path( __FILE__ ) . '/../objects.php';
require_once plugin_dir_path( __FILE__ ) . '/../actors.php';
function handle_inbox( $actor_slug, $activity ) {
if ( !array_key_exists( 'object', $activity ) ) {
return new \WP_Error(
'invalid_activity',
__( 'Activity must have an "object" field', 'pterotype' ),
array( 'status' => 400 );
);
}
$object = $activity['object'];
if ( array_key_exists( 'type', $object ) ) {
switch ( $object['type'] ) {
case 'Follow':
if ( !array_key_exists( 'object', $object ) ) {
break;
}
$follow_object = $object['object'];
if ( !array_key_exists( 'id', $follow_object ) ) {
break;
}
$object_id = \objects\get_object_by_activitypub_id( $follow_object['id'] );
if ( is_wp_error( $object_id ) ) {
break;
}
$actor_id = \actors\get_actor_id( $actor_slug );
\following\reject_follow( $actor_id, $object_id );
break;
default:
break;
}
}
}
?>

View File

@ -27,6 +27,15 @@ function accept_follow( $actor_id, $object_id ) {
);
}
function reject_follow( $actor_id, $object_id ) {
global $wpdb;
return $wpdb->delete(
'pterotype_following',
array( 'actor_id' => $actor_id, 'object_id' => $object_id ),
'%d'
);
}
function get_following_collection( $actor_slug ) {
global $wpdb;
$actor_id = \actors\get_actor_id( $actor_slug );

View File

@ -14,6 +14,8 @@ require_once plugin_dir_path( __FILE__ ) . '/activities/create.php';
require_once plugin_dir_path( __FILE__ ) . '/activities/update.php';
require_once plugin_dir_path( __FILE__ ) . '/activities/delete.php';
require_once plugin_dir_path( __FILE__ ) . '/activities/follow.php';
require_once plugin_dir_path( __FILE__ ) . '/activities/accept.php';
require_once plugin_dir_path( __FILE__ ) . '/activities/reject.php';
function handle_activity( $actor_slug, $activity ) {
if ( !array_key_exists( 'type', $activity ) ) {
@ -41,14 +43,26 @@ function handle_activity( $actor_slug, $activity ) {
$activity = \activities\accept\handle_inbox( $actor_slug, $activity );
break;
case 'Reject':
$activity = \activities\reject\handle_inbox( $actor_slug, $activity );
break;
case 'Add':
return new \WP_Error(
'not_implemented',
__( 'The Add activity has not been implemented', 'pterotype' ),
array( 'status' => 501 )
);
break;
case 'Remove':
return new \WP_Error(
'not_implemented',
__( 'The Remove activity has not been implemented', 'pterotype' ),
array( 'status' => 501 )
);
break;
case 'Announce':
break;
case 'Undo':
// TODO
break;
}
if ( is_wp_error( $activity ) ) {