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

Outbox Collection #593

Draft
wants to merge 94 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
5565c26
init
pfefferle Dec 8, 2023
7448cd6
outbox should not be public!
pfefferle Dec 8, 2023
6ac167f
add basic `to_activity` function
pfefferle Dec 11, 2023
704030c
Merge branch 'master' into add/outbox-collection
pfefferle Dec 11, 2023
89ece40
do not allow to instance post transformer
pfefferle Dec 11, 2023
0ba6d7b
Merge branch 'master' into add/outbox-collection
pfefferle Dec 12, 2023
efda4a5
fix tests
pfefferle Dec 12, 2023
1558551
Merge branch 'master' into add/outbox-collection
pfefferle Dec 13, 2023
6edc4b5
Merge branch 'master' into add/outbox-collection
pfefferle Dec 21, 2023
a38c565
Merge branch 'master' into add/outbox-collection
pfefferle Dec 22, 2023
2a3a6c3
Merge branch 'trunk' into add/outbox-collection
pfefferle Sep 27, 2024
5d66494
fix phpcs
pfefferle Sep 27, 2024
b1d260d
revert change
pfefferle Sep 27, 2024
81b0b88
remove unused `use` declarations
pfefferle Sep 27, 2024
8c0c3fa
the handler should not handle outgoing stuff
pfefferle Sep 27, 2024
3eb8ca6
Merge branch 'trunk' into add/outbox-collection
pfefferle Oct 22, 2024
43a3343
Update class-activitypub.php
pfefferle Oct 22, 2024
8746447
fix PHPCS
pfefferle Oct 22, 2024
242dea4
more PHPCS fixes
pfefferle Oct 22, 2024
f64aade
fix namespace issue
pfefferle Oct 22, 2024
5ca19a6
remove unneeded function
pfefferle Oct 22, 2024
9f525b0
fix sticky post endpoint
pfefferle Oct 22, 2024
e0aeefd
no need to check for User-ID
pfefferle Oct 22, 2024
2d3ba4b
Merge branch 'trunk' into add/outbox-collection
pfefferle Oct 23, 2024
1433e4f
Merge branch 'trunk' into add/outbox-collection
pfefferle Oct 23, 2024
943fc02
Merge branch 'trunk' into add/outbox-collection
pfefferle Oct 24, 2024
7f0a227
Merge branch 'trunk' into add/outbox-collection
pfefferle Oct 25, 2024
fb98bd2
Merge branch 'trunk' into add/outbox-collection
pfefferle Oct 26, 2024
945b335
Merge branch 'trunk' into add/outbox-collection
pfefferle Nov 5, 2024
9345991
support JSON and Arrays beside WP_Comments and WP_Posts
pfefferle Nov 5, 2024
d1e9839
fix auto-complete issue
pfefferle Nov 5, 2024
59ab8b9
simplify code.
pfefferle Nov 5, 2024
8133a1c
convert JSON to Activity_Object to not have everything duplicated
pfefferle Nov 5, 2024
0bdb30d
add support for maps and mentions
pfefferle Nov 5, 2024
593740f
Merge branch 'trunk' into add/outbox-collection
pfefferle Nov 7, 2024
748a266
it takes a string (JSON) or an array
pfefferle Nov 12, 2024
db789ff
Merge branch 'trunk' into add/outbox-collection
pfefferle Nov 13, 2024
22aea42
simplified based on the feedback of @obenland
pfefferle Nov 13, 2024
3648062
Merge branch 'add/outbox-collection' of https://github.com/Automattic…
pfefferle Nov 13, 2024
9b20505
rearrange code a bit
pfefferle Nov 14, 2024
617eff7
add missing uses
pfefferle Nov 14, 2024
ad5f35a
fix typo
pfefferle Nov 14, 2024
c1f63b5
add missing uses
pfefferle Nov 14, 2024
193ec0f
Merge branch 'trunk' into add/outbox-collection
pfefferle Nov 14, 2024
b00e64d
Merge branch 'trunk' into add/outbox-collection
pfefferle Nov 20, 2024
b005be7
Merge branch 'trunk' into add/outbox-collection
pfefferle Nov 20, 2024
726729f
Merge branch 'trunk' into add/outbox-collection
pfefferle Nov 20, 2024
ec9d389
Merge branch 'trunk' into add/outbox-collection
pfefferle Nov 21, 2024
37144b8
Merge branch 'trunk' into add/outbox-collection
pfefferle Nov 22, 2024
fe29ea4
Added Changelog-Entry
pfefferle Nov 22, 2024
5b31a6a
Merge branch 'trunk' into add/outbox-collection
pfefferle Dec 5, 2024
8f4f8b1
apply changes from @obenland
pfefferle Dec 6, 2024
f26eb3d
delay scheduling a bit
pfefferle Dec 6, 2024
77f8f06
change scheduling and add possibility to add items to outbox
pfefferle Dec 6, 2024
abef3dc
remove deprecated functions
pfefferle Dec 6, 2024
b93568d
add filter
pfefferle Dec 6, 2024
8d48752
Merge branch 'trunk' into add/outbox-collection
pfefferle Dec 6, 2024
17cc89b
fix indents
pfefferle Dec 6, 2024
535899c
removed deprecated functions
pfefferle Dec 6, 2024
9d8c270
add visibility and normalize autor id
pfefferle Dec 9, 2024
757c8c9
add taxonomies to store actor and actitiy-type informations
pfefferle Dec 11, 2024
400a70a
Merge branch 'trunk' into add/outbox-collection
pfefferle Dec 11, 2024
dd44ee2
Merge branch 'trunk' into add/outbox-collection
pfefferle Dec 11, 2024
451e339
Merge branch 'trunk' into add/outbox-collection
pfefferle Dec 17, 2024
9f81988
Merge branch 'trunk' into add/outbox-collection
obenland Jan 13, 2025
3fc94d3
Fix phpcs
obenland Jan 13, 2025
6589bed
Fix shortcode tests
obenland Jan 14, 2025
fad425e
Update json tests.
obenland Jan 14, 2025
a6e7190
Merge branch 'trunk' into add/outbox-collection
pfefferle Jan 15, 2025
1142be1
move map functions to base transformer
pfefferle Jan 15, 2025
1824b4b
use item instead of wp_object
pfefferle Jan 15, 2025
f9ca53d
protect functions
pfefferle Jan 15, 2025
58a84d9
fix tests and remove legacy tests
pfefferle Jan 15, 2025
c291d03
fix phpcs
pfefferle Jan 15, 2025
1aeb486
add unittests
pfefferle Jan 15, 2025
99a0a48
fix attachment issues and add tests
pfefferle Jan 15, 2025
5d89584
add tests for JSON transformer and fix detected problems
pfefferle Jan 15, 2025
8bea368
fix phpcs issues
pfefferle Jan 15, 2025
1c29caf
add activity-object transformer tests
pfefferle Jan 15, 2025
b654081
simplify code
pfefferle Jan 15, 2025
2077a01
define as global functions
pfefferle Jan 15, 2025
96d1146
re-added setter
pfefferle Jan 15, 2025
f028321
Merge branch 'trunk' into add/outbox-collection
pfefferle Jan 15, 2025
476250c
add content visibility
pfefferle Jan 16, 2025
511b422
fix PHPCS
pfefferle Jan 16, 2025
3720f30
Outbox: Use post meta instead of taxonomies (#1173)
obenland Jan 16, 2025
7e146bf
Update includes/scheduler/class-actor.php
pfefferle Jan 16, 2025
315493a
register content-visibility meta
pfefferle Jan 17, 2025
bb41713
Merge branch 'trunk' into add/outbox-collection
pfefferle Jan 20, 2025
a6cf6d9
Outbox: Update API Endpoint (#1170)
obenland Jan 20, 2025
aa88405
fix unittests
pfefferle Jan 20, 2025
4b2985b
Merge branch 'add/outbox-collection' of https://github.com/Automattic…
pfefferle Jan 20, 2025
8a7b5cc
pending seems to be the better status
pfefferle Jan 20, 2025
2d59047
Revert "pending seems to be the better status"
pfefferle Jan 20, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Outbox queue
* Comment counts get updated when the plugin is activated/deactivated/deleted
* Added a filter to make custom comment types manageable in WP.com Calypso

Expand Down
4 changes: 2 additions & 2 deletions activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
*/
function rest_init() {
Rest\Actors::init();
Rest\Outbox::init();
Rest\Inbox::init();
Rest\Followers::init();
Rest\Following::init();
Rest\Comment::init();
Rest\Server::init();
Rest\Collection::init();
Rest\Post::init();
( new Rest\Interaction_Controller() )->register_routes();
( new Rest\Application_Controller() )->register_routes();
( new Rest\Interaction_Controller() )->register_routes();
( new Rest\Outbox_Controller() )->register_routes();
( new Rest\Webfinger_Controller() )->register_routes();

// Load NodeInfo endpoints only if blog is public.
Expand Down
10 changes: 3 additions & 7 deletions includes/activity/class-base-object.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public static function init_from_json( $json ) {
$array = \json_decode( $json, true );

if ( ! is_array( $array ) ) {
$array = array();
return new WP_Error( 'invalid_json', __( 'Invalid JSON', 'activitypub' ), array( 'status' => 400 ) );
}

return self::init_from_array( $array );
Expand All @@ -600,15 +600,11 @@ public static function init_from_json( $json ) {
*/
public static function init_from_array( $data ) {
if ( ! is_array( $data ) ) {
return new WP_Error( 'invalid_array', __( 'Invalid array', 'activitypub' ), array( 'status' => 404 ) );
return new WP_Error( 'invalid_array', __( 'Invalid array', 'activitypub' ), array( 'status' => 400 ) );
}

$object = new static();

foreach ( $data as $key => $value ) {
$key = camel_to_snake_case( $key );
call_user_func( array( $object, 'set_' . $key ), $value );
}
$object->from_array( $data );

return $object;
}
Expand Down
99 changes: 98 additions & 1 deletion includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Exception;
use Activitypub\Transformer\Factory;
use Activitypub\Collection\Outbox;
use Activitypub\Collection\Followers;
use Activitypub\Collection\Extra_Fields;

Expand Down Expand Up @@ -448,7 +449,7 @@ public static function plugin_update_message( $data ) {
}

/**
* Register the "Followers" Taxonomy.
* Register Custom Post Types.
*/
private static function register_post_types() {
\register_post_type(
Expand Down Expand Up @@ -518,6 +519,102 @@ private static function register_post_types() {
)
);

// Register Outbox Post-Type.
register_post_type(
Outbox::POST_TYPE,
array(
'labels' => array(
'name' => _x( 'Outbox', 'post_type plural name', 'activitypub' ),
'singular_name' => _x( 'Outbox Item', 'post_type single name', 'activitypub' ),
),
'capabilities' => array(
'create_posts' => false,
),
'map_meta_cap' => true,
'public' => true,
'hierarchical' => true,
'rewrite' => false,
'query_var' => false,
'delete_with_user' => true,
'can_export' => true,
'supports' => array(),
)
);

/**
* Register Activity Type meta for Outbox items.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
*/
\register_post_meta(
Outbox::POST_TYPE,
'_activitypub_activity_type',
array(
'type' => 'string',
'description' => 'The type of the activity',
'single' => true,
'sanitize_callback' => function ( $value ) {
$value = ucfirst( strtolower( $value ) );
$schema = array(
'type' => 'string',
'enum' => array( 'Accept', 'Add', 'Announce', 'Arrive', 'Block', 'Create', 'Delete', 'Dislike', 'Flag', 'Follow', 'Ignore', 'Invite', 'Join', 'Leave', 'Like', 'Listen', 'Move', 'Offer', 'Question', 'Reject', 'Read', 'Remove', 'TentativeReject', 'TentativeAccept', 'Travel', 'Undo', 'Update', 'View' ),
'default' => 'Announce',
);

if ( is_wp_error( rest_validate_enum( $value, $schema, '' ) ) ) {
return $schema['default'];
}

return $value;
},
)
);

\register_post_meta(
Outbox::POST_TYPE,
'_activitypub_activity_actor',
array(
'type' => 'integer',
'single' => true,
'sanitize_callback' => function ( $value ) {
$schema = array(
'type' => 'string',
'enum' => array( 'application', 'blog', 'user' ),
'default' => 'user',
);

if ( is_wp_error( rest_validate_enum( $value, $schema, '' ) ) ) {
return $schema['default'];
}

return $value;
},
)
);

\register_post_meta(
Outbox::POST_TYPE,
'activitypub_content_visibility',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'sanitize_callback' => function ( $value ) {
$schema = array(
'type' => 'string',
'enum' => array( ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL ),
'default' => ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC,
);

if ( is_wp_error( rest_validate_enum( $value, $schema, '' ) ) ) {
return $schema['default'];
}

return $value;
},
)
);

// Both User and Blog Extra Fields types have the same args.
$args = array(
'labels' => array(
Expand Down
2 changes: 1 addition & 1 deletion includes/class-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static function should_be_federated( $comment ) {
return false;
}

if ( is_single_user() && \user_can( $user_id, 'publish_posts' ) ) {
if ( is_single_user() && \user_can( $user_id, 'activitypub' ) ) {
// On a single user site, comments by users with the `publish_posts` capability will be federated as the blog user.
$user_id = Actors::BLOG_USER_ID;
}
Expand Down
Loading
Loading