From: Zach Copley Date: Fri, 18 Feb 2011 18:02:41 +0000 (-0800) Subject: Activity Streams JSON - express to and in-reply-to stuff as person objects X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=da42d36d7f42c2357c21f71034f9c1cd04220c99;p=quix0rs-gnu-social.git Activity Streams JSON - express to and in-reply-to stuff as person objects --- diff --git a/lib/activity.php b/lib/activity.php index 25d70c982b..11af98abb5 100644 --- a/lib/activity.php +++ b/lib/activity.php @@ -364,6 +364,27 @@ class Activity if ($this->verb == ActivityVerb::POST && count($this->objects) == 1) { $activity['object'] = $this->objects[0]->asArray(); + // Context stuff. For now I'm just sticking most of it + // in a property called "context" + + if (!empty($this->context)) { + + if (!empty($this->context->location)) { + $loc = $this->context->location; + + // GeoJSON + + $activity['geopoint'] = array( + 'type' => 'Point', + 'coordinates' => array($loc->lat, $loc->lon) + ); + + } + + $activity['to'] = $this->context->getToArray(); + $activity['context'] = $this->context->asArray(); + } + // Instead of adding enclosures as an extension to JSON // Activities, it seems like we should be using the // attachedObjects property of ActivityObject @@ -457,28 +478,6 @@ class Activity } } - - // Context stuff. For now I'm just sticking most of it - // in a property called "context" - - if (!empty($this->context)) { - - if (!empty($this->context->location)) { - $loc = $this->context->location; - - // GeoJSON - - $activity['geopoint'] = array( - 'type' => 'Point', - 'coordinates' => array($loc->lat, $loc->lon) - ); - - } - - $activity['to'] = $this->context->getToArray(); - $activity['context'] = $this->context->asArray(); - } - return array_filter($activity); } diff --git a/lib/activitycontext.php b/lib/activitycontext.php index 3dc53d869d..acbd0e599f 100644 --- a/lib/activitycontext.php +++ b/lib/activitycontext.php @@ -137,19 +137,16 @@ class ActivityContext * * @return array the context */ + function asArray() { $context = array(); - $context['replyToId'] = $this->replyToID; - $context['replyToUrl'] = $this->replyToUrl; + $context['replyTo'] = $this->getInReplyToArray(); $context['conversation'] = $this->conversation; $context['forwardId'] = $this->forwardID; $context['forwardUrl'] = $this->forwardUrl; - // XXX: We might want to have the attention to stuff - // in here like we do with Atom - return array_filter($context); } @@ -164,16 +161,38 @@ class ActivityContext * * @return array the array of recipients */ + function getToArray() { $tos = array(); foreach ($this->attention as $attnUrl) { - $to = array('id' => $attnUrl, 'url' => $attnUrl); + $to = array( + 'objectType' => 'person', + 'id' => $attnUrl, + 'url' => $attnUrl + ); $tos[] = $to; } return $tos; } + /* + * Show replyTo + */ + + function getInReplyToArray() + { + $replyToObj = array('objectType' => 'note'); + + $replyToObj['id'] = $this->replyToID; + + if (!empty($this->replyToUrl)) { + $replyToObj['url'] = $this->replyToUrl; + } + + } + } +