Simplify Follow System Logic
This commit is contained in:
parent
12b1fd7b1f
commit
bb4bcd8ea1
@ -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);
|
||||
|
@ -72,20 +72,20 @@ class Activitypub_notice extends Managed_DataObject
|
||||
$to[]= 'https://www.w3.org/ns/activitystreams#Public';
|
||||
|
||||
$item = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => $notice->getUrl(),
|
||||
'type' => 'Note',
|
||||
'published' => str_replace(' ', 'T', $notice->getCreated()).'Z',
|
||||
'url' => $notice->getUrl(),
|
||||
'atributtedTo' => ActivityPubPlugin::actor_uri($profile),
|
||||
'to' => $to,
|
||||
'cc' => common_local_url('apActorFollowers', ['id' => $profile->getID()]),
|
||||
'atomUri' => $notice->getUrl(),
|
||||
'conversation' => $notice->getConversationUrl(),
|
||||
'content' => $notice->getContent(),
|
||||
'isLocal' => $notice->isLocal(),
|
||||
'attachment' => $attachments,
|
||||
'tag' => $tags
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => $notice->getUrl(),
|
||||
'type' => 'Note',
|
||||
'published' => str_replace(' ', 'T', $notice->getCreated()).'Z',
|
||||
'url' => $notice->getUrl(),
|
||||
'atributtedTo' => ActivityPubPlugin::actor_uri($profile),
|
||||
'to' => $to,
|
||||
'cc' => common_local_url('apActorFollowers', ['id' => $profile->getID()]),
|
||||
'atomUri' => $notice->getUrl(),
|
||||
'conversation' => $notice->getConversationUrl(),
|
||||
'content' => $notice->getContent(),
|
||||
'isLocal' => $notice->isLocal(),
|
||||
'attachment' => $attachments,
|
||||
'tag' => $tags
|
||||
];
|
||||
|
||||
// Is this a reply?
|
||||
@ -93,7 +93,7 @@ class Activitypub_notice extends Managed_DataObject
|
||||
$item['inReplyTo'] = Notice::getById($notice->reply_to)->getUrl();
|
||||
$item['inReplyToAtomUri'] = Notice::getById($notice->reply_to)->getUrl();
|
||||
}
|
||||
|
||||
|
||||
// Do we have a location for this notice?
|
||||
try {
|
||||
$location = Notice_location::locFromStored($notice);
|
||||
|
@ -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();
|
||||
$pending_list->add();
|
||||
return true;
|
||||
} elseif (isset($res_body[0]->error)) {
|
||||
throw new Exception($res_body[0]->error);
|
||||
|
Reference in New Issue
Block a user