From 8e3bd04d987aad7afe9d44e921befbfc5f9539a1 Mon Sep 17 00:00:00 2001
From: Evan Prodromou <evan@e14n.com>
Date: Mon, 3 Jun 2013 09:10:56 -0400
Subject: [PATCH] Only a single object in activitystrea.ms JSON output

---
 lib/activity.php | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/lib/activity.php b/lib/activity.php
index e352baf639..3b7a4d2aaa 100644
--- a/lib/activity.php
+++ b/lib/activity.php
@@ -374,8 +374,27 @@ class Activity
         $activity['id'] = $this->id;
 
         // object
-        if ($this->verb == ActivityVerb::POST && count($this->objects) == 1) {
-            $activity['object'] = $this->objects[0]->asArray();
+
+        if (count($this->objects) > 1) {
+            common_log(LOG_WARNING, "Ignoring extra objects in JSON output for activity " . $this->id);
+        } else if (count($this->objects == 0)) {
+            common_log(LOG_ERR, "Can't save " . $this->id);
+        } else {
+            $object = $this->objects[0];
+
+            if ($object instanceof Activity) {
+                // Sharing a post activity is more like sharing the original object
+                if ($this->verb == 'share' && $object->verb == 'post') {
+                    // XXX: Here's one for the obfuscation record books
+                    $object = $object->object;
+                }
+            }
+
+            $activity['object'] = $object->asArray();
+
+            if ($object instanceof Activity) {
+                $activity['object']['objectType'] = 'activity';
+            }
 
             // Context stuff. For now I'm just sticking most of it
             // in a property called "context"
@@ -385,14 +404,6 @@ class Activity
                 if (!empty($this->context->location)) {
                     $loc = $this->context->location;
 
-                    // GeoJSON
-
-                    $activity['geopoint'] = array(
-                        'type'        => 'Point',
-                        'coordinates' => array($loc->lat, $loc->lon),
-                        'deprecated'  => true,
-                    );
-
                     $activity['location'] = array(
                         'objectType' => 'place',
                         'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon),
@@ -452,24 +463,12 @@ class Activity
                     if ($enclosure->title) {
                         $attachments[]['displayName'] = $enclosure->title;
                     }
-               }
+                }
             }
 
             if (!empty($attachments)) {
                 $activity['object']['attachments'] = $attachments;
             }
-
-        } else {
-            $activity['object'] = array();
-            foreach($this->objects as $object) {
-                $oa = $object->asArray();
-                if ($object instanceof Activity) {
-                    // throw in a type
-                    // XXX: hackety-hack
-                    $oa['objectType'] = 'activity';
-                }
-                $activity['object'][] = $oa;
-            }
         }
 
         // published
-- 
2.39.5