André Menrath
ddeb5c6cca
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 47s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Failing after 52s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Failing after 54s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 56s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 53s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 52s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Failing after 51s
* Use WP_Post ID of the event source for linking the event source with an cached remote event post * Improve docs * Add tests for retrieving the event_sources list
71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Undo handler file.
|
|
*
|
|
* @package Event_Bridge_For_ActivityPub
|
|
* @since 1.0.0
|
|
* @license AGPL-3.0-or-later */
|
|
|
|
namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
|
|
|
use Activitypub\Collection\Actors;
|
|
use Event_Bridge_For_ActivityPub\Event_Sources;
|
|
use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources as Event_Sources_Collection;
|
|
|
|
use function Activitypub\object_to_uri;
|
|
|
|
/**
|
|
* Handle Uno requests.
|
|
*/
|
|
class Undo {
|
|
/**
|
|
* Initialize the class, registering the handler for incoming `Uno` activities to the ActivityPub plugin.
|
|
*/
|
|
public static function init() {
|
|
\add_action(
|
|
'activitypub_inbox_undo',
|
|
array( self::class, 'handle_undo' ),
|
|
15,
|
|
2
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Handle incoming "Undo" activities.
|
|
*
|
|
* @param array $activity The activity-object.
|
|
* @param int $user_id The id of the local blog-user.
|
|
*/
|
|
public static function handle_undo( $activity, $user_id ) {
|
|
// We only process activities that are target to the blog actor.
|
|
if ( Actors::BLOG_USER_ID !== $user_id ) {
|
|
return;
|
|
}
|
|
|
|
// Check that we are actually following/or have a pending follow request for this actor.
|
|
if ( ! Event_Sources::actor_is_event_source( $activity['actor'] ) ) {
|
|
return;
|
|
}
|
|
|
|
$accept_id = object_to_uri( $activity['object'] );
|
|
|
|
global $wpdb;
|
|
|
|
$results = $wpdb->get_results(
|
|
$wpdb->prepare(
|
|
"SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s",
|
|
'_event_bridge_for_activitypub_accept_of_follow',
|
|
esc_sql( $accept_id )
|
|
)
|
|
);
|
|
|
|
// If no event source with that accept ID is found return.
|
|
if ( empty( $results ) || ! $results ) {
|
|
return;
|
|
}
|
|
|
|
$post_id = reset( $results )->post_id;
|
|
|
|
\delete_post_meta( $post_id, '_event_bridge_for_activitypub_accept_of_follow' );
|
|
}
|
|
}
|