Skip to content
Closed
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
4 changes: 4 additions & 0 deletions .github/changelog/2236-from-description
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 11 additions & 4 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,25 @@ 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 )
) {
$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.
*
Expand Down
4 changes: 4 additions & 0 deletions includes/transformer/class-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions tests/includes/class-test-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/includes/collection/class-test-replies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
8 changes: 6 additions & 2 deletions tests/includes/transformer/class-test-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Activitypub\Tests\Transformer;

use Activitypub\Activity\Base_Object;
use Activitypub\Collection\Actors;
use Activitypub\Transformer\Post;

/**
Expand Down Expand Up @@ -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() );
}

/**
Expand Down