From ae04ffe71a03274604ada6f21dbb80c4180932cf Mon Sep 17 00:00:00 2001 From: Django Doucet Date: Mon, 13 Nov 2023 09:40:32 -0700 Subject: [PATCH] Rename Server class to Application --- includes/class-application.php | 82 ++++++++++++++++++++++++++++++++++ includes/class-server.php | 34 -------------- 2 files changed, 82 insertions(+), 34 deletions(-) create mode 100644 includes/class-application.php delete mode 100644 includes/class-server.php diff --git a/includes/class-application.php b/includes/class-application.php new file mode 100644 index 0000000..1a5b3a2 --- /dev/null +++ b/includes/class-application.php @@ -0,0 +1,82 @@ + 'publish_posts', + ) + ); + $follower_inboxes_all = []; + foreach ( $authors as $user ) { + $follower_inboxes = Followers::get_inboxes( $user->ID ); + $follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all ); + } + if ( ! is_user_disabled( Users::BLOG_USER_ID ) ) { + $follower_inboxes = Followers::get_inboxes( Users::BLOG_USER_ID ); + $follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all ); + } + return array_unique( array_filter( $follower_inboxes_all ) ); + } + + public static function known_users() { + // at this point we just need known_commenters + // this could get expensive though, eventually it would make sense + // to schedule an add comment_author_url on Follow to a known_users site option + $args = array( + 'user_id' => 0, + 'meta_query' => array( + array( + 'key' => 'protocol', + 'value' => 'activitypub', + 'compare' => '=' + ), + ) + ); + $comment_query = new WP_Comment_Query( $args ); + $known_users_all = []; + foreach ( $comment_query->comments as $user ) { + $known_users_all[] = $user->comment_author_url; + } + return array_unique( array_filter( $known_users_all ) ); + } + + public static function is_actor_delete_request( $request ) { + $json = $request->get_params( 'JSON' ); + if ( 'delete' === $json['type'] && $json['actor'] === $json['object'] ) { + return true; + } + return false; + } + + public static function is_known_actor( $request ) { + $json = $request->get_params( 'JSON' ); + if ( in_array( $json['actor'], self::known_users() ) ) { + return $json['actor']; + } + return false; + } + + public static function delete_remote_actor_comments( $actor ) { + \wp_schedule_single_event( + \time(), + 'activitypub_delete_remote_actor_comments', + array( $actor ) + ); + } +} diff --git a/includes/class-server.php b/includes/class-server.php deleted file mode 100644 index c82dd42..0000000 --- a/includes/class-server.php +++ /dev/null @@ -1,34 +0,0 @@ - 'publish_posts', - ) - ); - $follower_inboxes_all = []; - foreach ( $authors as $user ) { - $follower_inboxes = Followers::get_inboxes( $user->ID ); - $follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all ); - } - if ( ! is_user_disabled( Users::BLOG_USER_ID ) ) { - $follower_inboxes = Followers::get_inboxes( Users::BLOG_USER_ID ); - $follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all ); - } - return array_unique( array_filter( $follower_inboxes_all ) ); - } -}