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 = new Activitypub_pending_follow_requests($actor_profile->getID(), $object_profile->getID());
|
||||||
$pending_list->remove();
|
$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;
|
break;
|
||||||
default:
|
default:
|
||||||
ActivityPubReturn::error("Invalid object type.");
|
ActivityPubReturn::error("Invalid object type.");
|
||||||
|
@ -30,12 +30,13 @@ if (!defined('GNUSOCIAL')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isset($data->object)) {
|
try {
|
||||||
ActivityPubPlugin::get_local_notice_from_url($data->object)->repeat($actor_profile, "ActivityPub");
|
$object_notice = ActivityPubPlugin::get_local_notice_from_url($data->object);
|
||||||
ActivityPubReturn::answer("Notice repeated successfully.");
|
} catch (Exception $e) {
|
||||||
} else {
|
ActivityPubReturn::error('Invalid Object specified.');
|
||||||
ActivityPubReturn::error('No object id was specified.');
|
|
||||||
}
|
}
|
||||||
|
$object_notice->repeat($actor_profile, 'ActivityPub');
|
||||||
|
ActivityPubReturn::answer();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ActivityPubReturn::error($e->getMessage(), 403);
|
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;
|
$act->objects[] = $actobj;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$res = Activitypub_create::create_to_array(
|
Notice::saveActivity($act, $actor_profile, $options);
|
||||||
$data->id,
|
ActivityPubReturn::answer();
|
||||||
$data->actor,
|
|
||||||
Activitypub_notice::notice_to_array(Notice::saveActivity($act, $actor_profile, $options))
|
|
||||||
);
|
|
||||||
ActivityPubReturn::answer($res);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ActivityPubReturn::error($e->getMessage());
|
ActivityPubReturn::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,8 @@ if (!defined('GNUSOCIAL')) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$notice = ActivityPubPlugin::get_local_notice_from_url($data->object->id);
|
$notice = ActivityPubPlugin::get_local_notice_from_url($data->object->id);
|
||||||
$notice_to_array = Activitypub_notice::notice_to_array($notice);
|
|
||||||
$notice->deleteAs($actor_profile);
|
$notice->deleteAs($actor_profile);
|
||||||
ActivityPubReturn::answer(Activitypub_delete::delete_to_array($notice_to_array));
|
ActivityPubReturn::answer();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ActivityPubReturn::error($e->getMessage(), 403);
|
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
|
// 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);
|
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 = new Activitypub_postman($actor_profile, [$actor_aprofile]);
|
||||||
$postman->send(json_encode(Activitypub_accept::accept_to_array(Activitypub_follow::follow_to_array($data->actor, $data->object))), $actor_aprofile->get_inbox());
|
$postman->follow();
|
||||||
ActivityPubReturn::answer('', 202);
|
ActivityPubReturn::answer();
|
||||||
} 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);
|
||||||
ActivityPubReturn::error('Already following.', 409);
|
ActivityPubReturn::error('Already following.', 409);
|
||||||
|
@ -33,10 +33,10 @@ try {
|
|||||||
try {
|
try {
|
||||||
$object_notice = ActivityPubPlugin::get_local_notice_from_url($data->object);
|
$object_notice = ActivityPubPlugin::get_local_notice_from_url($data->object);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ActivityPubReturn::error("Invalid Object specified.");
|
ActivityPubReturn::error('Invalid Object specified.');
|
||||||
}
|
}
|
||||||
Fave::addNew($actor_profile, $object_notice);
|
Fave::addNew($actor_profile, $object_notice);
|
||||||
ActivityPubReturn::answer(Activitypub_like::like_to_array($data->actor, $data->object));
|
ActivityPubReturn::answer();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ActivityPubReturn::error($e->getMessage(), 403);
|
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));
|
Fave::removeEntry($actor_profile, ActivityPubPlugin::get_local_notice_from_url($data->object->object));
|
||||||
// Notice disfavorited successfully.
|
// Notice disfavorited successfully.
|
||||||
ActivityPubReturn::answer(
|
ActivityPubReturn::answer();
|
||||||
Activitypub_undo::undo_to_array(
|
|
||||||
Activitypub_like::like_to_array(
|
|
||||||
$actor_profile->getUrl(),
|
|
||||||
$data->object->object
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ActivityPubReturn::error($e->getMessage(), 403);
|
ActivityPubReturn::error($e->getMessage(), 403);
|
||||||
}
|
}
|
||||||
@ -71,22 +64,15 @@ switch ($data->object->type) {
|
|||||||
if (Subscription::exists($actor_profile, $object_profile)) {
|
if (Subscription::exists($actor_profile, $object_profile)) {
|
||||||
Subscription::cancel($actor_profile, $object_profile);
|
Subscription::cancel($actor_profile, $object_profile);
|
||||||
// You are no longer following this person.
|
// You are no longer following this person.
|
||||||
ActivityPubReturn::answer(
|
ActivityPubReturn::answer();
|
||||||
Activitypub_undo::undo_to_array(
|
|
||||||
Activitypub_accept::accept_to_array(
|
|
||||||
Activitypub_follow::follow_to_array(
|
|
||||||
$actor_profile->getUrl(),
|
|
||||||
$object_profile->getUrl()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
ActivityPubReturn::error('You are not following this person already.', 409);
|
// 409: You are not following this person already.
|
||||||
|
ActivityPubReturn::answer();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Announce':
|
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:
|
default:
|
||||||
ActivityPubReturn::error('Invalid object type.');
|
ActivityPubReturn::error('Invalid object type.');
|
||||||
break;
|
break;
|
||||||
|
@ -58,7 +58,7 @@ class Activitypub_postman
|
|||||||
*
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
* @param Profile $from Profile of sender
|
* @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 = [])
|
public function __construct($from, $to = [])
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user