6e7f82bf42
* init * save source id * fix delete and add improve undo * test new functions * add support for threaded comments * some formatting * check if URL is no longer available ...and returns either status 410 or 404. * improve delete handler * improve update handler * `object` and `actor` are already required by the inbox endpoint * fix typo * simplify queries * cosmetics * fix unit tests * schedule delete comments of deleted actor (#575) * schedule delete comments of deleted actor * phpcs --------- Co-authored-by: Django Doucet <django.doucet@webdevstudios.com> * move `get_comments_by_actor` to interactions collection * consistent wording * implement Tombstone * fix follow issue * fix inbox-create * added missing namespace * check if field is set * Fix namespacing issue * update profile and update interaction * fields are already validated by inbox * optimize avatar handling --------- Co-authored-by: Django <mediaformat.ux@gmail.com> Co-authored-by: Django Doucet <django.doucet@webdevstudios.com>
61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
namespace Activitypub\Handler;
|
|
|
|
use WP_Error;
|
|
use Activitypub\Collection\Interactions;
|
|
|
|
use function Activitypub\is_activity_public;
|
|
use function Activitypub\object_id_to_comment;
|
|
|
|
/**
|
|
* Handle Create requests
|
|
*/
|
|
class Create {
|
|
/**
|
|
* Initialize the class, registering WordPress hooks
|
|
*/
|
|
public static function init() {
|
|
\add_action( 'activitypub_inbox_create', array( self::class, 'handle_create' ), 10, 3 );
|
|
}
|
|
|
|
/**
|
|
* Handles "Create" requests
|
|
*
|
|
* @param array $array The activity-object
|
|
* @param int $user_id The id of the local blog-user
|
|
* @param Activitypub\Activity $object The activity object
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function handle_create( $array, $user_id, $object = null ) {
|
|
if (
|
|
! isset( $array['object'] ) ||
|
|
! isset( $array['object']['id'] )
|
|
) {
|
|
return;
|
|
}
|
|
|
|
// check if Activity is public or not
|
|
if ( ! is_activity_public( $array ) ) {
|
|
// @todo maybe send email
|
|
return;
|
|
}
|
|
|
|
$check_dupe = object_id_to_comment( $array['object']['id'] );
|
|
|
|
// if comment exists, call update action
|
|
if ( $check_dupe ) {
|
|
\do_action( 'activitypub_inbox_update', $array, $user_id, $object );
|
|
return;
|
|
}
|
|
|
|
$state = Interactions::add_comment( $array );
|
|
$reaction = null;
|
|
|
|
if ( $state && ! \is_wp_error( $reaction ) ) {
|
|
$reaction = \get_comment( $state );
|
|
}
|
|
|
|
\do_action( 'activitypub_handled_create', $array, $user_id, $state, $reaction );
|
|
}
|
|
}
|