]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activitymover.php
Removed plugin Google-Analytics as this is free/libre and decentralized
[quix0rs-gnu-social.git] / lib / activitymover.php
index b308ad5624c1188b230cdbece2e2cfb7f3d74c54..74c5c68ad688d8d824394f2d414e66ae2e0dc72c 100644 (file)
@@ -55,8 +55,15 @@ class ActivityMover extends QueueHandler
     {
         list ($act, $sink, $userURI, $remoteURI) = $data;
 
-        $user   = User::staticGet('uri', $userURI);
-        $remote = Profile::fromURI($remoteURI);
+        $user   = User::getKV('uri', $userURI);
+        try {
+            $remote = Profile::fromUri($remoteURI);
+        } catch (UnknownUriException $e) {
+            // Don't retry. It's hard to tell whether it's because of
+            // lookup failures or because the URI is permanently gone.
+            // If we knew it was temporary, we'd return false here.
+            return true;
+        }
 
         try {
             $this->moveActivity($act, $sink, $user, $remote);
@@ -81,32 +88,33 @@ class ActivityMover extends QueueHandler
     function moveActivity($act, $sink, $user, $remote)
     {
         if (empty($user)) {
-            throw new Exception(sprintf(_("No such user %s."),$act->actor->id));
+            // TRANS: Exception thrown if a non-existing user is provided. %s is a user ID.
+            throw new Exception(sprintf(_('No such user "%s".'),$act->actor->id));
         }
 
         switch ($act->verb) {
-        case ActivityVerb::FAVORITE:
+/*        case ActivityVerb::FAVORITE:
             $this->log(LOG_INFO,
                        "Moving favorite of {$act->objects[0]->id} by ".
                        "{$act->actor->id} to {$remote->nickname}.");
             // push it, then delete local
             $sink->postActivity($act);
-            $notice = Notice::staticGet('uri', $act->objects[0]->id);
+            $notice = Notice::getKV('uri', $act->objects[0]->id);
             if (!empty($notice)) {
                 $fave = Fave::pkeyGet(array('user_id' => $user->id,
                                             'notice_id' => $notice->id));
                 $fave->delete();
             }
-            break;
+            break;*/
         case ActivityVerb::POST:
             $this->log(LOG_INFO,
                        "Moving notice {$act->objects[0]->id} by ".
                        "{$act->actor->id} to {$remote->nickname}.");
             // XXX: send a reshare, not a post
             $sink->postActivity($act);
-            $notice = Notice::staticGet('uri', $act->objects[0]->id);
+            $notice = Notice::getKV('uri', $act->objects[0]->id);
             if (!empty($notice)) {
-                $notice->delete();
+                $notice->deleteAs($user->getProfile(), false);
             }
             break;
         case ActivityVerb::JOIN:
@@ -114,29 +122,31 @@ class ActivityMover extends QueueHandler
                        "Moving group join of {$act->objects[0]->id} by ".
                        "{$act->actor->id} to {$remote->nickname}.");
             $sink->postActivity($act);
-            $group = User_group::staticGet('uri', $act->objects[0]->id);
+            $group = User_group::getKV('uri', $act->objects[0]->id);
             if (!empty($group)) {
                 $user->leaveGroup($group);
             }
             break;
         case ActivityVerb::FOLLOW:
-            if ($act->actor->id == $user->uri) {
+            if ($act->actor->id === $user->getUri()) {
                 $this->log(LOG_INFO,
                            "Moving subscription to {$act->objects[0]->id} by ".
                            "{$act->actor->id} to {$remote->nickname}.");
                 $sink->postActivity($act);
-                $other = Profile::fromURI($act->objects[0]->id);
-                if (!empty($other)) {
+                try {
+                    $other = Profile::fromUri($act->objects[0]->id);
                     Subscription::cancel($user->getProfile(), $other);
+                } catch (UnknownUriException $e) {
+                    // Can't cancel subscription if we don't know who to alert
                 }
             } else {
-                $otherUser = User::staticGet('uri', $act->actor->id);
+                $otherUser = User::getKV('uri', $act->actor->id);
                 if (!empty($otherUser)) {
                     $this->log(LOG_INFO,
                                "Changing sub to {$act->objects[0]->id}".
                                "by {$act->actor->id} to {$remote->nickname}.");
                     $otherProfile = $otherUser->getProfile();
-                    Subscription::start($otherProfile, $remote);
+                    Subscription::ensureStart($otherProfile, $remote);
                     Subscription::cancel($otherProfile, $user->getProfile());
                 } else {
                     $this->log(LOG_NOTICE,