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