From 4de5612b8c3a842c53aea1c74d5a9ebae515449c Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 4 Sep 2018 00:01:34 -0600 Subject: [PATCH] Implement Follow (outbox) activity --- following.php | 29 +++++++++++++++++++++++++++++ inc/activities/follow.php | 23 +++++++++++++++++++++++ inc/init.php | 2 ++ inc/outbox.php | 2 ++ 4 files changed, 56 insertions(+) create mode 100644 following.php create mode 100644 inc/activities/follow.php diff --git a/following.php b/following.php new file mode 100644 index 0000000..ce688aa --- /dev/null +++ b/following.php @@ -0,0 +1,29 @@ +insert( + 'activitypub_following', + array( 'actor_id' => $actor_id, 'object' => wp_json_encode( $object ) ) + ); +} + +function create_following_table() { + global $wpdb; + $wpdb->query( + " + CREATE TABLE IF NOT EXISTS activitypub_following( + actor_id INT UNSIGNED NOT NULL, + object TEXT NOT NULL, + state VARCHAR(64) NOT NULL, + FOREIGN KEY actor_fk(actor_id) + REFERENCES activitypub_actors(id) + ); + " + ); +} +?> diff --git a/inc/activities/follow.php b/inc/activities/follow.php new file mode 100644 index 0000000..8d276eb --- /dev/null +++ b/inc/activities/follow.php @@ -0,0 +1,23 @@ + 400 ) + ); + } + $object = $activity['object']; + $actor_id = \actors\get_actor_id( $actor ); + $res = \following\request_follow( $actor_id, $object ); + if ( is_wp_error( $res ) ) { + return $res; + } + return $activity; +} +?> diff --git a/inc/init.php b/inc/init.php index 9acf95c..5283d97 100644 --- a/inc/init.php +++ b/inc/init.php @@ -7,6 +7,7 @@ require_once plugin_dir_path( __FILE__ ) . '/objects.php'; require_once plugin_dir_path( __FILE__ ) . '/activities.php'; require_once plugin_dir_path( __FILE__ ) . '/actors.php'; require_once plugin_dir_path( __FILE__ ) . '/likes.php'; +require_once plugin_dir_path( __FILE__ ) . '/following.php'; add_action( 'rest_api_init', function() { \api\register_routes(); @@ -24,5 +25,6 @@ add_action( 'activitypub_init', function() { \actors\create_actors_table(); \actors\initialize_user_actors(); \likes\create_likes_table(); + \following\create_following_table(); } ); ?> diff --git a/inc/outbox.php b/inc/outbox.php index dc112aa..69b5814 100644 --- a/inc/outbox.php +++ b/inc/outbox.php @@ -17,6 +17,7 @@ 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/like.php'; +require_once plugin_dir_path( __FILE__ ) . '/activities/follow.php'; function handle_activity( $actor, $activity ) { // TODO handle authentication/authorization @@ -38,6 +39,7 @@ function handle_activity( $actor, $activity ) { $activity = \activities\delete\handle( $actor, $activity ); break; case 'Follow': + $activity = \activities\follow\handle( $actor, $activity ); break; case 'Add': break;