fix #23
This commit is contained in:
parent
0fa7fc62f7
commit
13bbfe0501
3 changed files with 25 additions and 5 deletions
|
@ -36,6 +36,7 @@ function activitypub_init() {
|
|||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-outbox.php';
|
||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Outbox', 'register_routes' ) );
|
||||
add_action( 'activitypub_send_post_activity', array( 'Rest_Activitypub_Outbox', 'send_post_activity' ) );
|
||||
add_action( 'activitypub_send_update_activity', array( 'Rest_Activitypub_Outbox', 'send_update_activity' ) );
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-inbox.php';
|
||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Inbox', 'register_routes' ) );
|
||||
|
@ -62,9 +63,7 @@ function activitypub_init() {
|
|||
add_post_type_support( 'page', 'activitypub' );
|
||||
|
||||
$post_types = get_post_types_by_support( 'activitypub' );
|
||||
foreach ( $post_types as $post_type ) {
|
||||
add_action( 'publish_' . $post_type, array( 'Activitypub', 'schedule_post_activity' ) );
|
||||
}
|
||||
add_action( 'transition_post_status', array( 'Activitypub', 'schedule_post_activity' ), 10, 3 );
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-admin.php';
|
||||
add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) );
|
||||
|
|
|
@ -76,7 +76,11 @@ class Activitypub {
|
|||
*
|
||||
* @param int $post_id
|
||||
*/
|
||||
public static function schedule_post_activity( $post_id ) {
|
||||
wp_schedule_single_event( time() + wp_rand( 0, 120 ), 'activitypub_send_post_activity', array( $post_id ) );
|
||||
public static function schedule_post_activity( $new_status, $old_status, $post ) {
|
||||
if ( 'publish' === $new_status && 'publish' !== $old_status ) {
|
||||
wp_schedule_single_event( time() + wp_rand( 0, 120 ), 'activitypub_send_post_activity', array( $post->ID ) );
|
||||
} elseif ( 'publish' === $new_status ) {
|
||||
wp_schedule_single_event( time() + wp_rand( 0, 120 ), 'activitypub_send_update_activity', array( $post->ID ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,4 +124,21 @@ class Rest_Activitypub_Outbox {
|
|||
$response = activitypub_safe_remote_post( $inbox, $activity, $user_id );
|
||||
}
|
||||
}
|
||||
|
||||
public static function send_update_activity( $post_id ) {
|
||||
$post = get_post( $post_id );
|
||||
$user_id = $post->post_author;
|
||||
|
||||
$activitypub_post = new Activitypub_Post( $post );
|
||||
$activitypub_activity = new Activitypub_Activity( 'Update', Activitypub_Activity::TYPE_FULL );
|
||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||
|
||||
$activity = $activitypub_activity->to_json(); // phpcs:ignore
|
||||
|
||||
$followers = Db_Activitypub_Followers::get_followers( $user_id );
|
||||
|
||||
foreach ( activitypub_get_follower_inboxes( $user_id, $followers ) as $inbox ) {
|
||||
$response = activitypub_safe_remote_post( $inbox, $activity, $user_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue