2023-11-08 16:46:02 +01:00
|
|
|
<?php
|
|
|
|
namespace Activitypub\Handler;
|
|
|
|
|
|
|
|
use Activitypub\Collection\Followers;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles Delete requests.
|
|
|
|
*/
|
|
|
|
class Delete {
|
|
|
|
/**
|
|
|
|
* Initialize the class, registering WordPress hooks
|
|
|
|
*/
|
|
|
|
public static function init() {
|
|
|
|
\add_action( 'activitypub_inbox_delete', array( self::class, 'handle_delete' ), 10, 2 );
|
2023-11-13 16:58:04 +01:00
|
|
|
//
|
2023-11-08 16:46:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles "Delete" requests.
|
|
|
|
*
|
|
|
|
* @param array $activity The delete activity.
|
|
|
|
* @param int $user_id The ID of the user performing the delete activity.
|
|
|
|
*/
|
|
|
|
public function handle_delete( $activity, $user_id ) {
|
2023-11-10 19:29:07 +01:00
|
|
|
if (
|
|
|
|
! isset( $activity['object'] ) ||
|
|
|
|
! is_array( $activity['object'] ) ||
|
|
|
|
! isset( $activity['object']['id'] )
|
|
|
|
) {
|
2023-11-08 16:46:02 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$object_type = isset( $activity['object']['type'] ) ? $activity['object']['type'] : '';
|
|
|
|
|
|
|
|
switch ( $object_type ) {
|
|
|
|
case 'Person':
|
|
|
|
case 'Group':
|
|
|
|
case 'Organization':
|
|
|
|
case 'Service':
|
|
|
|
case 'Application':
|
2023-11-10 19:29:07 +01:00
|
|
|
$follower = Followers::get_follower( $user_id, $activity['actor'] );
|
|
|
|
if ( $follower ) {
|
|
|
|
$follower->delete();
|
|
|
|
}
|
2023-11-08 16:46:02 +01:00
|
|
|
|
2023-11-13 16:58:04 +01:00
|
|
|
// delete all activities from this user.
|
|
|
|
|
2023-11-08 16:46:02 +01:00
|
|
|
break;
|
|
|
|
case 'Tombstone':
|
|
|
|
// Handle tombstone.
|
|
|
|
break;
|
|
|
|
case 'Note':
|
|
|
|
case 'Article':
|
|
|
|
case 'Image':
|
|
|
|
case 'Audio':
|
|
|
|
case 'Video':
|
|
|
|
case 'Event':
|
|
|
|
case 'Document':
|
|
|
|
default:
|
|
|
|
// Handle delete activity for other object types.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|