Simplify Follow System Logic

This commit is contained in:
Diogo Cordeiro 2018-07-31 22:16:30 +01:00
parent 12b1fd7b1f
commit bb4bcd8ea1
3 changed files with 19 additions and 21 deletions

View File

@ -46,7 +46,9 @@ try {
if (!Subscription::exists($actor_profile, $object_profile)) {
Subscription::start($actor_profile, $object_profile);
common_debug('ActivityPubPlugin: Accepted Follow request from '.$data->actor.' to '.$data->object);
ActivityPubReturn::answer(Activitypub_accept::accept_to_array(Activitypub_follow::follow_to_array($data->actor, $data->object)), 202);
$postman = new Activitypub_postman($data->actor);
$postman->send(json_encode(Activitypub_accept::accept_to_array(Activitypub_follow::follow_to_array($data->actor, $data->object))), Activitypub_profile::from_profile($object_profile)->getInbox());
ActivityPubReturn::answer('', 202);
} else {
common_debug('ActivityPubPlugin: Received a repeated Follow request from '.$data->actor.' to '.$data->object);
ActivityPubReturn::error("Already following.", 409);

View File

@ -118,11 +118,7 @@ class Activitypub_postman
if ($res->getStatusCode() == 200 || $res->getStatusCode() == 202 || $res->getStatusCode() == 409) {
$pending_list = new Activitypub_pending_follow_requests($this->actor->getID(), $this->to[0]->getID());
if (! ($res->getStatusCode() == 202 || $res_body->type == "Accept" || $res->getStatusCode() == 409)) {
$pending_list->add();
throw new Exception("Your follow request is pending acceptation.");
}
$pending_list->remove();
return true;
} elseif (isset($res_body[0]->error)) {
throw new Exception($res_body[0]->error);