diff --git a/inc/activities/block.php b/inc/activities/block.php new file mode 100644 index 0000000..b6e69d4 --- /dev/null +++ b/inc/activities/block.php @@ -0,0 +1,22 @@ + 400 ) + ); + } + $actor_id = \actors\get_actor_id( $actor ); + $res = \blocks\create_block( $actor_id, $activity['object'] ); + if ( is_wp_error( $res ) ) { + return $res; + } + return $activity; +} +?> diff --git a/inc/activities/like.php b/inc/activities/like.php index e6db718..5c3c0eb 100644 --- a/inc/activities/like.php +++ b/inc/activities/like.php @@ -1,5 +1,5 @@ insert( + 'activitypub_blocks', + array( 'actor_id' => $actor_id, 'blocked_actor_url' => $blocked_actor_url ) + ); + if ( !$res ) { + return new \WP_Error( 'db_error', __( 'Error inserting block row', 'activitypub' ) ); + } +} + +function create_blocks_table() { + global $wpdb; + $wpdb->query( + " + CREATE TABLE IF NOT EXISTS activitypub_blocks( + actor_id INT UNSIGNED NOT NULL, + blocked_actor_url TEXT NOT NULL, + FOREIGN KEY actor_fk(actor_id) + REFERENCES activitypub_actors(id) + ); + " + ); +} +?> diff --git a/inc/outbox.php b/inc/outbox.php index 69b5814..e58c205 100644 --- a/inc/outbox.php +++ b/inc/outbox.php @@ -18,6 +18,7 @@ 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/like.php'; require_once plugin_dir_path( __FILE__ ) . '/activities/follow.php'; +require_once plugin_dir_path( __FILE__ ) . '/activities/block.php'; function handle_activity( $actor, $activity ) { // TODO handle authentication/authorization @@ -49,6 +50,7 @@ function handle_activity( $actor, $activity ) { $activity = \activities\like\handle( $actor, $activity ); break; case 'Block': + $activity = \activities\block\handle( $actor, $activity ); break; case 'Undo': break;