send activities for blog-wide user

This commit is contained in:
Matthias Pfefferle 2023-06-29 19:10:49 +02:00
parent 3e969c859a
commit ced8cd0e29
2 changed files with 22 additions and 14 deletions

View file

@ -68,35 +68,35 @@ class Scheduler {
return;
}
$activitypub_post = new Post( $post );
$activity_type = false;
$type = false;
if ( 'publish' === $new_status && 'publish' !== $old_status ) {
$activity_type = 'Create';
$type = 'Create';
} elseif ( 'publish' === $new_status ) {
$activity_type = 'Update';
$type = 'Update';
} elseif ( 'trash' === $new_status ) {
$activity_type = 'Delete';
$type = 'Delete';
}
if ( ! $activity_type ) {
if ( ! $type ) {
return;
}
// send User activities
if ( ! is_user_disabled( $activitypub_post->get_user_id() ) ) {
if ( ! is_user_disabled( $post->post_author ) ) {
$activitypub_post = new Post( $post );
\wp_schedule_single_event(
\time(),
'activitypub_send_activity',
array( $activitypub_post, $activity_type )
array( $activitypub_post, $type )
);
\wp_schedule_single_event(
\time(),
sprintf(
'activitypub_send_%s_activity',
\strtolower( $activity_type )
\strtolower( $type )
),
array( $activitypub_post )
);
@ -104,19 +104,19 @@ class Scheduler {
// send Blog-User activities
if ( ! is_user_disabled( User_Factory::BLOG_USER_ID ) ) {
$activitypub_post->set_post_author( User_Factory::BLOG_USER_ID );
$activitypub_post = new Post( $post, User_Factory::BLOG_USER_ID );
\wp_schedule_single_event(
\time(),
'activitypub_send_activity',
array( $activitypub_post, $activity_type )
array( $activitypub_post, $type )
);
\wp_schedule_single_event(
\time(),
sprintf(
'activitypub_send_%s_activity',
\strtolower( $activity_type )
\strtolower( $type )
),
array( $activitypub_post )
);

View file

@ -147,9 +147,17 @@ class Post {
* Constructor
*
* @param WP_Post $post
* @param int $post_author
*/
public function __construct( $post ) {
public function __construct( $post, $post_author = null ) {
$this->post = \get_post( $post );
if ( $post_author ) {
$this->post_author = $post_author;
} else {
$this->post_author = $this->post->post_author;
}
$path = sprintf( 'users/%d/followers', intval( $this->get_post_author() ) );
$this->add_to( get_rest_url_by_path( $path ) );
}