]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activityimporter.php
Add urlshortenerplugin2.php to solve some @todo's and adding exceptions
[quix0rs-gnu-social.git] / lib / activityimporter.php
index aa9b95e084c6b80fb54f717e3ecbde991e90c212..1c34b64d35db8b84826b8bcaf1734fae32e7eeb2 100644 (file)
@@ -63,9 +63,9 @@ class ActivityImporter extends QueueHandler
 
         $done = null;
 
-        if (Event::handle('StartImportActivity',
-                          array($user, $author, $activity, $trusted, &$done))) {
-            try {
+        try {
+            if (Event::handle('StartImportActivity',
+                              array($user, $author, $activity, $trusted, &$done))) {
                 switch ($activity->verb) {
                 case ActivityVerb::FOLLOW:
                     $this->subscribeProfile($user, $author, $activity);
@@ -83,16 +83,10 @@ class ActivityImporter extends QueueHandler
                 Event::handle('EndImportActivity',
                               array($user, $author, $activity, $trusted));
                 $done = true;
-            } catch (ClientException $ce) {
-                common_log(LOG_WARNING, $ce->getMessage());
-                $done = true;
-            } catch (ServerException $se) {
-                common_log(LOG_ERR, $se->getMessage());
-                $done = false;
-            } catch (Exception $e) {
-                common_log(LOG_ERR, $e->getMessage());
-                $done = false;
             }
+        } catch (Exception $e) {
+            common_log(LOG_ERR, $e->getMessage());
+            $done = true;
         }
         return $done;
     }
@@ -104,17 +98,17 @@ class ActivityImporter extends QueueHandler
         if ($activity->objects[0]->id == $author->id) {
             if (!$this->trusted) {
                 // TRANS: Client exception thrown when trying to force a subscription for an untrusted user.
-                throw new ClientException(_("Cannot force subscription for untrusted user."));
+                throw new ClientException(_('Cannot force subscription for untrusted user.'));
             }
 
             $other = $activity->actor;
-            $otherUser = User::staticGet('uri', $other->id);
+            $otherUser = User::getKV('uri', $other->id);
 
             if (!empty($otherUser)) {
                 $otherProfile = $otherUser->getProfile();
             } else {
-                // TRANS: Client exception thrown when trying to for a remote user to subscribe.
-                throw new Exception(_("Cannot force remote user to subscribe."));
+                // TRANS: Client exception thrown when trying to force a remote user to subscribe.
+                throw new Exception(_('Cannot force remote user to subscribe.'));
             }
 
             // XXX: don't do this for untrusted input!
@@ -129,13 +123,13 @@ class ActivityImporter extends QueueHandler
 
             if (empty($otherProfile)) {
                 // TRANS: Client exception thrown when trying to subscribe to an unknown profile.
-                throw new ClientException(_("Unknown profile."));
+                throw new ClientException(_('Unknown profile.'));
             }
 
             Subscription::start($profile, $otherProfile);
         } else {
             // TRANS: Client exception thrown when trying to import an event not related to the importing user.
-            throw new Exception(_("This activity seems unrelated to our user."));
+            throw new Exception(_('This activity seems unrelated to our user.'));
         }
     }
 
@@ -145,13 +139,13 @@ class ActivityImporter extends QueueHandler
 
         $uri = $activity->objects[0]->id;
 
-        $group = User_group::staticGet('uri', $uri);
+        $group = User_group::getKV('uri', $uri);
 
         if (empty($group)) {
             $oprofile = Ostatus_profile::ensureActivityObjectProfile($activity->objects[0]);
             if (!$oprofile->isGroup()) {
                 // TRANS: Client exception thrown when trying to join a remote group that is not a group.
-                throw new ClientException(_("Remote profile is not a group!"));
+                throw new ClientException(_('Remote profile is not a group!'));
             }
             $group = $oprofile->localGroup();
         }
@@ -163,10 +157,7 @@ class ActivityImporter extends QueueHandler
             throw new ClientException(_("User is already a member of this group."));
         }
 
-        if (Event::handle('StartJoinGroup', array($group, $user))) {
-            Group_member::join($group->id, $user->id);
-            Event::handle('EndJoinGroup', array($group, $user));
-        }
+        $user->joinGroup($group);
     }
 
     // XXX: largely cadged from Ostatus_profile::processNote()
@@ -177,7 +168,7 @@ class ActivityImporter extends QueueHandler
 
         $sourceUri = $note->id;
 
-        $notice = Notice::staticGet('uri', $sourceUri);
+        $notice = Notice::getKV('uri', $sourceUri);
 
         if (!empty($notice)) {
 
@@ -204,7 +195,7 @@ class ActivityImporter extends QueueHandler
                 }
             } else {
                 // TRANS: Client exception thrown when trying to overwrite the author information for a non-trusted user during import.
-                throw new ClientException(_("Not overwriting author info for non-trusted user."));
+                throw new ClientException(_('Not overwriting author info for non-trusted user.'));
             }
         }
 
@@ -220,7 +211,7 @@ class ActivityImporter extends QueueHandler
             // @fixme fetch from $sourceUrl?
             // TRANS: Client exception thrown when trying to import a notice without content.
             // TRANS: %s is the notice URI.
-            throw new ClientException(sprintf(_("No content for notice %s."),$sourceUri));
+            throw new ClientException(sprintf(_('No content for notice %s.'),$sourceUri));
         }
 
         // Get (safe!) HTML and text versions of the content
@@ -253,7 +244,7 @@ class ActivityImporter extends QueueHandler
             // Maintain direct reply associations
             // @fixme what about conversation ID?
             if (!empty($activity->context->replyToID)) {
-                $orig = Notice::staticGet('uri',
+                $orig = Notice::getKV('uri',
                                           $activity->context->replyToID);
                 if (!empty($orig)) {
                     $options['reply_to'] = $orig->id;
@@ -299,19 +290,19 @@ class ActivityImporter extends QueueHandler
         return $saved;
     }
 
-    function filterAttention($attn)
+    protected function filterAttention(array $attn)
     {
-        $groups = array();
-        $replies = array();
+        $groups = array();  // TODO: context->attention
+        $replies = array(); // TODO: context->attention
 
-        foreach (array_unique($attn) as $recipient) {
+        foreach ($attn as $recipient=>$type) {
 
             // Is the recipient a local user?
 
-            $user = User::staticGet('uri', $recipient);
+            $user = User::getKV('uri', $recipient);
 
-            if ($user) {
-                // @fixme sender verification, spam etc?
+            if ($user instanceof User) {
+                // TODO: @fixme sender verification, spam etc?
                 $replies[] = $recipient;
                 continue;
             }
@@ -328,12 +319,12 @@ class ActivityImporter extends QueueHandler
             }
 
             // Is the recipient a local group?
-            // @fixme uri on user_group isn't reliable yet
-            // $group = User_group::staticGet('uri', $recipient);
+            // TODO: @fixme uri on user_group isn't reliable yet
+            // $group = User_group::getKV('uri', $recipient);
             $id = OStatusPlugin::localGroupFromUrl($recipient);
 
             if ($id) {
-                $group = User_group::staticGet('id', $id);
+                $group = User_group::getKV('id', $id);
                 if ($group) {
                     // Deliver to all members of this local group if allowed.
                     $profile = $sender->localProfile();