diff --git a/inc/activities/reject.php b/inc/activities/reject.php new file mode 100644 index 0000000..fecb0c6 --- /dev/null +++ b/inc/activities/reject.php @@ -0,0 +1,39 @@ + 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; + } + } +} +?> diff --git a/inc/following.php b/inc/following.php index 7a0a43c..7d8cd9b 100644 --- a/inc/following.php +++ b/inc/following.php @@ -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 ); diff --git a/inc/inbox.php b/inc/inbox.php index 3baff52..5cedbb1 100644 --- a/inc/inbox.php +++ b/inc/inbox.php @@ -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 ) ) {