diff --git a/includes/functions.php b/includes/functions.php index fea1821..0fd9276 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -2,6 +2,7 @@ namespace Activitypub; use WP_Error; +use WP_Comment_Query; use Activitypub\Http; use Activitypub\Activity\Activity; use Activitypub\Collection\Followers; @@ -622,3 +623,29 @@ function get_total_users() { return $users + 1; } + +/** + * Examine a comment ID and look up an existing comment it represents. + * + * @param string $id ActivityPub object ID (usually a URL) to check. + * + * @return int|boolean Comment ID, or false on failure. + */ +function object_id_to_comment( $id ) { + $comment_query = new WP_Comment_Query( + array( + 'meta_key' => 'source_id', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key + 'meta_value' => $id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value + ) + ); + + if ( ! $comment_query->comments ) { + return false; + } + + if ( count( $comment_query->comments ) > 1 ) { + return false; + } + + return $comment_query->comments[0]; +} diff --git a/includes/handler/class-delete.php b/includes/handler/class-delete.php index d4530c9..a33ffdd 100644 --- a/includes/handler/class-delete.php +++ b/includes/handler/class-delete.php @@ -21,7 +21,11 @@ class Delete { * @param int $user_id The ID of the user performing the delete activity. */ public function handle_delete( $activity, $user_id ) { - if ( ! isset( $activity['object'] ) || ! is_array( $activity['object'] ) ) { + if ( + ! isset( $activity['object'] ) || + ! is_array( $activity['object'] ) || + ! isset( $activity['object']['id'] ) + ) { return; } @@ -33,7 +37,10 @@ class Delete { case 'Organization': case 'Service': case 'Application': - Followers::remove_follower( $activity['object']['id'], $user_id ); + $follower = Followers::get_follower( $user_id, $activity['actor'] ); + if ( $follower ) { + $follower->delete(); + } break; case 'Tombstone': diff --git a/includes/handler/class-undo.php b/includes/handler/class-undo.php index 9c68924..7d39868 100644 --- a/includes/handler/class-undo.php +++ b/includes/handler/class-undo.php @@ -23,6 +23,7 @@ class Undo { public static function handle_undo( $activity, $user_id ) { if ( isset( $activity['object'] ) && + isset( $activity['actor'] ) && isset( $activity['object']['type'] ) && 'Follow' === $activity['object']['type'] ) {