From 7f3059427db0f48c6f49b278aec6333acd73d1ac Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Mon, 3 Jul 2023 18:18:03 +0200 Subject: [PATCH] fix tests --- includes/class-activity-dispatcher.php | 37 +++++++++++++++----------- includes/functions.php | 14 ++++++---- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/includes/class-activity-dispatcher.php b/includes/class-activity-dispatcher.php index 692c487..e3ce52d 100644 --- a/includes/class-activity-dispatcher.php +++ b/includes/class-activity-dispatcher.php @@ -30,11 +30,11 @@ class Activity_Dispatcher { * Send Activities to followers and mentioned users. * * @param WP_Post $wp_post The ActivityPub Post. - * @param string $activity_type The Activity-Type. + * @param string $type The Activity-Type. * * @return void */ - public static function send_user_activity( WP_Post $wp_post, $activity_type ) { + public static function send_user_activity( WP_Post $wp_post, $type ) { // check if a migration is needed before sending new posts Migration::maybe_migrate(); @@ -42,22 +42,23 @@ class Activity_Dispatcher { return; } - $post = new Post( $wp_post ); + $object = Post::transform( $wp_post )->to_object(); - $activitypub_activity = new Activity( $activity_type ); - $activitypub_activity->from_post( $post ); + $activity = new Activity(); + $activity->set_type( $type ); + $activity->set_object( $object ); $user_id = $wp_post->post_author; $follower_inboxes = Followers::get_inboxes( $user_id ); - $mentioned_inboxes = Mention::get_inboxes( $activitypub_activity->get_cc() ); + $mentioned_inboxes = Mention::get_inboxes( $activity->get_cc() ); $inboxes = array_merge( $follower_inboxes, $mentioned_inboxes ); $inboxes = array_unique( $inboxes ); - $array = $activity->to_json(); + $json = $activity->to_json(); foreach ( $inboxes as $inbox ) { - safe_remote_post( $inbox, $array, $user_id ); + safe_remote_post( $inbox, $json, $user_id ); } } @@ -65,11 +66,11 @@ class Activity_Dispatcher { * Send Activities to followers and mentioned users. * * @param WP_Post $wp_post The ActivityPub Post. - * @param string $activity_type The Activity-Type. + * @param string $type The Activity-Type. * * @return void */ - public static function send_blog_activity( WP_Post $wp_post, $activity_type ) { + public static function send_blog_activity( WP_Post $wp_post, $type ) { // check if a migration is needed before sending new posts Migration::maybe_migrate(); @@ -77,22 +78,26 @@ class Activity_Dispatcher { return; } - $post = new Post( $wp_post, User_Factory::BLOG_USER_ID ); + $user = User_Factory::get_user( User_Factory::BLOG_USER_ID ); - $activitypub_activity = new Activity( $activity_type ); - $activitypub_activity->from_post( $post ); + $object = Post::transform( $wp_post )->to_object(); + $object->set_attributed_to( $user->get_id() ); + + $activity = new Activity(); + $activity->set_type( $type ); + $activity->set_object( $object ); $user_id = User_Factory::BLOG_USER_ID; $follower_inboxes = Followers::get_inboxes( $user_id ); - $mentioned_inboxes = Mention::get_inboxes( $activitypub_activity->get_cc() ); + $mentioned_inboxes = Mention::get_inboxes( $activity->get_cc() ); $inboxes = array_merge( $follower_inboxes, $mentioned_inboxes ); $inboxes = array_unique( $inboxes ); - $array = $activity->to_json(); + $json = $activity->to_json(); foreach ( $inboxes as $inbox ) { - safe_remote_post( $inbox, $array, $user_id ); + safe_remote_post( $inbox, $json, $user_id ); } } } diff --git a/includes/functions.php b/includes/functions.php index 85cf94a..65279cb 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1,23 +1,27 @@