Implement Block activity
This commit is contained in:
parent
4de5612b8c
commit
3c2ce17455
22
inc/activities/block.php
Normal file
22
inc/activities/block.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace activities\block;
|
||||
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../blocks.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../actors.php';
|
||||
|
||||
function handle( $actor, $activity ) {
|
||||
if ( !array_key_exists( 'object', $activity ) ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
__( 'Expected an object', 'activitypub' ),
|
||||
array( 'status' => 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;
|
||||
}
|
||||
?>
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace activites\like;
|
||||
namespace activities\like;
|
||||
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../likes.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/../actors.php';
|
||||
|
34
inc/blocks.php
Normal file
34
inc/blocks.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace blocks;
|
||||
|
||||
/*
|
||||
If an actor is in another actor's block list, any activities
|
||||
from the blocked actor that go into the blocking actors' inbox
|
||||
get ignored
|
||||
*/
|
||||
|
||||
function create_block( $actor_id, $blocked_actor_url ) {
|
||||
global $wpdb;
|
||||
$res = $wpdb->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)
|
||||
);
|
||||
"
|
||||
);
|
||||
}
|
||||
?>
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user