Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 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
83cc587
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Jul 18, 2025
2bbaa48
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Jul 24, 2025
122a951
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Sep 9, 2025
7f32440
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Oct 2, 2025
f16bf04
Fix typo in Comment_Utils class reference
pfefferle Oct 2, 2025
f90bdb0
Fix incorrect import and usage of Comment_Util class
pfefferle Oct 2, 2025
11e098c
Improve Undo handler object validation and defaults
pfefferle Oct 3, 2025
8777641
Revert "Improve Undo handler object validation and defaults"
pfefferle Oct 3, 2025
eb9262d
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Oct 23, 2025
0dfe418
Improve Announce activity creation for received comments
pfefferle Oct 23, 2025
1c30a7c
Remove redundant recipient settings in announce activity
pfefferle Oct 23, 2025
a046ba9
Simplify blog actor assignment in comment scheduler
pfefferle Oct 23, 2025
a861977
Update includes/class-dispatcher.php
pfefferle Oct 23, 2025
ba1f84f
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Oct 23, 2025
e2f3a75
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Oct 24, 2025
2f678e0
Merge branch 'trunk' into add/boost-incoming-activities
pfefferle Oct 30, 2025
ab718f0
Prettify
matticbot Oct 30, 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.
5 changes: 3 additions & 2 deletions includes/collection/class-interactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ public static function activity_to_comment( $activity ) {
'comment_date' => \get_date_from_gmt( \gmdate( 'Y-m-d H:i:s', \strtotime( $date ) ) ),
'comment_date_gmt' => \gmdate( 'Y-m-d H:i:s', \strtotime( $date ) ),
'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
57 changes: 55 additions & 2 deletions includes/scheduler/class-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Activitypub\Scheduler;

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

use function Activitypub\add_to_outbox;
Expand Down Expand Up @@ -45,9 +47,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 @@ -81,6 +86,54 @@ public static function schedule_comment_activity( $new_status, $old_status, $com
add_to_outbox( $comment, $type, $comment->user_id );
}

/**
* Announce an interaction.
*
* When a comment is received from another ActivityPub instance and approved,
* this method creates an Announce activity so the blog's followers are notified
* about the 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_Utils::was_received( $comment ) ) {
return;
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get this from the Inbox, instead of saving it in comment meta?
Alternatively, could we use the source_id meta as the object instead of offering the full object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can postpone this a bit until we have the inbox activated by default. PR incoming.


// Validate activity structure.
if ( ! $activity || ! \is_array( $activity ) ) {
return;
}

// Ensure object exists in the activity.
if ( empty( $activity['object'] ) || ! \is_array( $activity['object'] ) ) {
return;
}

// Create the Announce activity.
$announce = new Activity();
$announce->set_type( 'Announce' );
$announce->set_actor( Actors::BLOG_USER_ID );
$announce->set_object( $activity );

// Add to outbox with error handling.
add_to_outbox( $announce, null, Actors::BLOG_USER_ID, ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC );
}

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