Skip to content

Comment: Send announce for all new comments #1562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 29 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0f4155e
Comment: Send announce for all new comments
pfefferle Apr 10, 2025
bb1ad46
Add changelog
matticbot Apr 10, 2025
adab316
phpcs fix
pfefferle Apr 10, 2025
c167c7c
Merge branch 'add/boost-incoming-activities' of https://github.com/Au…
pfefferle Apr 10, 2025
c069473
activities are normally not in reply to
pfefferle Apr 10, 2025
b1d461c
Set Actor URL!
pfefferle Apr 10, 2025
3fcdf0f
backwards compatibility
pfefferle Apr 10, 2025
ec02ba3
AI test fail
pfefferle Apr 10, 2025
8821578
lemmy sends 400 for "inbox_timeout"
pfefferle Apr 10, 2025
e658a63
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Apr 10, 2025
cccddce
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Apr 10, 2025
592df9b
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Apr 10, 2025
ced037c
move function to scheduler class
pfefferle Apr 11, 2025
c9bdb96
add blog user to audience
pfefferle Apr 11, 2025
fb8938d
add missing namespaces
pfefferle Apr 11, 2025
4a119b3
fix namespace issue
pfefferle Apr 11, 2025
4bd182a
Fix namespaces
pfefferle Apr 11, 2025
3888f57
fix namespace
pfefferle Apr 11, 2025
2af0df3
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Apr 11, 2025
926610b
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Apr 22, 2025
f8261ad
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Apr 22, 2025
39afe00
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Apr 25, 2025
1892e6d
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Apr 30, 2025
a5ceb57
Add `to`
pfefferle Apr 30, 2025
cd6f04c
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle May 6, 2025
cd6e6e3
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle May 14, 2025
c701c90
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle May 14, 2025
70ccddb
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle May 20, 2025
635fdc3
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Jun 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/1562-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Incoming interactions create an Announce activity so other instances get notified about it.
2 changes: 1 addition & 1 deletion includes/class-dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Dispatcher {
* @see https://github.com/tfredrich/RestApiTutorial.com/blob/fd08b0f67f07450521d143b123cd6e1846cb2e3b/content/advanced/responses/retries.md
* @var int[]
*/
public static $retry_error_codes = array( 408, 429, 500, 502, 503, 504 );
public static $retry_error_codes = array( 400, 408, 429, 500, 502, 503, 504 );

/**
* Initialize the class, registering WordPress hooks.
Expand Down
5 changes: 3 additions & 2 deletions includes/collection/class-interactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ public static function activity_to_comment( $activity ) {
'comment_type' => 'comment',
'comment_author_email' => $webfinger,
'comment_meta' => array(
'source_id' => \esc_url_raw( object_to_uri( $activity['object'] ) ),
'protocol' => 'activitypub',
'source_id' => \esc_url_raw( object_to_uri( $activity['object'] ) ),
'protocol' => 'activitypub',
'_activitypub_activity' => $activity,
),
);

Expand Down
51 changes: 49 additions & 2 deletions includes/scheduler/class-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

namespace Activitypub\Scheduler;

use Activitypub\Activity\Activity;
use Activitypub\Collection\Actors;
use Activitypub\Comment as Comment_Util;

use function Activitypub\add_to_outbox;
use function Activitypub\should_comment_be_federated;

Expand Down Expand Up @@ -42,9 +46,12 @@ public static function schedule_comment_activity( $new_status, $old_status, $com
}

$comment = get_comment( $comment );
if ( ! $comment ) {
return;
}

// Federate only comments that are written by a registered user.
if ( ! $comment || ! $comment->user_id ) {
if ( ! $comment->user_id ) {
self::maybe_announce_interaction( $new_status, $old_status, $comment );
return;
}

Expand Down Expand Up @@ -77,6 +84,46 @@ public static function schedule_comment_activity( $new_status, $old_status, $com
add_to_outbox( $comment, $type, $comment->user_id );
}

/**
* Announce an interaction.
*
* @param string $new_status The new comment status.
* @param string $old_status The old comment status.
* @param \WP_Comment $comment The comment object.
*/
public static function maybe_announce_interaction( $new_status, $old_status, $comment ) {
// Only if we're in both Blog and User modes.
if ( ACTIVITYPUB_ACTOR_AND_BLOG_MODE !== \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ) {
return;
}

if ( 'approved' !== $new_status || 'approved' === $old_status ) {
return;
}

if ( ! Comment_Util::was_received( $comment ) ) {
return;
}

// Get activity from comment meta.
$activity = \get_comment_meta( $comment->comment_ID, '_activitypub_activity', true );

if ( ! $activity ) {
return;
}

$activity['cc'][] = Actors::get_by_id( Actors::BLOG_USER_ID )->get_id();
$activity['to'][] = Actors::get_by_id( Actors::BLOG_USER_ID )->get_id();
$activity['object']['cc'][] = Actors::get_by_id( Actors::BLOG_USER_ID )->get_id();
$activity['object']['to'][] = Actors::get_by_id( Actors::BLOG_USER_ID )->get_id();

$announce = new Activity();
$announce->set_type( 'Announce' );
$announce->set_object( $activity );

add_to_outbox( $announce, null, Actors::BLOG_USER_ID, ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC );
}

/**
* Schedule Comment Activities on insert.
*
Expand Down
Loading