Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
37 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
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.
4 changes: 0 additions & 4 deletions includes/activity/class-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ public function pre_fill_activity_from_object() {
$this->set( 'actor', $object->get_attributed_to() );
}

if ( $object->get_in_reply_to() && ! $this->get_in_reply_to() ) {
$this->set( 'in_reply_to', $object->get_in_reply_to() );
}

if ( $object->get_id() && ! $this->get_id() ) {
$id = strtok( $object->get_id(), '#' );
if ( $object->get_updated() ) {
Expand Down
34 changes: 34 additions & 0 deletions includes/class-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public static function init() {
\add_action( 'update_option_activitypub_allow_likes', array( self::class, 'maybe_update_comment_counts' ), 10, 2 );
\add_action( 'update_option_activitypub_allow_reposts', array( self::class, 'maybe_update_comment_counts' ), 10, 2 );
\add_filter( 'pre_wp_update_comment_count_now', array( static::class, 'pre_wp_update_comment_count_now' ), 10, 3 );

\add_action( 'transition_comment_status', array( self::class, 'maybe_announce_interaction' ), 20, 3 );
}

/**
Expand Down Expand Up @@ -804,6 +806,38 @@ public static function pre_wp_update_comment_count_now( $new_count, $old_count,
return $new_count;
}

/**
* 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 ) {
if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
return;
}

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

$comment = \get_comment( $comment );

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

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

if ( ! $activity ) {
return;
}

add_to_outbox( $activity, 'Announce', Actors::BLOG_USER_ID, ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC );
}

/**
* Check if a comment type is enabled.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/class-dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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 @@ -270,8 +270,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
7 changes: 7 additions & 0 deletions includes/collection/class-outbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public static function add( Activity $activity, $user_id, $visibility = ACTIVITY
$object_id = self::get_object_id( $activity );
$title = self::get_object_title( $activity->get_object() );

if ( ! $activity->get_actor() ) {
$activity->set_actor( Actors::get_by_id( $user_id )->get_id() );
}

$outbox_item = array(
'post_type' => self::POST_TYPE,
'post_title' => sprintf(
Expand Down Expand Up @@ -213,6 +217,9 @@ public static function get_activity( $outbox_item ) {

if ( $activity_object['type'] === $type ) {
$activity = Activity::init_from_array( $activity_object );
if ( ! $activity->get_actor() ) {
$activity->set_actor( $actor->get_id() );
}
} else {
$activity = new Activity();
$activity->set_type( $type );
Expand Down
6 changes: 3 additions & 3 deletions tests/includes/collection/class-test-outbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function activity_object_provider() {
),
'Create',
1,
'{"@context":["https:\/\/www.w3.org\/ns\/activitystreams",{"Hashtag":"as:Hashtag","sensitive":"as:sensitive"}],"id":"http:\/\/example.org\/?post_type=ap_outbox\u0026p=351","type":"Create","to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"object":{"id":"https:\/\/example.com\/1","type":"Note","content":"\u003Cp\u003EThis is a note\u003C\/p\u003E","contentMap":{"en":"\u003Cp\u003EThis is a note\u003C\/p\u003E"},"to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"mediaType":"text\/html"}}',
'{"@context":["https:\/\/www.w3.org\/ns\/activitystreams",{"Hashtag":"as:Hashtag","sensitive":"as:sensitive"}],"actor":"http:\/\/example.org\/?author=1","id":"http:\/\/example.org\/?post_type=ap_outbox\u0026p=351","type":"Create","to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"object":{"id":"https:\/\/example.com\/1","type":"Note","content":"\u003Cp\u003EThis is a note\u003C\/p\u003E","contentMap":{"en":"\u003Cp\u003EThis is a note\u003C\/p\u003E"},"to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"mediaType":"text\/html"}}',
),
array(
array(
Expand All @@ -126,7 +126,7 @@ public function activity_object_provider() {
),
'Create',
2,
'{"@context":["https:\/\/www.w3.org\/ns\/activitystreams",{"Hashtag":"as:Hashtag","sensitive":"as:sensitive"}],"id":"http:\/\/example.org\/?post_type=ap_outbox\u0026p=352","type":"Create","to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"object":{"id":"https:\/\/example.com\/2","type":"Note","content":"\u003Cp\u003EThis is another note\u003C\/p\u003E","contentMap":{"en":"\u003Cp\u003EThis is another note\u003C\/p\u003E"},"to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"mediaType":"text\/html"}}',
'{"@context":["https:\/\/www.w3.org\/ns\/activitystreams",{"Hashtag":"as:Hashtag","sensitive":"as:sensitive"}],"actor":"http:\/\/example.org\/?author=0","id":"http:\/\/example.org\/?post_type=ap_outbox\u0026p=352","type":"Create","to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"object":{"id":"https:\/\/example.com\/2","type":"Note","content":"\u003Cp\u003EThis is another note\u003C\/p\u003E","contentMap":{"en":"\u003Cp\u003EThis is another note\u003C\/p\u003E"},"to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"mediaType":"text\/html"}}',
),
array(
Event::init_from_array(
Expand Down Expand Up @@ -163,7 +163,7 @@ public function activity_object_provider() {
),
'Create',
1,
'{"@context":["https:\/\/schema.org\/","https:\/\/www.w3.org\/ns\/activitystreams",{"pt":"https:\/\/joinpeertube.org\/ns#","mz":"https:\/\/joinmobilizon.org\/ns#","status":"http:\/\/www.w3.org\/2002\/12\/cal\/ical#status","commentsEnabled":"pt:commentsEnabled","isOnline":"mz:isOnline","timezone":"mz:timezone","participantCount":"mz:participantCount","anonymousParticipationEnabled":"mz:anonymousParticipationEnabled","joinMode":{"@id":"mz:joinMode","@type":"mz:joinModeType"},"externalParticipationUrl":{"@id":"mz:externalParticipationUrl","@type":"schema:URL"},"repliesModerationOption":{"@id":"mz:repliesModerationOption","@type":"@vocab"},"contacts":{"@id":"mz:contacts","@type":"@id"}}],"id":"http:\/\/example.org\/?post_type=ap_outbox\u0026p=353","type":"Create","to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"object":{"id":"https:\/\/example.com\/3","type":"Event","content":"\u003Cp\u003EYou should not miss this Event!\u003C\/p\u003E","contentMap":{"en":"\u003Cp\u003EYou should not miss this Event!\u003C\/p\u003E"},"name":"WP Test Event","nameMap":{"en":"WP Test Event"},"endTime":"2030-02-29T17:00:00+01:00","location":[{"id":"https:\/\/example.com\/place\/1","type":"Place","attributedTo":"https:\/\/wp-test.event-federation.eu\/@test","name":"Fediverse Place","address":{"type":"PostalAddress","addressCountry":"FediCountry","addressLocality":"FediTown","postalCode":"1337","streetAddress":"FediStreet"}},{"type":"VirtualLocation","url":"https:\/\/example.com\/VirtualMeetingRoom"}],"startTime":"2030-02-29T16:00:00+01:00","to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"mediaType":"text\/html","timezone":"Europe\/Vienna","category":"MOVEMENTS_POLITICS","joinMode":"external"}}',
'{"@context":["https:\/\/schema.org\/","https:\/\/www.w3.org\/ns\/activitystreams",{"pt":"https:\/\/joinpeertube.org\/ns#","mz":"https:\/\/joinmobilizon.org\/ns#","status":"http:\/\/www.w3.org\/2002\/12\/cal\/ical#status","commentsEnabled":"pt:commentsEnabled","isOnline":"mz:isOnline","timezone":"mz:timezone","participantCount":"mz:participantCount","anonymousParticipationEnabled":"mz:anonymousParticipationEnabled","joinMode":{"@id":"mz:joinMode","@type":"mz:joinModeType"},"externalParticipationUrl":{"@id":"mz:externalParticipationUrl","@type":"schema:URL"},"repliesModerationOption":{"@id":"mz:repliesModerationOption","@type":"@vocab"},"contacts":{"@id":"mz:contacts","@type":"@id"}}],"actor":"http:\/\/example.org\/?author=1","id":"http:\/\/example.org\/?post_type=ap_outbox\u0026p=353","type":"Create","to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"object":{"id":"https:\/\/example.com\/3","type":"Event","content":"\u003Cp\u003EYou should not miss this Event!\u003C\/p\u003E","contentMap":{"en":"\u003Cp\u003EYou should not miss this Event!\u003C\/p\u003E"},"name":"WP Test Event","nameMap":{"en":"WP Test Event"},"endTime":"2030-02-29T17:00:00+01:00","location":[{"id":"https:\/\/example.com\/place\/1","type":"Place","attributedTo":"https:\/\/wp-test.event-federation.eu\/@test","name":"Fediverse Place","address":{"type":"PostalAddress","addressCountry":"FediCountry","addressLocality":"FediTown","postalCode":"1337","streetAddress":"FediStreet"}},{"type":"VirtualLocation","url":"https:\/\/example.com\/VirtualMeetingRoom"}],"startTime":"2030-02-29T16:00:00+01:00","to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"mediaType":"text\/html","timezone":"Europe\/Vienna","category":"MOVEMENTS_POLITICS","joinMode":"external"}}',
),
);
}
Expand Down
Loading