Update inbox and fix Follow Accept bug
This commit is contained in:
parent
b4880713d5
commit
9c6aff46d9
@ -58,11 +58,11 @@ class apActorInboxAction extends ManagedAction
|
||||
}
|
||||
|
||||
if (!$profile->isLocal()) {
|
||||
ActivityPubReturn::error("This is not a local user.");
|
||||
ActivityPubReturn::error('This is not a local user.');
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
ActivityPubReturn::error("C2S not implemented just yet.");
|
||||
ActivityPubReturn::error('C2S not implemented just yet.');
|
||||
}
|
||||
|
||||
common_debug('ActivityPub Inbox: Received a POST request.');
|
||||
@ -72,31 +72,34 @@ class apActorInboxAction extends ManagedAction
|
||||
|
||||
// Validate data
|
||||
if (!(isset($data->type))) {
|
||||
ActivityPubReturn::error("Type was not specified.");
|
||||
ActivityPubReturn::error('Type was not specified.');
|
||||
}
|
||||
if (!isset($data->actor)) {
|
||||
ActivityPubReturn::error("Actor was not specified.");
|
||||
ActivityPubReturn::error('Actor was not specified.');
|
||||
}
|
||||
if (!isset($data->object)) {
|
||||
ActivityPubReturn::error("Object was not specified.");
|
||||
ActivityPubReturn::error('Object was not specified.');
|
||||
}
|
||||
|
||||
$discovery = new Activitypub_explorer;
|
||||
// Get valid Actor object
|
||||
try {
|
||||
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "explorer.php";
|
||||
$actor_profile = new Activitypub_explorer;
|
||||
$actor_profile = $actor_profile->lookup($data->actor);
|
||||
$actor_profile = $discovery->lookup($data->actor);
|
||||
$actor_profile = $actor_profile[0];
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error("Invalid Actor.", 404);
|
||||
ActivityPubReturn::error('Invalid Actor.', 404);
|
||||
}
|
||||
unset($discovery);
|
||||
|
||||
// Public To:
|
||||
$public_to = array("https://www.w3.org/ns/activitystreams#Public",
|
||||
"Public",
|
||||
"as:Public");
|
||||
$public_to = ['https://www.w3.org/ns/activitystreams#Public',
|
||||
'Public',
|
||||
'as:Public'
|
||||
];
|
||||
|
||||
$to_profiles = array($profile);
|
||||
$to_profiles = [ActivityPubPlugin::actor_uri($profile),
|
||||
'https://www.w3.org/ns/activitystreams#Public'
|
||||
];
|
||||
|
||||
// Process request
|
||||
switch ($data->type) {
|
||||
|
@ -52,7 +52,7 @@ class apSharedInboxAction extends ManagedAction
|
||||
protected function handle()
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
ActivityPubReturn::error("Only POST requests allowed.");
|
||||
ActivityPubReturn::error('Only POST requests allowed.');
|
||||
}
|
||||
|
||||
common_debug('ActivityPub Shared Inbox: Received a POST request.');
|
||||
@ -62,13 +62,13 @@ class apSharedInboxAction extends ManagedAction
|
||||
|
||||
// Validate data
|
||||
if (!isset($data->type)) {
|
||||
ActivityPubReturn::error("Type was not specified.");
|
||||
ActivityPubReturn::error('Type was not specified.');
|
||||
}
|
||||
if (!isset($data->actor)) {
|
||||
ActivityPubReturn::error("Actor was not specified.");
|
||||
ActivityPubReturn::error('Actor was not specified.');
|
||||
}
|
||||
if (!isset($data->object)) {
|
||||
ActivityPubReturn::error("Object was not specified.");
|
||||
ActivityPubReturn::error('Object was not specified.');
|
||||
}
|
||||
|
||||
$discovery = new Activitypub_explorer;
|
||||
@ -77,49 +77,49 @@ class apSharedInboxAction extends ManagedAction
|
||||
$actor_profile = $discovery->lookup($data->actor);
|
||||
$actor_profile = $actor_profile[0];
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error("Invalid Actor.", 404);
|
||||
ActivityPubReturn::error('Invalid Actor.', 404);
|
||||
}
|
||||
unset($discovery);
|
||||
|
||||
// Public To:
|
||||
$public_to = ["https://www.w3.org/ns/activitystreams#Public",
|
||||
"Public",
|
||||
"as:Public"
|
||||
$public_to = ['https://www.w3.org/ns/activitystreams#Public',
|
||||
'Public',
|
||||
'as:Public'
|
||||
];
|
||||
|
||||
$to_profiles = "https://www.w3.org/ns/activitystreams#Public";
|
||||
$to_profiles = 'https://www.w3.org/ns/activitystreams#Public';
|
||||
|
||||
// Process request
|
||||
switch ($data->type) {
|
||||
// Data available:
|
||||
// Profile $actor_profile
|
||||
// string|object $data->object
|
||||
case "Create":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Create.php";
|
||||
case 'Create':
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Create.php';
|
||||
break;
|
||||
case "Follow":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Follow.php";
|
||||
case 'Follow':
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Follow.php';
|
||||
break;
|
||||
case "Like":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Like.php";
|
||||
case 'Like':
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Like.php';
|
||||
break;
|
||||
case "Announce":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Announce.php";
|
||||
case 'Announce':
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Announce.php';
|
||||
break;
|
||||
case "Undo":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Undo.php";
|
||||
case 'Undo':
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Undo.php';
|
||||
break;
|
||||
case "Delete":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Delete.php";
|
||||
case 'Delete':
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Delete.php';
|
||||
break;
|
||||
case "Accept":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Accept.php";
|
||||
case 'Accept':
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Accept.php';
|
||||
break;
|
||||
case "Reject":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Reject.php";
|
||||
case 'Reject':
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Reject.php';
|
||||
break;
|
||||
default:
|
||||
ActivityPubReturn::error("Invalid type value.");
|
||||
ActivityPubReturn::error('Invalid type value.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,16 +34,22 @@ if (!filter_var($data->object, FILTER_VALIDATE_URL)) {
|
||||
ActivityPubReturn::error('Invalid Object Actor URL.');
|
||||
}
|
||||
|
||||
// Get valid Object profile
|
||||
// Ensure valid Object profile
|
||||
try {
|
||||
$object_profile = new Activitypub_explorer;
|
||||
$object_profile = $object_profile->lookup($data->object)[0];
|
||||
$object_aprofile = Activitypub_profile::from_profile($object_profile);
|
||||
if (!isset ($profile)) {
|
||||
$object_profile = new Activitypub_explorer;
|
||||
$object_profile = $object_profile->lookup($data->object)[0];
|
||||
} else {
|
||||
$object_profile = $profile;
|
||||
unset ($profile);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
common_debug();
|
||||
ActivityPubReturn::error('Invalid Object Actor URL.', 404);
|
||||
}
|
||||
|
||||
// Get Actor's Aprofile
|
||||
$actor_aprofile = Activitypub_profile::from_profile($actor_profile);
|
||||
|
||||
try {
|
||||
if (!Subscription::exists($actor_profile, $object_profile)) {
|
||||
Subscription::start($actor_profile, $object_profile);
|
||||
@ -51,7 +57,7 @@ try {
|
||||
|
||||
// Send Accept back
|
||||
$postman = new Activitypub_postman($actor_profile);
|
||||
$postman->send(json_encode(Activitypub_accept::accept_to_array(Activitypub_follow::follow_to_array($data->actor, $data->object))), $object_aprofile->getInbox());
|
||||
$postman->send(json_encode(Activitypub_accept::accept_to_array(Activitypub_follow::follow_to_array($data->actor, $data->object))), $actor_aprofile->getInbox());
|
||||
ActivityPubReturn::answer('', 202);
|
||||
} else {
|
||||
common_debug('ActivityPubPlugin: Received a repeated Follow request from '.$data->actor.' to '.$data->object);
|
||||
|
Reference in New Issue
Block a user