Skip to content

Commit 62f7b48

Browse files
pfefferlematticbot
andauthored
Fix: (Pixelfed) Follow (#1501)
* Fix: Pixelfed Follow * fix test * Add changelog * cleanup other fields too * Test that `set_to` will not be replaced by object if already set by activity * improve tests props @obenland --------- Co-authored-by: Automattic Bot <sysops+ghmatticbot@automattic.com>
1 parent e394264 commit 62f7b48

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Properly set `to` audience of `Activity` instead of changing the `Follow` Object.

includes/activity/class-activity.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ public function set_object( $data ) {
148148
}
149149

150150
foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) {
151-
$this->set( $i, $data->get( $i ) );
151+
$value = $data->get( $i );
152+
if ( $value && ! $this->get( $i ) ) {
153+
$this->set( $i, $value );
154+
}
152155
}
153156

154157
if ( $data->get_published() && ! $this->get_published() ) {
@@ -163,7 +166,7 @@ public function set_object( $data ) {
163166
$this->set( 'actor', $data->get_attributed_to() );
164167
}
165168

166-
if ( $data->get_in_reply_to() ) {
169+
if ( $data->get_in_reply_to() && ! $this->get_in_reply_to() ) {
167170
$this->set( 'in_reply_to', $data->get_in_reply_to() );
168171
}
169172

includes/handler/class-follow.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Activitypub\Handler;
99

1010
use Activitypub\Notification;
11+
use Activitypub\Activity\Activity;
1112
use Activitypub\Collection\Actors;
1213
use Activitypub\Collection\Followers;
1314

@@ -102,9 +103,12 @@ public static function queue_accept( $actor, $activity_object, $user_id, $follow
102103
)
103104
);
104105

105-
// Send response only to the Follower.
106-
$activity_object['to'] = array( $actor );
106+
$activity = new Activity();
107+
$activity->set_type( 'Accept' );
108+
$activity->set_actor( Actors::get_by_id( $user_id )->get_id() );
109+
$activity->set_object( $activity_object );
110+
$activity->set_to( array( $actor ) );
107111

108-
add_to_outbox( $activity_object, 'Accept', $user_id, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE );
112+
add_to_outbox( $activity, null, $user_id, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE );
109113
}
110114
}

tests/includes/activity/class-test-activity.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Activitypub\Tests\Activity;
99

1010
use Activitypub\Activity\Activity;
11+
use Activitypub\Collection\Actors;
1112
use DMS\PHPUnitExtensions\ArraySubset\Assert;
1213

1314
/**
@@ -132,4 +133,40 @@ public function test_activity_object_id() {
132133

133134
$this->assertTrue( str_starts_with( $activity->get_id(), 'https://example.com/author/123#activity-update-' ) );
134135
}
136+
137+
/**
138+
* Test activity object.
139+
*/
140+
public function test_activity_object_in_reply_to() {
141+
// Create user with `activitypub` capabilities.
142+
$user_id = self::factory()->user->create(
143+
array(
144+
'role' => 'author',
145+
)
146+
);
147+
148+
// Only send minimal data.
149+
$activity_object = array(
150+
'id' => 'https://example.com/post/123',
151+
'type' => 'Follow',
152+
'actor' => 'https://example.com/author/123',
153+
'object' => 'https://example.com/post/123',
154+
'to' => array( 'https://example.com/author/123' ),
155+
);
156+
157+
$activity = new Activity();
158+
$activity->set_type( 'Accept' );
159+
$activity->set_actor( Actors::get_by_id( $user_id )->get_id() );
160+
$activity->set_object( $activity_object );
161+
162+
$this->assertContains( 'https://example.com/author/123', $activity->get_to() );
163+
164+
$activity->set_to( array( 'https://example.com/author/456' ) );
165+
$activity->set_object( $activity_object );
166+
167+
$this->assertContains( 'https://example.com/author/456', $activity->get_to() );
168+
169+
// Delete user.
170+
\wp_delete_user( $user_id );
171+
}
135172
}

tests/includes/handler/class-test-follow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function test_queue_accept() {
115115

116116
$this->assertEquals( 'Follow', $activity_json['object']['type'] );
117117
$this->assertEquals( 'https://example.com/user/1', $activity_json['object']['object'] );
118-
$this->assertEquals( array( $actor ), $activity_json['object']['to'] );
118+
$this->assertEquals( array( $actor ), $activity_json['to'] );
119119
$this->assertEquals( $actor, $activity_json['object']['actor'] );
120120

121121
// Clean up.

0 commit comments

Comments
 (0)