From 4668fd55b90f1f259754ae755e248421ee8ca056 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Thu, 16 Jan 2025 17:13:07 +0100 Subject: [PATCH] Augment the ActivityPub New Follower E-Mail --- includes/class-notifications.php | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/includes/class-notifications.php b/includes/class-notifications.php index bcc1a314..ee9acb29 100644 --- a/includes/class-notifications.php +++ b/includes/class-notifications.php @@ -46,6 +46,7 @@ private function register_hooks() { add_action( 'notify_new_friend_request', array( $this, 'notify_new_friend_request' ) ); add_action( 'notify_accepted_friend_request', array( $this, 'notify_accepted_friend_request' ) ); add_action( 'notify_friend_message_received', array( $this, 'notify_friend_message_received' ), 10, 3 ); + add_action( 'activitypub_new_follower_email', array( $this, 'activitypub_new_follower_email' ), 10, 3 ); if ( ! get_user_option( 'friends_no_friend_follower_notification' ) ) { add_action( 'activitypub_followers_post_follow', array( $this, 'activitypub_followers_post_follow' ), 10, 4 ); add_action( 'activitypub_followers_pre_remove_follower', array( $this, 'activitypub_followers_pre_remove_follower' ), 10, 3 ); @@ -357,6 +358,48 @@ public function notify_friend_message_received( User $friend_user, $message, $su $this->send_mail( $user->user_email, $email_title, $email_message ); } + /** + * Augment the ActivityPub new follower e-mail + * + * @param array $actor The actor. + */ + public function activitypub_new_follower_email( $actor ) { + if ( isset( $actor['id'] ) ) { + $url = $actor['id']; + } elseif ( isset( $actor['url'] ) ) { + $url = $actor['url']; + } else { + return; + } + + $url = \ActivityPub\object_to_uri( $url ); + $server = wp_parse_url( $url, PHP_URL_HOST ); + $following = User_Feed::get_by_url( $url ); + if ( ! $following || is_wp_error( $following ) ) { + $following = User_Feed::get_by_url( str_replace( '/users/', '/@', $url ) ); + } + if ( $following && ! is_wp_error( $following ) ) { + $following = $following->get_friend_user(); + } else { + $following = false; + } + echo '

'; + if ( $following ) { + echo esc_html__( 'You are already following them!', 'friends' ); + echo ' '; + // translators: %s is a URL. + echo wp_kses( sprintf( __( 'Go to their friends page to see what they recently posted about.', 'friends' ), esc_url( $following->get_local_friends_page_url() ) ), array( 'a' => array( 'href' => array() ) ) ); + } else { + // translators: %s is a URL. + echo wp_kses( sprintf( __( 'You can view their profile at %s', 'friends' ), '' . esc_url( $url ) . '' ), array( 'a' => array( 'href' => array() ) ) ); + echo '

'; + echo '

'; + // translators: %s is a URL. + echo wp_kses( sprintf( __( 'Maybe you want to follow them back?', 'friends' ), esc_url( add_query_arg( 'url', $url, admin_url( 'admin.php?page=add-friend' ) ) ) ), array( 'a' => array( 'href' => array() ) ) ); + } + echo '

'; + } + /** * Notify of a follower *