diff --git a/.github/changelog/2236-from-description b/.github/changelog/2236-from-description new file mode 100644 index 000000000..ab6707e9c --- /dev/null +++ b/.github/changelog/2236-from-description @@ -0,0 +1,4 @@ +Significance: minor +Type: fixed + +Improved handling of posts switched to 'local' visibility so they update correctly and can be re-enabled by changing visibility again. diff --git a/includes/functions.php b/includes/functions.php index 8a92a9694..d461f3e00 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -325,11 +325,7 @@ function is_post_disabled( $post ) { return true; } - $visibility = \get_post_meta( $post->ID, 'activitypub_content_visibility', true ); - if ( - ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL === $visibility || - ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE === $visibility || ! \post_type_supports( $post->post_type, 'activitypub' ) || 'private' === $post->post_status || ! empty( $post->post_password ) @@ -337,6 +333,17 @@ function is_post_disabled( $post ) { $disabled = true; } + $visibility = \get_post_meta( $post->ID, 'activitypub_content_visibility', true ); + + if ( + ! $disabled && + \in_array( $visibility, array( ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE ), true ) && + 'federated' !== \get_post_meta( $post->ID, 'activitypub_status', true ) + ) { + // If post wasn't federated, we don't need to send an update with the new visibility. + $disabled = true; + } + /** * Allow plugins to disable posts for ActivityPub. * diff --git a/includes/transformer/class-base.php b/includes/transformer/class-base.php index 6f7f703a1..877174e05 100644 --- a/includes/transformer/class-base.php +++ b/includes/transformer/class-base.php @@ -206,6 +206,10 @@ protected function set_audience( $activity_object ) { case ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE: $activity_object->add_to( $mentions ); $activity_object->add_to( $replied_to ); + break; + case ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL: + $activity_object->add_to( $actor->get_id() ); + $activity_object->add_cc( $actor->get_id() ); } return $activity_object; diff --git a/tests/includes/class-test-query.php b/tests/includes/class-test-query.php index 84fc5442f..376840d79 100644 --- a/tests/includes/class-test-query.php +++ b/tests/includes/class-test-query.php @@ -320,6 +320,11 @@ public function test_post_activity_object() { Query::get_instance()->__destruct(); add_post_meta( self::$post_id, 'activitypub_content_visibility', ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL ); $this->go_to( get_permalink( self::$post_id ) ); + $this->assertNotNull( Query::get_instance()->get_activitypub_object() ); + + Query::get_instance()->__destruct(); + delete_post_meta( self::$post_id, 'activitypub_status' ); + $this->go_to( get_permalink( self::$post_id ) ); $this->assertNull( Query::get_instance()->get_activitypub_object() ); Query::get_instance()->__destruct(); diff --git a/tests/includes/collection/class-test-replies.php b/tests/includes/collection/class-test-replies.php index c4a4ae78c..eb48a0c6c 100644 --- a/tests/includes/collection/class-test-replies.php +++ b/tests/includes/collection/class-test-replies.php @@ -72,6 +72,7 @@ public function test_get_context_collection() { ); // Test with disabled post. + delete_post_meta( $context_post_id, 'activitypub_status' ); add_post_meta( $context_post_id, 'activitypub_content_visibility', ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL ); $this->assertFalse( Replies::get_context_collection( $context_post_id ), 'Should return false for disabled posts' ); delete_post_meta( $context_post_id, 'activitypub_content_visibility' ); diff --git a/tests/includes/transformer/class-test-post.php b/tests/includes/transformer/class-test-post.php index b01f1704d..00c8f3836 100644 --- a/tests/includes/transformer/class-test-post.php +++ b/tests/includes/transformer/class-test-post.php @@ -8,6 +8,7 @@ namespace Activitypub\Tests\Transformer; use Activitypub\Activity\Base_Object; +use Activitypub\Collection\Actors; use Activitypub\Transformer\Post; /** @@ -286,12 +287,15 @@ public function test_content_visibility() { $object = Post::transform( get_post( $post_id ) )->to_object(); $this->assertContains( 'https://www.w3.org/ns/activitystreams#Public', $object->get_cc() ); + \delete_post_meta( $post_id, 'activitypub_status' ); \update_post_meta( $post_id, 'activitypub_content_visibility', ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL ); + $actor = Actors::get_by_id( 1 ); + $this->assertTrue( \Activitypub\is_post_disabled( $post_id ) ); $object = Post::transform( get_post( $post_id ) )->to_object(); - $this->assertEmpty( $object->get_to() ); - $this->assertEmpty( $object->get_cc() ); + $this->assertEquals( array( $actor->get_id() ), $object->get_to() ); + $this->assertEquals( array( $actor->get_id() ), $object->get_cc() ); } /**