Fix some issues

This commit is contained in:
Diogo Cordeiro 2018-08-03 18:47:20 +01:00
parent 442e66d112
commit de432cda88
4 changed files with 62 additions and 52 deletions

View File

@ -88,36 +88,43 @@ class apActorInboxAction extends ManagedAction
ActivityPubReturn::error($e->getMessage(), 404);
}
$to_profiles = [$profile];
$cc = [$profile];
// Process request
define('INBOX_HANDLERS', __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR);
switch ($data['type']) {
case "Create":
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Create.php";
break;
case "Delete":
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Delete.php";
break;
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";
break;
case "Undo":
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Undo.php";
break;
case "Announce":
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Announce.php";
break;
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";
break;
// Data available:
// Profile $actor_profile Actor performing the action
// string|object $data->object Object to be handled
// Array|String $cc Destinataries
// Profile $profile Local user to whom this action is directed
case 'Create':
$cc = array_merge ([$profile], $data['object']['cc']);
require_once INBOX_HANDLERS . 'Create.php';
break;
case 'Follow':
require_once INBOX_HANDLERS . 'Follow.php';
break;
case 'Like':
require_once INBOX_HANDLERS . 'Like.php';
break;
case 'Announce':
require_once INBOX_HANDLERS . 'Announce.php';
break;
case 'Undo':
require_once INBOX_HANDLERS . 'Undo.php';
break;
case 'Delete':
require_once INBOX_HANDLERS . 'Delete.php';
break;
case 'Accept':
require_once INBOX_HANDLERS . 'Accept.php';
break;
case 'Reject':
require_once INBOX_HANDLERS . 'Reject.php';
break;
default:
ActivityPubReturn::error("Invalid type value.");
ActivityPubReturn::error('Invalid type value.');
}
}
}

View File

@ -78,39 +78,44 @@ class apSharedInboxAction extends ManagedAction
ActivityPubReturn::error($e->getMessage(), 404);
}
$to_profiles = [];
$cc = [];
// Process request
define('INBOX_HANDLERS', __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR);
switch ($data['type']) {
// Data available:
// Profile $actor_profile
// Profile $actor_profile Actor performing the action
// string|object $data->object Object to be handled
// Array|String $cc Destinataries
// string|object $data->object
case 'Create':
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Create.php';
break;
$cc = $data['object']['cc'];
$res = $data['object'];
require_once INBOX_HANDLERS . 'Create.php';
break;
case 'Follow':
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Follow.php';
break;
require_once INBOX_HANDLERS . 'Follow.php';
break;
case 'Like':
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Like.php';
break;
require_once INBOX_HANDLERS . 'Like.php';
break;
case 'Announce':
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Announce.php';
break;
require_once INBOX_HANDLERS . 'Announce.php';
break;
case 'Undo':
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Undo.php';
break;
require_once INBOX_HANDLERS . 'Undo.php';
break;
case 'Delete':
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Delete.php';
break;
require_once INBOX_HANDLERS . 'Delete.php';
break;
case 'Accept':
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Accept.php';
break;
require_once INBOX_HANDLERS . 'Accept.php';
break;
case 'Reject':
require_once __DIR__ . DIRECTORY_SEPARATOR . 'inbox' . DIRECTORY_SEPARATOR . 'Reject.php';
break;
require_once INBOX_HANDLERS . 'Reject.php';
break;
default:
ActivityPubReturn::error('Invalid type value.');
ActivityPubReturn::error('Invalid type value.');
}
}
}

View File

@ -31,8 +31,6 @@ if (!defined('GNUSOCIAL')) {
$valid_object_types = ['Note'];
$res = $data['object'];
try {
Activitypub_notice::validate_remote_notice($res);
} catch (Exception $e) {
@ -61,7 +59,7 @@ try {
$res['id'],
$res['url'],
$res['content'],
$res['cc'],
$cc,
$settings
);
ActivityPubReturn::answer();

View File

@ -144,13 +144,13 @@ class Activitypub_notice extends Managed_DataObject
throw new UnsupportedMediaException('Downloaded image was not an image.');
}
file_put_contents($temp_filename, $imgData);
unset($imgData); // No need to carry this in memory.
common_debug('ActivityPub Create Notice: Stored dowloaded image in: '.$temp_filename);
$id = $actor_profile->getID();
$imagefile = new ImageFile(null, $temp_filename);
$filename = hash(File::FILEHASH_ALG, $imgData).image_type_to_extension($imagefile->type);
unset($imgData); // No need to carry this in memory.
rename($temp_filename, File::path($filename));
common_debug('ActivityPub Create Notice: Moved image from: '.$temp_filename.' to '.$filename);
$mediaFile = new MediaFile($filename, $attach['mediaType']);
@ -186,7 +186,7 @@ class Activitypub_notice extends Managed_DataObject
array_unique($cc);
foreach ($cc as $cc_url) {
try {
$cc_profiles = array_merge($cc_profiles, $discovery->lookup($cc_url));
$cc = array_merge($cc, $discovery->lookup($cc_url));
} catch (Exception $e) {
// Invalid actor found, just let it go. // TODO: Fallback to OStatus
}
@ -195,7 +195,7 @@ class Activitypub_notice extends Managed_DataObject
// No need to do anything else at this point, let's just break out the if
} else {
try {
$cc_profiles = array_merge($cc_profiles, $discovery->lookup($cc));
$cc = array_merge($cc, $discovery->lookup($cc));
} catch (Exception $e) {
// Invalid actor found, just let it go. // TODO: Fallback to OStatus
}
@ -203,7 +203,7 @@ class Activitypub_notice extends Managed_DataObject
unset($discovery);
foreach ($cc_profiles as $tp) {
foreach ($cc as $tp) {
$act->context->attention[ActivityPubPlugin::actor_uri($tp)] = 'http://activitystrea.ms/schema/1.0/person';
}