André Menrath
03b6a8e598
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
- the application actor is managed manually by default - no admin-options are included yet - the old new follower table only is used hardcoded by the application actor - no admin notifications are send yet - todo: a lot more
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
namespace Activitypub\Handler;
|
|
|
|
use Activitypub\Collection\Users;
|
|
use Activitypub\Model\Follow_Request;
|
|
|
|
/**
|
|
* Handle Undo requests
|
|
*/
|
|
class Undo {
|
|
/**
|
|
* Initialize the class, registering WordPress hooks
|
|
*/
|
|
public static function init() {
|
|
\add_action(
|
|
'activitypub_inbox_undo',
|
|
array( self::class, 'handle_undo' )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Handle "Unfollow" requests
|
|
*
|
|
* @param array $activity The JSON "Undo" Activity
|
|
* @param int $user_id The ID of the ID of the WordPress User
|
|
*/
|
|
public static function handle_undo( $activity ) {
|
|
if (
|
|
isset( $activity['object']['type'] ) &&
|
|
'Follow' === $activity['object']['type'] &&
|
|
isset( $activity['object']['object'] ) &&
|
|
filter_var( $activity['object']['object'], FILTER_VALIDATE_URL )
|
|
) {
|
|
$user = Users::get_by_resource( $activity['object']['object'] );
|
|
|
|
if ( ! $user || is_wp_error( $user ) ) {
|
|
// If we can not find a user,
|
|
// we can not initiate a follow process
|
|
return;
|
|
}
|
|
|
|
$follow_request = Follow_Request::get_from_array( $activity['object'] );
|
|
$follow_request->delete();
|
|
}
|
|
}
|
|
}
|