diff --git a/templates/welcome.php b/templates/welcome.php
index cb4d05f..02e8be3 100644
--- a/templates/welcome.php
+++ b/templates/welcome.php
@@ -3,8 +3,9 @@
\dirname( __FILE__ ) . '/admin-header.php',
true,
array(
- 'settings' => '',
- 'welcome' => 'active',
+ 'settings' => '',
+ 'welcome' => 'active',
+ 'followers' => '',
)
);
?>
@@ -13,29 +14,65 @@
+
+
+
+
%1$s or the URL %2$s
. Users who can not access this settings page will find their username on the Edit Profile page.',
+ 'People can follow your Blog by using the username %1$s
or the URL %2$s
. This Blog-User will federate all posts written on your Blog, regardless of the User who posted it. You can customize the Blog-User on the Settings page.',
'activitypub'
),
- \esc_attr( \Activitypub\get_webfinger_resource( wp_get_current_user()->ID ) ),
- \esc_url_raw( \get_author_posts_url( wp_get_current_user()->ID ) ),
+ \esc_attr( $blog_user->get_resource() ),
+ \esc_url_raw( $blog_user->get_url() ),
+ \esc_url_raw( \admin_url( '/options-general.php?page=activitypub&tab=settings' ) )
+ ),
+ 'default'
+ );
+ ?>
+
+
+
+
+
+
+
+
+ ID );
+ echo wp_kses(
+ \sprintf(
+ // translators:
+ \__(
+ 'People can also follow you by using your Username %1$s
or your Author-URL %2$s
. Users who can not access this settings page will find their username on the Edit Profile page.',
+ 'activitypub'
+ ),
+ \esc_attr( $user->get_resource() ),
+ \esc_url_raw( $user->get_url() ),
\esc_url_raw( \admin_url( 'profile.php#activitypub' ) )
),
'default'
);
?>
+
+
+
+
Site Health to ensure that your site is compatible and/or use the "Help" tab (in the top right of the settings pages).', 'activitypub' ),
+ \__(
+ 'If you have problems using this plugin, please check the Site Health to ensure that your site is compatible and/or use the "Help" tab (in the top right of the settings pages).',
+ 'activitypub'
+ ),
\esc_url_raw( admin_url( 'site-health.php' ) )
),
'default'
diff --git a/tests/test-class-activitypub-activity-dispatcher.php b/tests/test-class-activitypub-activity-dispatcher.php
index 70ed304..54ebda0 100644
--- a/tests/test-class-activitypub-activity-dispatcher.php
+++ b/tests/test-class-activitypub-activity-dispatcher.php
@@ -34,21 +34,25 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
$pre_http_request = new MockAction();
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
- $activitypub_post = new \Activitypub\Model\Post( $post );
- \Activitypub\Activity_Dispatcher::send_create_activity( $activitypub_post );
-
- $this->assertNotEmpty( $activitypub_post->get_content() );
+ \Activitypub\Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
$this->assertSame( 2, $pre_http_request->get_call_count() );
$all_args = $pre_http_request->get_args();
$first_call_args = array_shift( $all_args );
+
$this->assertEquals( 'https://example.com/author/jon/inbox', $first_call_args[2] );
$second_call_args = array_shift( $all_args );
$this->assertEquals( 'https://example.org/users/username/inbox', $second_call_args[2] );
+ $json = json_decode( $second_call_args[1]['body'] );
+ $this->assertEquals( 'Create', $json->type );
+ $this->assertEquals( 'http://example.org/?author=1', $json->actor );
+ $this->assertEquals( 'http://example.org/?author=1', $json->object->attributedTo );
+
remove_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10 );
}
+
public function test_dispatch_mentions() {
$post = \wp_insert_post(
array(
@@ -76,10 +80,7 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
$pre_http_request = new MockAction();
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
- $activitypub_post = new \Activitypub\Model\Post( $post );
- \Activitypub\Activity_Dispatcher::send_create_activity( $activitypub_post );
-
- $this->assertNotEmpty( $activitypub_post->get_content() );
+ \Activitypub\Activity_Dispatcher::send_activity( get_post( $post ), 'Create' );
$this->assertSame( 1, $pre_http_request->get_call_count() );
$all_args = $pre_http_request->get_args();
@@ -93,6 +94,80 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
remove_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10 );
}
+ public function test_dispatch_announce() {
+ $followers = array( 'https://example.com/author/jon' );
+
+ foreach ( $followers as $follower ) {
+ \Activitypub\Collection\Followers::add_follower( \Activitypub\Collection\Users::BLOG_USER_ID, $follower );
+ }
+
+ $post = \wp_insert_post(
+ array(
+ 'post_author' => 1,
+ 'post_content' => 'hello',
+ )
+ );
+
+ $pre_http_request = new MockAction();
+ add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
+
+ \Activitypub\Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );
+
+ $all_args = $pre_http_request->get_args();
+ $first_call_args = $all_args[0];
+
+ $this->assertSame( 1, $pre_http_request->get_call_count() );
+
+ $user = new \Activitypub\Model\Blog_User();
+
+ $json = json_decode( $first_call_args[1]['body'] );
+ $this->assertEquals( 'Announce', $json->type );
+ $this->assertEquals( $user->get_url(), $json->actor );
+
+ remove_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10 );
+ }
+
+ public function test_dispatch_blog_activity() {
+ $followers = array( 'https://example.com/author/jon' );
+
+ add_filter(
+ 'activitypub_is_single_user',
+ function( $return ) {
+ return true;
+ }
+ );
+
+ foreach ( $followers as $follower ) {
+ \Activitypub\Collection\Followers::add_follower( \Activitypub\Collection\Users::BLOG_USER_ID, $follower );
+ }
+
+ $post = \wp_insert_post(
+ array(
+ 'post_author' => 1,
+ 'post_content' => 'hello',
+ )
+ );
+
+ $pre_http_request = new MockAction();
+ add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
+
+ \Activitypub\Activity_Dispatcher::send_activity_or_announce( get_post( $post ), 'Create' );
+
+ $all_args = $pre_http_request->get_args();
+ $first_call_args = $all_args[0];
+
+ $this->assertSame( 1, $pre_http_request->get_call_count() );
+
+ $user = new \Activitypub\Model\Blog_User();
+
+ $json = json_decode( $first_call_args[1]['body'] );
+ $this->assertEquals( 'Create', $json->type );
+ $this->assertEquals( $user->get_url(), $json->actor );
+ $this->assertEquals( $user->get_url(), $json->object->attributedTo );
+
+ remove_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10 );
+ }
+
public function set_up() {
parent::set_up();
add_filter( 'pre_get_remote_metadata_by_actor', array( get_called_class(), 'pre_get_remote_metadata_by_actor' ), 10, 2 );
diff --git a/tests/test-class-activitypub-activity.php b/tests/test-class-activitypub-activity.php
index 8262f6c..ba9f5a2 100644
--- a/tests/test-class-activitypub-activity.php
+++ b/tests/test-class-activitypub-activity.php
@@ -17,10 +17,11 @@ class Test_Activitypub_Activity extends WP_UnitTestCase {
10
);
- $activitypub_post = new \Activitypub\Model\Post( $post );
+ $activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();
- $activitypub_activity = new \Activitypub\Model\Activity( 'Create' );
- $activitypub_activity->from_post( $activitypub_post );
+ $activitypub_activity = new \Activitypub\Activity\Activity();
+ $activitypub_activity->set_type( 'Create' );
+ $activitypub_activity->set_object( $activitypub_post );
$this->assertContains( \Activitypub\get_rest_url_by_path( 'users/1/followers' ), $activitypub_activity->get_to() );
$this->assertContains( 'https://example.com/alex', $activitypub_activity->get_cc() );
@@ -36,7 +37,7 @@ class Test_Activitypub_Activity extends WP_UnitTestCase {
'content' => 'Hello world!',
);
- $object = \Activitypub\Activity\Base_Object::from_array( $test_array );
+ $object = \Activitypub\Activity\Base_Object::init_from_array( $test_array );
$this->assertEquals( 'Hello world!', $object->get_content() );
$this->assertEquals( $test_array, $object->to_array() );
diff --git a/tests/test-class-activitypub-post.php b/tests/test-class-activitypub-post.php
index 4f1c74e..e995afa 100644
--- a/tests/test-class-activitypub-post.php
+++ b/tests/test-class-activitypub-post.php
@@ -10,13 +10,13 @@ class Test_Activitypub_Post extends WP_UnitTestCase {
$permalink = \get_permalink( $post );
- $activitypub_post = new \Activitypub\Model\Post( $post );
+ $activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();
$this->assertEquals( $permalink, $activitypub_post->get_id() );
\wp_trash_post( $post );
- $activitypub_post = new \Activitypub\Model\Post( $post );
+ $activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();
$this->assertEquals( $permalink, $activitypub_post->get_id() );
}
diff --git a/tests/test-class-activitypub-rest-post-signature-verification.php b/tests/test-class-activitypub-rest-post-signature-verification.php
index f0acd34..97f78f9 100644
--- a/tests/test-class-activitypub-rest-post-signature-verification.php
+++ b/tests/test-class-activitypub-rest-post-signature-verification.php
@@ -10,9 +10,10 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase {
)
);
$remote_actor = \get_author_posts_url( 2 );
- $activitypub_post = new \Activitypub\Model\Post( $post );
- $activitypub_activity = new Activitypub\Model\Activity( 'Create' );
- $activitypub_activity->from_post( $activitypub_post );
+ $activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();
+ $activitypub_activity = new Activitypub\Activity\Activity( 'Create' );
+ $activitypub_activity->set_type( 'Create' );
+ $activitypub_activity->set_object( $activitypub_post );
$activitypub_activity->add_cc( $remote_actor );
$activity = $activitypub_activity->to_json();
@@ -42,7 +43,9 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase {
$signed_headers = $signature_block['headers'];
$signed_data = Activitypub\Signature::get_signed_data( $signed_headers, $signature_block, $headers );
- $public_key = Activitypub\Signature::get_public_key( 1 );
+ $user = Activitypub\Collection\Users::get_by_id( 1 );
+
+ $public_key = $user->get__public_key();
// signature_verification
$verified = \openssl_verify( $signed_data, $signature_block['signature'], $public_key, 'rsa-sha256' ) > 0;
@@ -53,6 +56,8 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase {
add_filter(
'pre_get_remote_metadata_by_actor',
function( $json, $actor ) {
+ $user = Activitypub\Collection\Users::get_by_id( 1 );
+ $public_key = $user->get__public_key();
// return ActivityPub Profile with signature
return array(
'id' => $actor,
@@ -60,7 +65,7 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase {
'publicKey' => array(
'id' => $actor . '#main-key',
'owner' => $actor,
- 'publicKeyPem' => \Activitypub\Signature::get_public_key( 1 ),
+ 'publicKeyPem' => $public_key,
),
);
},
@@ -77,9 +82,10 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase {
);
$remote_actor = \get_author_posts_url( 2 );
$remote_actor_inbox = Activitypub\get_rest_url_by_path( '/inbox' );
- $activitypub_post = new \Activitypub\Model\Post( $post );
- $activitypub_activity = new Activitypub\Model\Activity( 'Create' );
- $activitypub_activity->from_post( $activitypub_post );
+ $activitypub_post = \Activitypub\Transformer\Post::transform( \get_post( $post ) )->to_object();
+ $activitypub_activity = new Activitypub\Activity\Activity();
+ $activitypub_activity->set_type( 'Create' );
+ $activitypub_activity->set_object( $activitypub_post );
$activitypub_activity->add_cc( $remote_actor_inbox );
$activity = $activitypub_activity->to_json();
diff --git a/tests/test-class-db-activitypub-followers.php b/tests/test-class-db-activitypub-followers.php
index 3634713..2f21767 100644
--- a/tests/test-class-db-activitypub-followers.php
+++ b/tests/test-class-db-activitypub-followers.php
@@ -6,42 +6,42 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase {
'url' => 'https://example.org/users/username',
'inbox' => 'https://example.org/users/username/inbox',
'name' => 'username',
- 'prefferedUsername' => 'username',
+ 'preferredUsername' => 'username',
),
'jon@example.com' => array(
'id' => 'https://example.com/author/jon',
'url' => 'https://example.com/author/jon',
'inbox' => 'https://example.com/author/jon/inbox',
'name' => 'jon',
- 'prefferedUsername' => 'jon',
+ 'preferredUsername' => 'jon',
),
'doe@example.org' => array(
'id' => 'https://example.org/author/doe',
'url' => 'https://example.org/author/doe',
'inbox' => 'https://example.org/author/doe/inbox',
'name' => 'doe',
- 'prefferedUsername' => 'doe',
+ 'preferredUsername' => 'doe',
),
'sally@example.org' => array(
'id' => 'http://sally.example.org',
'url' => 'http://sally.example.org',
'inbox' => 'http://sally.example.org/inbox',
'name' => 'jon',
- 'prefferedUsername' => 'jon',
+ 'preferredUsername' => 'jon',
),
'12345@example.com' => array(
'id' => 'https://12345.example.com',
'url' => 'https://12345.example.com',
'inbox' => 'https://12345.example.com/inbox',
'name' => '12345',
- 'prefferedUsername' => '12345',
+ 'preferredUsername' => '12345',
),
'user2@example.com' => array(
'id' => 'https://user2.example.com',
'url' => 'https://user2.example.com',
'inbox' => 'https://user2.example.com/inbox',
'name' => 'user2',
- 'prefferedUsername' => 'user2',
+ 'preferredUsername' => 'user2',
),
);
@@ -223,7 +223,7 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase {
$follower = \Activitypub\Collection\Followers::get_follower( 1, 'http://sally.example.org' );
for ( $i = 1; $i <= 15; $i++ ) {
- add_post_meta( $follower->get__id(), 'errors', 'error ' . $i );
+ add_post_meta( $follower->get__id(), 'activitypub_errors', 'error ' . $i );
}
$follower = \Activitypub\Collection\Followers::get_follower( 1, 'http://sally.example.org' );
@@ -244,6 +244,29 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase {
$this->assertEquals( 0, count( $followers ) );
}
+ public function test_add_duplicate_follower() {
+ $pre_http_request = new MockAction();
+ add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
+
+ $follower = 'https://12345.example.com';
+
+ \Activitypub\Collection\Followers::add_follower( 1, $follower );
+ \Activitypub\Collection\Followers::add_follower( 1, $follower );
+ \Activitypub\Collection\Followers::add_follower( 1, $follower );
+ \Activitypub\Collection\Followers::add_follower( 1, $follower );
+ \Activitypub\Collection\Followers::add_follower( 1, $follower );
+ \Activitypub\Collection\Followers::add_follower( 1, $follower );
+
+ $db_followers = \Activitypub\Collection\Followers::get_followers( 1 );
+
+ $this->assertContains( $follower, $db_followers );
+
+ $follower = current( $db_followers );
+ $meta = get_post_meta( $follower->get__id(), 'activitypub_user_id' );
+
+ $this->assertCount( 1, $meta );
+ }
+
public static function http_request_host_is_external( $in, $host ) {
if ( in_array( $host, array( 'example.com', 'example.org' ), true ) ) {