updated plugin ActivityPub version 3.3.3

This commit is contained in:
2024-10-09 12:44:17 +00:00
committed by Gitium
parent fb4b27bbc6
commit c54fa007bd
106 changed files with 7070 additions and 2918 deletions

View File

@ -1,17 +1,24 @@
<?php
/**
* Undo handler file.
*
* @package Activitypub
*/
namespace Activitypub\Handler;
use Activitypub\Collection\Users;
use Activitypub\Collection\Followers;
use Activitypub\Comment;
use function Activitypub\object_to_uri;
/**
* Handle Undo requests
* Handle Undo requests.
*/
class Undo {
/**
* Initialize the class, registering WordPress hooks
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
\add_action(
@ -21,23 +28,27 @@ class Undo {
}
/**
* Handle "Unfollow" requests
* Handle "Unfollow" requests.
*
* @param array $activity The JSON "Undo" Activity
* @param int $user_id The ID of the ID of the WordPress User
* @param array $activity The JSON "Undo" Activity.
*/
public static function handle_undo( $activity ) {
if (
isset( $activity['object']['type'] ) &&
'Follow' === $activity['object']['type'] &&
isset( $activity['object']['object'] )
! isset( $activity['object']['type'] ) ||
! isset( $activity['object']['object'] )
) {
return;
}
$type = $activity['object']['type'];
// Handle "Unfollow" requests.
if ( 'Follow' === $type ) {
$user_id = object_to_uri( $activity['object']['object'] );
$user = Users::get_by_resource( $user_id );
$user = Users::get_by_resource( $user_id );
if ( ! $user || is_wp_error( $user ) ) {
// If we can not find a user,
// we can not initiate a follow process
// If we can not find a user, we can not initiate a follow process.
return;
}
@ -46,5 +57,23 @@ class Undo {
Followers::remove_follower( $user_id, $actor );
}
// Handle "Undo" requests for "Like" and "Create" activities.
if ( in_array( $type, array( 'Like', 'Create', 'Announce' ), true ) ) {
if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
return;
}
$object_id = object_to_uri( $activity['object'] );
$comment = Comment::object_id_to_comment( esc_url_raw( $object_id ) );
if ( empty( $comment ) ) {
return;
}
$state = wp_trash_comment( $comment );
do_action( 'activitypub_handled_undo', $activity, $user_id, isset( $state ) ? $state : null, null );
}
}
}