Skip to content

Commit

Permalink
Actors: deprecate as User_Collection throughout (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwiebe authored Nov 27, 2024
1 parent f1244e7 commit 9beea62
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improved

* More User -> Actor renaming
* Outsource Constants to a separate file
* Better handling of `readme.txt` and `README.md`

Expand Down
10 changes: 5 additions & 5 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Activitypub;

use Activitypub\Collection\Followers;
use Activitypub\Collection\Actors as User_Collection;
use Activitypub\Collection\Actors;

/**
* Block class.
Expand Down Expand Up @@ -161,7 +161,7 @@ private static function get_user_id( $user_string ) {

// If the user string is 'site', return the Blog User ID.
if ( 'site' === $user_string ) {
return User_Collection::BLOG_USER_ID;
return Actors::BLOG_USER_ID;
}

// The only other value should be 'inherit', which means to use the query context to determine the User.
Expand All @@ -171,7 +171,7 @@ private static function get_user_id( $user_string ) {

// For a homepage/front page, if the Blog User is active, use it.
if ( ( is_front_page() || is_home() ) && ! is_user_type_disabled( 'blog' ) ) {
return User_Collection::BLOG_USER_ID;
return Actors::BLOG_USER_ID;
}

// If we're in a loop, use the post author.
Expand Down Expand Up @@ -219,7 +219,7 @@ protected static function filter_array_by_keys( $data, $keys ) {
*/
public static function render_follow_me_block( $attrs ) {
$user_id = self::get_user_id( $attrs['selectedUser'] );
$user = User_Collection::get_by_id( $user_id );
$user = Actors::get_by_id( $user_id );
if ( is_wp_error( $user ) ) {
if ( 'inherit' === $attrs['selectedUser'] ) {
// If the user is 'inherit' and we couldn't determine the user, don't render anything.
Expand Down Expand Up @@ -259,7 +259,7 @@ public static function render_follower_block( $attrs ) {
return '<!-- Followers block: `inherit` mode does not display on this type of page -->';
}

$user = User_Collection::get_by_id( $followee_user_id );
$user = Actors::get_by_id( $followee_user_id );
if ( is_wp_error( $user ) ) {
return '<!-- Followers block: `' . $followee_user_id . '` not an active ActivityPub user -->';
}
Expand Down
4 changes: 2 additions & 2 deletions includes/collection/class-actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
*/
class Actors {
/**
* The ID of the Blog Actor.
* The ID of the Blog User.
*
* @var int
*/
const BLOG_USER_ID = 0;

/**
* The ID of the Application Actor.
* The ID of the Application User.
*
* @var int
*/
Expand Down
6 changes: 3 additions & 3 deletions includes/rest/class-actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use WP_REST_Request;
use WP_REST_Response;
use Activitypub\Webfinger;
use Activitypub\Collection\Actors as User_Collection;
use Activitypub\Collection\Actors as Actor_Collection;

use function Activitypub\is_activitypub_request;

Expand Down Expand Up @@ -74,7 +74,7 @@ public static function register_routes() {
*/
public static function get( $request ) {
$user_id = $request->get_param( 'user_id' );
$user = User_Collection::get_by_various( $user_id );
$user = Actor_Collection::get_by_various( $user_id );

if ( is_wp_error( $user ) ) {
return $user;
Expand Down Expand Up @@ -114,7 +114,7 @@ public static function get( $request ) {
public static function remote_follow_get( WP_REST_Request $request ) {
$resource = $request->get_param( 'resource' );
$user_id = $request->get_param( 'user_id' );
$user = User_Collection::get_by_various( $user_id );
$user = Actor_Collection::get_by_various( $user_id );

if ( is_wp_error( $user ) ) {
return $user;
Expand Down
10 changes: 5 additions & 5 deletions includes/rest/class-collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Activitypub\Collection\Replies;
use Activitypub\Transformer\Factory;
use Activitypub\Activity\Base_Object;
use Activitypub\Collection\Actors as User_Collection;
use Activitypub\Collection\Actors;

use function Activitypub\esc_hashtag;
use function Activitypub\is_single_user;
Expand Down Expand Up @@ -154,7 +154,7 @@ public static function replies_get( $request ) {
*/
public static function tags_get( $request ) {
$user_id = $request->get_param( 'user_id' );
$user = User_Collection::get_by_various( $user_id );
$user = Actors::get_by_various( $user_id );

if ( is_wp_error( $user ) ) {
return $user;
Expand Down Expand Up @@ -206,15 +206,15 @@ public static function tags_get( $request ) {
*/
public static function featured_get( $request ) {
$user_id = $request->get_param( 'user_id' );
$user = User_Collection::get_by_various( $user_id );
$user = Actors::get_by_various( $user_id );

if ( is_wp_error( $user ) ) {
return $user;
}

$sticky_posts = \get_option( 'sticky_posts' );

if ( ! is_single_user() && User_Collection::BLOG_USER_ID === $user->get__id() ) {
if ( ! is_single_user() && Actors::BLOG_USER_ID === $user->get__id() ) {
$posts = array();
} elseif ( $sticky_posts && is_array( $sticky_posts ) ) {
// only show public posts.
Expand Down Expand Up @@ -278,7 +278,7 @@ public static function moderators_get() {
'orderedItems' => array(),
);

$users = User_Collection::get_collection();
$users = Actors::get_collection();

foreach ( $users as $user ) {
$response['orderedItems'][] = $user->get_id();
Expand Down
4 changes: 2 additions & 2 deletions includes/rest/class-followers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use stdClass;
use WP_REST_Server;
use WP_REST_Response;
use Activitypub\Collection\Actors as User_Collection;
use Activitypub\Collection\Actors;
use Activitypub\Collection\Followers as Follower_Collection;

use function Activitypub\get_rest_url_by_path;
Expand Down Expand Up @@ -58,7 +58,7 @@ public static function register_routes() {
*/
public static function get( $request ) {
$user_id = $request->get_param( 'user_id' );
$user = User_Collection::get_by_various( $user_id );
$user = Actors::get_by_various( $user_id );

if ( is_wp_error( $user ) ) {
return $user;
Expand Down
6 changes: 3 additions & 3 deletions includes/rest/class-following.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Activitypub\Rest;

use WP_REST_Response;
use Activitypub\Collection\Actors as User_Collection;
use Activitypub\Collection\Actors;

use function Activitypub\is_single_user;
use function Activitypub\get_rest_url_by_path;
Expand Down Expand Up @@ -58,7 +58,7 @@ public static function register_routes() {
*/
public static function get( $request ) {
$user_id = $request->get_param( 'user_id' );
$user = User_Collection::get_by_various( $user_id );
$user = Actors::get_by_various( $user_id );

if ( is_wp_error( $user ) ) {
return $user;
Expand Down Expand Up @@ -128,7 +128,7 @@ public static function default_following( $follow_list, $user ) {
return $follow_list;
}

$users = User_Collection::get_collection();
$users = Actors::get_collection();

foreach ( $users as $user ) {
$follow_list[] = $user->get_id();
Expand Down
6 changes: 3 additions & 3 deletions includes/rest/class-inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use WP_REST_Server;
use WP_REST_Response;
use Activitypub\Activity\Activity;
use Activitypub\Collection\Actors as User_Collection;
use Activitypub\Collection\Actors;

use function Activitypub\get_context;
use function Activitypub\url_to_authorid;
Expand Down Expand Up @@ -78,7 +78,7 @@ public static function register_routes() {
*/
public static function user_inbox_get( $request ) {
$user_id = $request->get_param( 'user_id' );
$user = User_Collection::get_by_various( $user_id );
$user = Actors::get_by_various( $user_id );

if ( is_wp_error( $user ) ) {
return $user;
Expand Down Expand Up @@ -129,7 +129,7 @@ public static function user_inbox_get( $request ) {
*/
public static function user_inbox_post( $request ) {
$user_id = $request->get_param( 'user_id' );
$user = User_Collection::get_by_various( $user_id );
$user = Actors::get_by_various( $user_id );

if ( is_wp_error( $user ) ) {
return $user;
Expand Down
4 changes: 2 additions & 2 deletions includes/rest/class-outbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use WP_REST_Server;
use WP_REST_Response;
use Activitypub\Activity\Activity;
use Activitypub\Collection\Actors as User_Collection;
use Activitypub\Collection\Actors;
use Activitypub\Transformer\Factory;

use function Activitypub\get_context;
Expand Down Expand Up @@ -59,7 +59,7 @@ public static function register_routes() {
*/
public static function user_outbox_get( $request ) {
$user_id = $request->get_param( 'user_id' );
$user = User_Collection::get_by_various( $user_id );
$user = Actors::get_by_various( $user_id );

if ( is_wp_error( $user ) ) {
return $user;
Expand Down
6 changes: 3 additions & 3 deletions integration/class-webfinger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Activitypub\Integration;

use Activitypub\Collection\Actors as User_Collection;
use Activitypub\Collection\Actors;

use function Activitypub\get_rest_url_by_path;

Expand Down Expand Up @@ -35,7 +35,7 @@ public static function init() {
* @return array The jrd array.
*/
public static function add_user_discovery( $jrd, $uri, $user ) {
$user = User_Collection::get_by_id( $user->ID );
$user = Actors::get_by_id( $user->ID );

if ( ! $user || is_wp_error( $user ) ) {
return $jrd;
Expand Down Expand Up @@ -72,7 +72,7 @@ public static function add_user_discovery( $jrd, $uri, $user ) {
* @return array|\WP_Error The jrd array or WP_Error.
*/
public static function add_pseudo_user_discovery( $jrd, $uri ) {
$user = User_Collection::get_by_resource( $uri );
$user = Actors::get_by_resource( $uri );

if ( \is_wp_error( $user ) ) {
return $user;
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ For reasons of data protection, it is not possible to see the followers of other

= Dev =

* Improved: More User -> Actor renaming
* Fixed: editor error when switching to edit a synced Pattern
* Added: A `pre_activitypub_get_upload_baseurl` filter
* Added: Fediverse Preview on post-overview page
Expand Down

0 comments on commit 9beea62

Please sign in to comment.