Announce all posts through the application actor
Some checks failed
PHP_CodeSniffer / phpcs (push) Has been cancelled
Unit Testing / phpunit (5.6, 6.2) (push) Has been cancelled
Unit Testing / phpunit (7.0) (push) Has been cancelled
Unit Testing / phpunit (7.2) (push) Has been cancelled
Unit Testing / phpunit (7.3) (push) Has been cancelled
Unit Testing / phpunit (7.4) (push) Has been cancelled
Unit Testing / phpunit (8.0) (push) Has been cancelled
Unit Testing / phpunit (8.1) (push) Has been cancelled
Unit Testing / phpunit (8.2) (push) Has been cancelled
Unit Testing / phpunit (latest) (push) Has been cancelled

This commit is contained in:
André Menrath 2023-12-23 09:52:03 +01:00
parent fb2db28926
commit eb58862777
3 changed files with 32 additions and 8 deletions

View file

@ -10,6 +10,7 @@ use Activitypub\Transformer\Factory;
use Activitypub\Transformer\Post;
use Activitypub\Transformer\Comment;
use function Activitypub\get_rest_url_by_path;
use function Activitypub\is_single_user;
use function Activitypub\is_user_disabled;
use function Activitypub\safe_remote_post;
@ -49,8 +50,10 @@ class Activity_Dispatcher {
if ( is_single_user() ) {
self::send_activity( $wp_object, $type, Users::BLOG_USER_ID );
self::send_announce( $wp_object, $type, Users::APPLICATION_USER_ID );
} else {
self::send_announce( $wp_object, $type );
self::send_announce( $wp_object, $type, Users::BLOG_USER_ID );
self::send_announce( $wp_object, $type, Users::APPLICATION_USER_ID );
}
}
@ -88,21 +91,36 @@ class Activity_Dispatcher {
*
* @return void
*/
public static function send_announce( $wp_object, $type ) {
public static function send_announce( $wp_object, $type, $user_id = null ) {
if ( ! in_array( $type, array( 'Create', 'Update' ), true ) ) {
return;
}
if ( is_user_disabled( Users::BLOG_USER_ID ) ) {
$transformer = Factory::instance()->get_transformer( $wp_object );
if ( null !== $user_id && Users::APPLICATION_USER_ID !== $user_id ) {
$transformer->change_wp_user_id( $user_id );
}
if ( ! $user_id ) {
$user_id = $transformer->get_wp_user_id();
}
if ( is_user_disabled( $user_id ) ) {
return;
}
$transformer = Factory::instance()->get_transformer( $wp_object );
$transformer->change_wp_user_id( Users::BLOG_USER_ID );
$user_id = $transformer->get_wp_user_id();
$activity = $transformer->to_activity( 'Announce' );
// TODO: properly fix this for the instance-to-instance federation with Mobilizon.
// Error:
// Failed to map identity from signature (payload actor mismatch)
// key_id=http://wp.lan/wp-json/activitypub/1.0/application, actor=http://wp.lan/@blog
// Of course, the announce must be sent as the Application actor because he also signed it!
if ( Users::APPLICATION_USER_ID === $user_id ) {
$activity->set_actor( get_rest_url_by_path( 'application' ) );
}
self::send_activity_to_inboxes( $activity, $user_id );
}

View file

@ -7,6 +7,7 @@ use Activitypub\Model\User;
use Activitypub\Model\Blog_User;
use Activitypub\Model\Application_User;
use function Activitypub\get_rest_url_by_path;
use function Activitypub\url_to_authorid;
use function Activitypub\is_user_disabled;
@ -176,6 +177,11 @@ class Users {
return self::get_by_id( self::BLOG_USER_ID );
}
// check for application actor
if ( self::normalize_url( get_rest_url_by_path( 'application' ) ) === self::normalize_url( $resource ) ) {
return self::get_by_id( self::APPLICATION_USER_ID );
}
return new WP_Error(
'activitypub_no_user_found',
\__( 'User not found', 'activitypub' ),

View file

@ -16,7 +16,7 @@ class Followers extends WP_List_Table {
public function __construct() {
if ( get_current_screen()->id === 'settings_page_activitypub' ) {
$this->user_id = Users::BLOG_USER_ID;
$this->user_id = Users::APPLICATION_USER_ID;
} else {
$this->user_id = \get_current_user_id();
}