Skip to content

Commit 0f4155e

Browse files
committed
Comment: Send announce for all new comments
Supersedes #1515 and fixes #1001
1 parent 4293ba4 commit 0f4155e

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

includes/class-comment.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public static function init() {
3333
\add_action( 'update_option_activitypub_allow_likes', array( self::class, 'maybe_update_comment_counts' ), 10, 2 );
3434
\add_action( 'update_option_activitypub_allow_reposts', array( self::class, 'maybe_update_comment_counts' ), 10, 2 );
3535
\add_filter( 'pre_wp_update_comment_count_now', array( static::class, 'pre_wp_update_comment_count_now' ), 10, 3 );
36+
37+
\add_action( 'transition_comment_status', array( self::class, 'maybe_announce_interaction' ), 20, 3 );
3638
}
3739

3840
/**
@@ -804,6 +806,38 @@ public static function pre_wp_update_comment_count_now( $new_count, $old_count,
804806
return $new_count;
805807
}
806808

809+
/**
810+
* Announce an interaction.
811+
*
812+
* @param string $new_status The new comment status.
813+
* @param string $old_status The old comment status.
814+
* @param \WP_Comment $comment The comment object.
815+
*/
816+
public static function maybe_announce_interaction( $new_status, $old_status, $comment ) {
817+
if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
818+
return;
819+
}
820+
821+
if ( 'approved' !== $new_status || 'approved' === $old_status ) {
822+
return;
823+
}
824+
825+
$comment = \get_comment( $comment );
826+
827+
if ( ! self::was_received( $comment ) ) {
828+
return;
829+
}
830+
831+
// get activity from comment meta
832+
$activity = \get_comment_meta( $comment->comment_ID, '_activitypub_activity', true );
833+
834+
if ( ! $activity ) {
835+
return;
836+
}
837+
838+
add_to_outbox( $activity, 'Announce', Actors::BLOG_USER_ID, ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC );
839+
}
840+
807841
/**
808842
* Check if a comment type is enabled.
809843
*

includes/collection/class-interactions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ public static function activity_to_comment( $activity ) {
270270
'comment_type' => 'comment',
271271
'comment_author_email' => $webfinger,
272272
'comment_meta' => array(
273-
'source_id' => \esc_url_raw( object_to_uri( $activity['object'] ) ),
274-
'protocol' => 'activitypub',
273+
'source_id' => \esc_url_raw( object_to_uri( $activity['object'] ) ),
274+
'protocol' => 'activitypub',
275+
'_activitypub_activity' => $activity,
275276
),
276277
);
277278

0 commit comments

Comments
 (0)