From ba3bd39fd4b2d85f49a70168df94368050e5b8cf Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 10 Apr 2025 15:44:44 +0200 Subject: [PATCH 1/3] fix/outbox-activities --- includes/activity/class-activity.php | 4 ---- includes/collection/class-outbox.php | 7 +++++++ tests/includes/collection/class-test-outbox.php | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/includes/activity/class-activity.php b/includes/activity/class-activity.php index f9da8b26f..7eade851b 100644 --- a/includes/activity/class-activity.php +++ b/includes/activity/class-activity.php @@ -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() ) { diff --git a/includes/collection/class-outbox.php b/includes/collection/class-outbox.php index f610ea6b5..cf1dff89f 100644 --- a/includes/collection/class-outbox.php +++ b/includes/collection/class-outbox.php @@ -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( @@ -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 ); diff --git a/tests/includes/collection/class-test-outbox.php b/tests/includes/collection/class-test-outbox.php index fc4ee1335..e03117468 100644 --- a/tests/includes/collection/class-test-outbox.php +++ b/tests/includes/collection/class-test-outbox.php @@ -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( @@ -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( @@ -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"}}', ), ); } From 4b939cabc380f381b46cd99210cfdaa57cdcce94 Mon Sep 17 00:00:00 2001 From: Automattic Bot Date: Thu, 10 Apr 2025 16:49:58 +0300 Subject: [PATCH 2/3] Add changelog --- .github/changelog/1564-from-description | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/changelog/1564-from-description diff --git a/.github/changelog/1564-from-description b/.github/changelog/1564-from-description new file mode 100644 index 000000000..52b102073 --- /dev/null +++ b/.github/changelog/1564-from-description @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Ensure that an `Activity` has an `Actor` before adding it to the Outbox. From cda68372a944417e121762b715d1b1d839b1c258 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 10 Apr 2025 16:13:19 +0200 Subject: [PATCH 3/3] be more specific --- includes/activity/class-activity.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/activity/class-activity.php b/includes/activity/class-activity.php index 7eade851b..b4623ac26 100644 --- a/includes/activity/class-activity.php +++ b/includes/activity/class-activity.php @@ -233,6 +233,10 @@ public function pre_fill_activity_from_object() { $this->set( 'actor', $object->get_attributed_to() ); } + if ( $this->get_type() !== 'Announce' && $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() ) {