prepare federation method

This commit is contained in:
Matthias Pfefferle 2023-06-14 15:02:45 +02:00
parent 723a3e3363
commit a8fe587f91
4 changed files with 34 additions and 21 deletions

View file

@ -26,6 +26,8 @@ class Activity_Dispatcher {
\add_action( 'activitypub_send_create_activity', array( self::class, 'send_create_activity' ) ); \add_action( 'activitypub_send_create_activity', array( self::class, 'send_create_activity' ) );
\add_action( 'activitypub_send_update_activity', array( self::class, 'send_update_activity' ) ); \add_action( 'activitypub_send_update_activity', array( self::class, 'send_update_activity' ) );
\add_action( 'activitypub_send_delete_activity', array( self::class, 'send_delete_activity' ) ); \add_action( 'activitypub_send_delete_activity', array( self::class, 'send_delete_activity' ) );
\add_action( 'activitypub_send_activity', array( self::class, 'send_activity' ), 10, 2 );
} }
/** /**
@ -67,13 +69,8 @@ class Activity_Dispatcher {
// check if a migration is needed before sending new posts // check if a migration is needed before sending new posts
Migration::maybe_migrate(); Migration::maybe_migrate();
if ( ! is_single_user_mode() ) {
// send User-Activity
self::send_user_activity( $activitypub_post, $activity_type );
}
// send Blog-User-Activity // send Blog-User-Activity
self::send_user_activity( $activitypub_post, $activity_type, User_Factory::BLOG_USER_ID ); self::send_user_activity( $activitypub_post, $activity_type );
} }
/** /**
@ -92,12 +89,15 @@ class Activity_Dispatcher {
$actor = $user->get_url(); $actor = $user->get_url();
} else { } else {
$user_id = $activitypub_post->get_post_author(); $user_id = $activitypub_post->get_post_author();
$actor = $activitypub_activity->get_actor(); $actor = null;
} }
$activitypub_activity = new Activity( $activity_type ); $activitypub_activity = new Activity( $activity_type );
$activitypub_activity->from_post( $activitypub_post ); $activitypub_activity->from_post( $activitypub_post );
$activitypub_activity->set_actor( $actor );
if ( $actor ) {
$activitypub_activity->set_actor( $actor );
}
$follower_inboxes = Followers::get_inboxes( $user_id ); $follower_inboxes = Followers::get_inboxes( $user_id );
$mentioned_inboxes = Mention::get_inboxes( $activitypub_activity->get_cc() ); $mentioned_inboxes = Mention::get_inboxes( $activitypub_activity->get_cc() );

View file

@ -70,22 +70,29 @@ class Scheduler {
$activitypub_post = new Post( $post ); $activitypub_post = new Post( $post );
$activity_type = false;
if ( 'publish' === $new_status && 'publish' !== $old_status ) { if ( 'publish' === $new_status && 'publish' !== $old_status ) {
\wp_schedule_single_event( $activity_type = 'Create';
\time(),
'activitypub_send_create_activity',
array( $activitypub_post )
);
} elseif ( 'publish' === $new_status ) { } elseif ( 'publish' === $new_status ) {
\wp_schedule_single_event( $activity_type = 'Update';
\time(),
'activitypub_send_update_activity',
array( $activitypub_post )
);
} elseif ( 'trash' === $new_status ) { } elseif ( 'trash' === $new_status ) {
$activity_type = 'Delete';
}
if ( $activity_type ) {
\wp_schedule_single_event( \wp_schedule_single_event(
\time(), \time(),
'activitypub_send_delete_activity', 'activitypub_send_activity',
array( $activitypub_post, $activity_type )
);
\wp_schedule_single_event(
\time(),
sprintf(
'activitypub_send_%s_activity',
\strtolower( $activity_type )
),
array( $activitypub_post ) array( $activitypub_post )
); );
} }

View file

@ -56,9 +56,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
return $actor; return $actor;
} }
$transient_key = 'activitypub_' . $actor;
// only check the cache if needed. // only check the cache if needed.
if ( $cached ) { if ( $cached ) {
$transient_key = 'activitypub_' . $actor;
$metadata = \get_transient( $transient_key ); $metadata = \get_transient( $transient_key );
if ( $metadata ) { if ( $metadata ) {

View file

@ -44,7 +44,12 @@ class Blog_User extends User {
* @return string The User-Description. * @return string The User-Description.
*/ */
public function get_summary() { public function get_summary() {
return \wpautop( \wp_kses( \get_bloginfo( 'description' ), 'default' ) ); return \wpautop(
\wp_kses(
\get_bloginfo( 'description' ),
'default'
)
);
} }
/** /**