From 1353c89b387377741335e80e386eb97dfd752c46 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Mon, 6 Nov 2023 12:21:46 +0100 Subject: [PATCH] move functions --- includes/class-comments.php | 22 ---------------------- includes/class-scheduler.php | 10 +++++++--- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/includes/class-comments.php b/includes/class-comments.php index 773fa3b..c9ae124 100644 --- a/includes/class-comments.php +++ b/includes/class-comments.php @@ -18,7 +18,6 @@ class Comments { \add_filter( 'comment_post', array( self::class, 'postprocess_comment' ), 10, 3 ); \add_filter( 'comment_reply_link', array( self::class, 'comment_reply_link' ), 10, 4 ); \add_action( 'edit_comment', array( self::class, 'edit_comment' ), 20, 2 ); //schedule_admin_comment_activity - \add_action( 'transition_comment_status', array( self::class, 'schedule_comment_activity' ), 20, 3 ); } /** @@ -133,25 +132,4 @@ class Comments { \wp_schedule_single_event( \time(), 'activitypub_send_activity', array( $wp_comment, 'Update' ) ); } } - - /** - * Schedule Comment Activities - * - * transition_comment_status() - * @param int $comment - */ - public static function schedule_comment_activity( $new_status, $old_status, $activitypub_comment ) { - if ( 'approved' === $new_status && 'approved' !== $old_status ) { - - // Only federate replies from local actors - $ap_object = unserialize( \get_comment_meta( $activitypub_comment->comment_ID, 'ap_object', true ) ); - if ( empty( $ap_object ) ) { - \wp_schedule_single_event( \time(), 'activitypub_send_activity', array( $activitypub_comment, 'Create' ) ); - } - } elseif ( 'trash' === $new_status ) { - \wp_schedule_single_event( \time(), 'activitypub_send_activity', array( $activitypub_comment, 'Delete' ) ); - } elseif ( 'update' === $new_status ) { - \wp_schedule_single_event( \time(), 'activitypub_send_activity', array( $activitypub_comment, 'Update' ) ); - } - } } diff --git a/includes/class-scheduler.php b/includes/class-scheduler.php index 257efc8..582ac8c 100644 --- a/includes/class-scheduler.php +++ b/includes/class-scheduler.php @@ -17,7 +17,7 @@ class Scheduler { */ public static function init() { \add_action( 'transition_post_status', array( self::class, 'schedule_post_activity' ), 33, 3 ); - \add_action( 'transition_comment_status', array( self::class, 'schedule_comment_activity' ), 33, 3 ); + \add_action( 'transition_comment_status', array( self::class, 'schedule_comment_activity' ), 20, 3 ); \add_action( 'activitypub_update_followers', array( self::class, 'update_followers' ) ); \add_action( 'activitypub_cleanup_followers', array( self::class, 'cleanup_followers' ) ); @@ -116,10 +116,14 @@ class Scheduler { } if ( 'approved' === $new_status && 'approved' !== $old_status ) { - \wp_schedule_single_event( \time(), 'activitypub_send_activity', array( $comment, 'Create' ) ); + // Only federate replies from local actors + $activity_object = unserialize( \get_comment_meta( $comment->comment_ID, 'ap_object', true ) ); + if ( empty( $activity_object ) ) { + \wp_schedule_single_event( \time(), 'activitypub_send_activity', array( $comment, 'Create' ) ); + } } elseif ( 'trash' === $new_status ) { \wp_schedule_single_event( \time(), 'activitypub_send_activity', array( $comment, 'Delete' ) ); - } elseif ( $old_status === $new_status ) { + } elseif ( 'update' === $new_status ) { \wp_schedule_single_event( \time(), 'activitypub_send_activity', array( $comment, 'Update' ) ); } }