Proper ActivityPub Return Answers
This commit is contained in:
parent
1f04b7ed40
commit
8b860d6da2
@ -50,7 +50,7 @@ case "Follow":
|
||||
|
||||
$pending_list = new Activitypub_pending_follow_requests($actor_profile->getID(), $object_profile->getID());
|
||||
$pending_list->remove();
|
||||
ActivityPubReturn::answer($data); // You are now being followed by this person.
|
||||
ActivityPubReturn::answer(); // You are now being followed by this person.
|
||||
break;
|
||||
default:
|
||||
ActivityPubReturn::error("Invalid object type.");
|
||||
|
@ -30,12 +30,13 @@ if (!defined('GNUSOCIAL')) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (isset($data->object)) {
|
||||
ActivityPubPlugin::get_local_notice_from_url($data->object)->repeat($actor_profile, "ActivityPub");
|
||||
ActivityPubReturn::answer("Notice repeated successfully.");
|
||||
} else {
|
||||
ActivityPubReturn::error('No object id was specified.');
|
||||
try {
|
||||
$object_notice = ActivityPubPlugin::get_local_notice_from_url($data->object);
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error('Invalid Object specified.');
|
||||
}
|
||||
$object_notice->repeat($actor_profile, 'ActivityPub');
|
||||
ActivityPubReturn::answer();
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error($e->getMessage(), 403);
|
||||
}
|
||||
|
@ -129,12 +129,8 @@ $actobj->content = strip_tags($content,'<p><b><i><u><a><ul><ol><li>');
|
||||
$act->objects[] = $actobj;
|
||||
|
||||
try {
|
||||
$res = Activitypub_create::create_to_array(
|
||||
$data->id,
|
||||
$data->actor,
|
||||
Activitypub_notice::notice_to_array(Notice::saveActivity($act, $actor_profile, $options))
|
||||
);
|
||||
ActivityPubReturn::answer($res);
|
||||
Notice::saveActivity($act, $actor_profile, $options);
|
||||
ActivityPubReturn::answer();
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error($e->getMessage());
|
||||
}
|
||||
|
@ -31,9 +31,8 @@ if (!defined('GNUSOCIAL')) {
|
||||
|
||||
try {
|
||||
$notice = ActivityPubPlugin::get_local_notice_from_url($data->object->id);
|
||||
$notice_to_array = Activitypub_notice::notice_to_array($notice);
|
||||
$notice->deleteAs($actor_profile);
|
||||
ActivityPubReturn::answer(Activitypub_delete::delete_to_array($notice_to_array));
|
||||
ActivityPubReturn::answer();
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error($e->getMessage(), 403);
|
||||
}
|
||||
|
@ -56,9 +56,9 @@ if (!Subscription::exists($actor_profile, $object_profile)) {
|
||||
|
||||
// Notify remote instance that we have accepted their request
|
||||
common_debug('ActivityPubPlugin: Notifying remote instance that we have accepted their Follow request request from '.$data->actor.' to '.$data->object);
|
||||
$postman = new Activitypub_postman($actor_profile);
|
||||
$postman->send(json_encode(Activitypub_accept::accept_to_array(Activitypub_follow::follow_to_array($data->actor, $data->object))), $actor_aprofile->get_inbox());
|
||||
ActivityPubReturn::answer('', 202);
|
||||
$postman = new Activitypub_postman($actor_profile, [$actor_aprofile]);
|
||||
$postman->follow();
|
||||
ActivityPubReturn::answer();
|
||||
} else {
|
||||
common_debug('ActivityPubPlugin: Received a repeated Follow request from '.$data->actor.' to '.$data->object);
|
||||
ActivityPubReturn::error('Already following.', 409);
|
||||
|
@ -33,10 +33,10 @@ try {
|
||||
try {
|
||||
$object_notice = ActivityPubPlugin::get_local_notice_from_url($data->object);
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error("Invalid Object specified.");
|
||||
ActivityPubReturn::error('Invalid Object specified.');
|
||||
}
|
||||
Fave::addNew($actor_profile, $object_notice);
|
||||
ActivityPubReturn::answer(Activitypub_like::like_to_array($data->actor, $data->object));
|
||||
ActivityPubReturn::answer();
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error($e->getMessage(), 403);
|
||||
}
|
||||
|
@ -43,14 +43,7 @@ switch ($data->object->type) {
|
||||
}
|
||||
Fave::removeEntry($actor_profile, ActivityPubPlugin::get_local_notice_from_url($data->object->object));
|
||||
// Notice disfavorited successfully.
|
||||
ActivityPubReturn::answer(
|
||||
Activitypub_undo::undo_to_array(
|
||||
Activitypub_like::like_to_array(
|
||||
$actor_profile->getUrl(),
|
||||
$data->object->object
|
||||
)
|
||||
)
|
||||
);
|
||||
ActivityPubReturn::answer();
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error($e->getMessage(), 403);
|
||||
}
|
||||
@ -71,22 +64,15 @@ switch ($data->object->type) {
|
||||
if (Subscription::exists($actor_profile, $object_profile)) {
|
||||
Subscription::cancel($actor_profile, $object_profile);
|
||||
// You are no longer following this person.
|
||||
ActivityPubReturn::answer(
|
||||
Activitypub_undo::undo_to_array(
|
||||
Activitypub_accept::accept_to_array(
|
||||
Activitypub_follow::follow_to_array(
|
||||
$actor_profile->getUrl(),
|
||||
$object_profile->getUrl()
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
ActivityPubReturn::answer();
|
||||
} else {
|
||||
ActivityPubReturn::error('You are not following this person already.', 409);
|
||||
// 409: You are not following this person already.
|
||||
ActivityPubReturn::answer();
|
||||
}
|
||||
break;
|
||||
case 'Announce':
|
||||
ActivityPubReturn::answer(); // TODO: Implement Undo Announce
|
||||
// This is a dummy entry point as GNU Social doesn't allow Undo Announce
|
||||
ActivityPubReturn::answer();
|
||||
default:
|
||||
ActivityPubReturn::error('Invalid object type.');
|
||||
break;
|
||||
|
@ -58,7 +58,7 @@ class Activitypub_postman
|
||||
*
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @param Profile $from Profile of sender
|
||||
* @param Activitypub_profile $to array of destinataries
|
||||
* @param Array of Activitypub_profile $to destinataries
|
||||
*/
|
||||
public function __construct($from, $to = [])
|
||||
{
|
||||
|
Reference in New Issue
Block a user