From 20738f48cd421cb3b8d9fdf2ecdff1148b47d8ea Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Sun, 29 Jul 2018 02:57:46 +0100 Subject: [PATCH] Add location to notices (closes #44) --- actions/apactorliked.php | 7 +++--- actions/inbox/Create.php | 5 +++++ classes/Activitypub_notice.php | 40 +++++++++++++++++++++------------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/actions/apactorliked.php b/actions/apactorliked.php index 436baf9..ff1fe46 100755 --- a/actions/apactorliked.php +++ b/actions/apactorliked.php @@ -108,9 +108,10 @@ class apActorLikedAction extends ManagedAction */ protected function pretty_fave($fave_object) { - $res = array("uri" => $fave_object->uri, - "created" => $fave_object->created, - "object" => Activitypub_notice::notice_to_array(Notice::getByID($fave_object->notice_id))); + $res = [ + 'created' => $fave_object->created, + 'object' => Activitypub_notice::notice_to_array(Notice::getByID($fave_object->notice_id)) + ]; return $res; } diff --git a/actions/inbox/Create.php b/actions/inbox/Create.php index 2a89553..ff2b5cc 100755 --- a/actions/inbox/Create.php +++ b/actions/inbox/Create.php @@ -127,6 +127,11 @@ foreach ($to_profiles as $tp) { $act->context->attention[ActivityPubPlugin::actor_uri($tp)] = "http://activitystrea.ms/schema/1.0/person"; } +// Add location if that is set +if (isset ($data->object->latitude, $data->object->longitude)) { + $act->context->location = Location::fromLatLon($data->object->latitude, $data->object->longitude); +} + // Reject notice if it is too long (without the HTML) // This is done after MediaFile::fromUpload etc. just to act the same as the ApiStatusesUpdateAction if (Notice::contentTooLong($content)) { diff --git a/classes/Activitypub_notice.php b/classes/Activitypub_notice.php index d90fda7..953f912 100755 --- a/classes/Activitypub_notice.php +++ b/classes/Activitypub_notice.php @@ -71,21 +71,31 @@ class Activitypub_notice extends Managed_DataObject } $item = [ - 'id' => $notice->getUrl(), - 'type' => 'Note', - 'inReplyTo' => empty($notice->reply_to) ? null : Notice::getById($notice->reply_to)->getUrl(), - 'published' => $notice->getCreated(), - 'url' => $notice->getUrl(), - 'atributedTo' => ActivityPubPlugin::actor_uri($profile), - 'to' => $to, - 'atomUri' => $notice->getUrl(), - 'inReplyToAtomUri' => empty($notice->reply_to) ? null : Notice::getById($notice->reply_to)->getUrl(), - 'conversation' => $notice->getConversationUrl(), - 'content' => $notice->getContent(), - 'is_local' => $notice->isLocal(), - 'attachment' => $attachments, - 'tag' => $tags - ]; + 'context' => 'https://www.w3.org/ns/activitystreams', + 'id' => $notice->getUrl(), + 'type' => 'Note', + 'inReplyTo' => empty($notice->reply_to) ? null : Notice::getById($notice->reply_to)->getUrl(), + 'published' => $notice->getCreated(), + 'url' => $notice->getUrl(), + 'atributedTo' => ActivityPubPlugin::actor_uri($profile), + 'to' => $to, + 'atomUri' => $notice->getUrl(), + 'inReplyToAtomUri' => empty($notice->reply_to) ? null : Notice::getById($notice->reply_to)->getUrl(), + 'conversation' => $notice->getConversationUrl(), + 'content' => $notice->getContent(), + 'is_local' => $notice->isLocal(), + 'attachment' => $attachments, + 'tag' => $tags + ]; + + // Do we have a location for this notice? + try { + $location = Notice_location::locFromStored($notice); + $item['latitude'] = $location->lat; + $item['longitude'] = $location->lon; + } catch (Exception $ex) { + // Apparently no. + } return $item; }