Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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 build/social-web/index-rtl.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/social-web/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-commands', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-data-controls', 'wp-date', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-keyboard-shortcuts', 'wp-keycodes', 'wp-primitives', 'wp-private-apis', 'wp-url', 'wp-warning'), 'version' => 'dcd1fc89c94fc175e1b4');
<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-commands', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-data-controls', 'wp-date', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-keyboard-shortcuts', 'wp-keycodes', 'wp-primitives', 'wp-private-apis', 'wp-url', 'wp-warning'), 'version' => '8086815d0b505895bb2c');
1 change: 1 addition & 0 deletions build/social-web/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 40 additions & 40 deletions build/social-web/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/social-web/style-index-rtl.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/social-web/style-index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions includes/class-post-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public static function init() {
\add_action( 'init', array( self::class, 'register_activitypub_post_meta' ), 11 );

\add_action( 'rest_api_init', array( self::class, 'register_ap_actor_rest_field' ) );
\add_action( 'rest_api_init', array( self::class, 'register_ap_post_actor_rest_field' ) );

\add_filter( 'rest_ap_post_query', array( self::class, 'filter_ap_post_by_user' ) );

\add_filter( 'activitypub_get_actor_extra_fields', array( Extra_Fields::class, 'default_actor_extra_fields' ), 10, 2 );

Expand Down Expand Up @@ -574,6 +577,69 @@ public static function register_ap_actor_rest_field() {
);
}

/**
* Register a REST field for the ap_post post type to embed remote actor data.
*/
public static function register_ap_post_actor_rest_field() {
\register_rest_field(
Posts::POST_TYPE,
'actor',
array(
/**
* Get the remote actor data for an ap_post.
*
* @param array $response Prepared response array.
* @return array|null The actor data or null if not found.
*/
'get_callback' => function ( $response ) {
$id = \get_post_meta( $response['id'], '_activitypub_remote_actor_id', true );
$actor = Remote_Actors::get( $id );

if ( \is_wp_error( $actor ) ) {
return null;
}

return $actor;
},
'schema' => array(
'description' => 'Remote actor data',
'type' => 'object',
'context' => array( 'view', 'edit' ),
),
)
);
}

/**
* Filter ap_post REST query to only show posts for the current user.
*
* @param array $args Query arguments.
*
* @return array Modified query arguments.
*/
public static function filter_ap_post_by_user( $args ) {
$user_id = \get_current_user_id();

if ( ! $user_id ) {
// If no user is logged in, return empty results.
$args['post__in'] = array( 0 );
return $args;
}

// Add meta query to filter by _activitypub_user_id.
if ( ! isset( $args['meta_query'] ) ) {
$args['meta_query'] = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
}

$args['meta_query'][] = array(
'key' => '_activitypub_user_id',
'value' => $user_id,
'compare' => '=',
);

return $args;
}

/**
* Prevent empty or default meta values.
*
Expand Down
11 changes: 11 additions & 0 deletions includes/collection/class-remote-actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ public static function get_inboxes() {
return $inboxes;
}

/**
* Get an Remote Actor from the collection.
*
* @param int $id The object ID.
*
* @return \WP_Post|null The post object or null on failure.
*/
public static function get( $id ) {
return \get_post( $id );
}

/**
* Upsert (insert or update) a remote actor as a custom post type.
*
Expand Down
26 changes: 22 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@wordpress/primitives": "^4.31.0",
"@wordpress/scripts": "^30.23.0",
"@wordpress/url": "^4.22.0",
"@wordpress/views": "^1.0.0",
"@wordpress/viewport": "^6.32.0",
"prettier": "npm:wp-prettier@^3.0.3"
},
Expand Down
16 changes: 16 additions & 0 deletions src/social-web/components/fields/author.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { __ } from '@wordpress/i18n';
import type { Field } from '@wordpress/dataviews';
import type { FeedPost } from '../../types';

export const authorField: Field< FeedPost > = {
id: 'actor.post_title',
label: __( 'Author', 'activitypub' ),
enableHiding: false,
enableSorting: false,
enableGlobalSearch: true,
getValue: ( { item }: { item: FeedPost } ) => {
// DataViews will automatically extract actor.post_title using dot notation
// but we provide a fallback getValue for consistency
return ( item as any ).actor?.post_title || '';
},
};
Loading
Loading