some code cleanups

This commit is contained in:
Matthias Pfefferle 2023-04-21 08:51:38 +02:00
parent 5faddba511
commit a8b963ec26

View file

@ -1,7 +1,10 @@
<?php <?php
namespace Activitypub\Rest; namespace Activitypub\Rest;
use WP_REST_Response;
use Activitypub\Signature;
use Activitypub\Model\Activity; use Activitypub\Model\Activity;
use \Activitypub\Peer\Followers;
/** /**
* ActivityPub Inbox REST-Class * ActivityPub Inbox REST-Class
@ -116,7 +119,7 @@ class Inbox {
*/ */
\do_action( 'activitypub_inbox_post' ); \do_action( 'activitypub_inbox_post' );
$response = new \WP_REST_Response( $json, 200 ); $response = new WP_REST_Response( $json, 200 );
$response->header( 'Content-Type', 'application/activity+json' ); $response->header( 'Content-Type', 'application/activity+json' );
@ -140,7 +143,7 @@ class Inbox {
\do_action( 'activitypub_inbox', $data, $user_id, $type ); \do_action( 'activitypub_inbox', $data, $user_id, $type );
\do_action( "activitypub_inbox_{$type}", $data, $user_id ); \do_action( "activitypub_inbox_{$type}", $data, $user_id );
return new \WP_REST_Response( array(), 202 ); return new WP_REST_Response( array(), 202 );
} }
/** /**
@ -179,7 +182,7 @@ class Inbox {
\do_action( "activitypub_inbox_{$type}", $data, $user->ID ); \do_action( "activitypub_inbox_{$type}", $data, $user->ID );
} }
return new \WP_REST_Response( array(), 202 ); return new WP_REST_Response( array(), 202 );
} }
/** /**
@ -233,7 +236,7 @@ class Inbox {
$params['signature'] = array( $params['signature'] = array(
'required' => true, 'required' => true,
'validate_callback' => function( $param, $request, $key ) { 'validate_callback' => function( $param, $request, $key ) {
if ( ! \Activitypub\Signature::verify_http_signature( $request ) ) { if ( ! Signature::verify_http_signature( $request ) ) {
return false; // returns http 400 rest_invalid_param return false; // returns http 400 rest_invalid_param
} }
return $param; return $param;
@ -283,7 +286,7 @@ class Inbox {
'type' => 'string', 'type' => 'string',
'sanitize_callback' => 'esc_url_raw', 'sanitize_callback' => 'esc_url_raw',
'validate_callback' => function( $param, $request, $key ) { 'validate_callback' => function( $param, $request, $key ) {
if ( ! \Activitypub\Signature::verify_http_signature( $request ) ) { if ( ! Signature::verify_http_signature( $request ) ) {
return false; return false;
} }
return $param; return $param;
@ -357,7 +360,7 @@ class Inbox {
*/ */
public static function handle_follow( $object, $user_id ) { public static function handle_follow( $object, $user_id ) {
// save follower // save follower
\Activitypub\Peer\Followers::add_follower( $object['actor'], $user_id ); Followers::add_follower( $object['actor'], $user_id );
// get inbox // get inbox
$inbox = \Activitypub\get_inbox_by_actor( $object['actor'] ); $inbox = \Activitypub\get_inbox_by_actor( $object['actor'] );
@ -382,7 +385,7 @@ class Inbox {
*/ */
public static function handle_unfollow( $object, $user_id ) { public static function handle_unfollow( $object, $user_id ) {
if ( isset( $object['object'] ) && isset( $object['object']['type'] ) && 'Follow' === $object['object']['type'] ) { if ( isset( $object['object'] ) && isset( $object['object']['type'] ) && 'Follow' === $object['object']['type'] ) {
\Activitypub\Peer\Followers::remove_follower( $object['actor'], $user_id ); Followers::remove_follower( $object['actor'], $user_id );
} }
} }