]> 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 6248b332c41d3fd6e5d704b8984d855dc437a661..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,16 +147,48 @@ class FavoritePlugin extends ActivityHandlerPlugin
                           'format' => '(xml|json)'));
     }
 
-    public function saveNoticeFromActivity(Activity $activity, Profile $actor, 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));
+
+        // 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];
+
+        try {
+            $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;
+        }
+        return $object;
     }
 
+
     public function activityObjectFromNotice(Notice $notice)
     {
+        $fave = Fave::fromStored($notice);
+        return $fave->asActivityObject();
     }
 
     public function deleteRelated(Notice $notice)
     {
+        try {
+            $fave = Fave::fromStored($notice);
+            $fave->delete();
+        } catch (NoResultException $e) {
+            // Cool, no problem. We wanted to get rid of it anyway.
+        }
     }
 
     // API stuff
@@ -196,15 +228,15 @@ class FavoritePlugin extends ActivityHandlerPlugin
     {
         parent::onNoticeDeleteRelated($notice);
 
-        // The below algorithm is because we have faves not stored as
-        // proper activities in Notice from legacy versions of SN/GNU social
+        // The below algorithm is because we want to delete fave
+        // activities on any notice which _has_ faves, and not as
+        // in the parent function only ones that _are_ faves.
 
         $fave = new Fave();
         $fave->notice_id = $notice->id;
 
         if ($fave->find()) {
             while ($fave->fetch()) {
-                Fave::blowCacheForProfileId($fave->user_id);
                 $fave->delete();
             }
         }
@@ -256,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();