Activity Streams JSON - express to and in-reply-to stuff as person objects

This commit is contained in:
Zach Copley 2011-02-18 10:02:41 -08:00
parent 20e414665d
commit da42d36d7f
2 changed files with 46 additions and 28 deletions

View File

@ -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);
}

View File

@ -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;
}
}
}