Skip to content
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

Send Activity and not its object #1217

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions includes/class-dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Activitypub\Activity\Activity;
use Activitypub\Collection\Actors;
use Activitypub\Collection\Followers;
use Activitypub\Transformer\Factory as Transformer_Factory;

/**
* ActivityPub Dispatcher Class.
Expand Down Expand Up @@ -66,7 +65,7 @@ public static function process_outbox( $id ) {
$activity->set_type( $type );
$activity->set_id( $outbox_item->guid );
// Pre-fill the Activity with data (for example cc and to).
$activity->from_json( $outbox_item->post_content );
$activity->set_object( Activity::init_from_json( $outbox_item->post_content ) );
$activity->set_actor( Actors::get_by_id( $outbox_item->post_author )->get_id() );

// Use simple Object (only ID-URI) for Like and Announce.
Expand Down
25 changes: 24 additions & 1 deletion tests/includes/class-test-dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @coversDefaultClass Activitypub\Dispatcher
*/
class Test_Dispatcher extends WP_UnitTestCase {
class Test_Dispatcher extends \Activitypub\Tests\ActivityPub_Outbox_TestCase {
/**
* Tear down the test case.
*/
Expand Down Expand Up @@ -90,4 +90,27 @@ function ( $name ) {
$result = Dispatcher::maybe_add_inboxes_of_blog_user( $inboxes, 1, $activity );
$this->assertEquals( $inboxes, $result );
}

/**
* Test process_outbox.
*
* @covers ::process_outbox
*/
public function test_process_outbox() {
$post_id = self::factory()->post->create( array( 'post_author' => self::$user_id ) );

$test_callback = function ( $send, $activity ) {
$this->assertInstanceOf( Activity::class, $activity );
$this->assertEquals( 'Create', $activity->get_type() );

return $send;
};
add_filter( 'activitypub_send_activity_to_followers', $test_callback, 10, 2 );

$outbox_item = $this->get_latest_outbox_item( \add_query_arg( 'p', $post_id, \home_url( '/' ) ) );

Dispatcher::process_outbox( $outbox_item->ID );

remove_filter( 'activitypub_send_activity_to_followers', $test_callback );
}
}
Loading