]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Favorite/FavoritePlugin.php
FavorAction now uses Notice::saveActivity
[quix0rs-gnu-social.git] / plugins / Favorite / FavoritePlugin.php
index 18aa32738b6b866d8ba46d0f5d8e7e5ca519eb13..61efe21027b0d5b3497307df9f47cba82c8f9a59 100644 (file)
@@ -63,7 +63,7 @@ class FavoritePlugin extends ActivityHandlerPlugin
                                          '    modified = "%s" '.
                                          'WHERE user_id = %d '.
                                          'AND notice_id = %d',
-                                         Fave::newURI($fave->user_id, $fave->notice_id, $fave->modified),
+                                         Fave::newUri($fave->user_id, $fave->notice_id, $fave->modified),
                                          common_sql_date(strtotime($fave->modified)),
                                          $fave->user_id,
                                          $fave->notice_id));
@@ -147,39 +147,30 @@ class FavoritePlugin extends ActivityHandlerPlugin
                           'format' => '(xml|json)'));
     }
 
-    public function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
-    {
-    }
-
-    // FIXME: Set this to abstract public when all plugins have migrated!
-    public function saveObjectFromActivity(Activity $activity, Notice $stored, array $options=array())  
+    // FIXME: Set this to abstract public in lib/activityhandlerplugin.php ddwhen all plugins have migrated!
+    protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())  
     {
         assert($this->isMyActivity($act));
-        $actor = $stored->getProfile();
-        $uris = array();
-        if (count($act->objects) != 1) {
-            // TRANS: Exception thrown when a favor activity has anything but 1 object
-            throw new ClientException(_('Favoring activites can only be done one at a time'));
+
+        // If empty, we should've created it ourselves on our node.
+        if (!isset($options['created'])) {
+            $options['created'] = !empty($act->time) ? common_sql_date($act->time) : common_sql_now();
         }
+        if (!isset($options['uri'])) {
+            $options['uri'] = !empty($act->id) ? $act->id : $act->selfLink;
+        }
+
+        // We must have an objects[0] here because in isMyActivity we require the count to be == 1
+        $actobj = $act->objects[0];
 
-        $obj = $act->objects[0];
-        $type = isset($obj->type) ? ActivityUtils::resolveUri($obj->type, true) : ActivityObject::NOTE;
-        $uris = $obj->getIdentifiers();
         try {
-            $local = ActivityUtils::findLocalObject($uris, $type);
-        } catch (Exception $e) {
-            // TODO: if it's not available locally, we should import the favorited object!
-            common_debug('Could not find favored notice locally: '.var_export($uris,true));
+            $object = Fave::saveActivityObject($actobj, $stored);
+        } catch (ServerException $e) {
+            // Probably that the favored notice doesn't exist in our local database
+            // but may also be some missing profile or so, which we could catch in a
+            // more explicit catch-statement.
             return null;
         }
-
-        if (!empty($act->time)) {
-            // This should reasonably mean that it was created on our instance.
-            $options['created'] = common_sql_date($act->time);
-        }
-
-        $options['uri'] = !empty($act->id) ? $act->id : $act->selfLink;
-        $object = Fave::saveNew($actor, $local, $type, $options);
         return $object;
     }
 
@@ -297,6 +288,19 @@ class FavoritePlugin extends ActivityHandlerPlugin
         }
     }
 
+    public function showNoticeListItem(NoticeListItem $nli)
+    {
+        // pass
+    }
+    public function openNoticeListItemElement(NoticeListItem $nli)
+    {
+        // pass
+    }
+    public function closeNoticeListItemElement(NoticeListItem $nli)
+    {
+        // pass
+    }
+
     public function onAppendUserActivityStreamObjects(UserActivityStream $uas, array &$objs)
     {
         $faves = array();