]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Start handling salmon entries directly with Notice::saveActivity
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 16 Jan 2016 16:25:29 +0000 (17:25 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 16 Jan 2016 16:25:29 +0000 (17:25 +0100)
More to come...

lib/activityhandlerplugin.php
plugins/OStatus/lib/magicenvelope.php
plugins/OStatus/lib/salmonaction.php

index 988a6c30a3f5f5ead193123b5dc2a317eb319eca..cb8a6b9bc91c6d42a528f804ef0660a1d8d4af43 100644 (file)
@@ -380,6 +380,11 @@ abstract class ActivityHandlerPlugin extends Plugin
         if (!$this->isMyActivity($activity)) {
             return true;
         }
+        if (!isset($this->oldSaveNew)) {
+            // Handle saveActivity in OStatus class for incoming salmon, remove this event
+            // handler when all plugins have gotten rid of "oldSaveNew".
+            return true;
+        }
 
         $this->log(LOG_INFO, get_called_class()." checking {$activity->id} as a valid Salmon slap.");
 
@@ -428,11 +433,7 @@ abstract class ActivityHandlerPlugin extends Plugin
                          'is_local' => Notice::REMOTE,
                          'source' => 'ostatus');
 
-        if (!isset($this->oldSaveNew)) {
-            $notice = Notice::saveActivity($activity, $actor, $options);
-        } else {
-            $notice = $this->saveNoticeFromActivity($activity, $actor, $options);
-        }
+        $notice = $this->saveNoticeFromActivity($activity, $actor, $options);
 
         return false;
     }
index a60880dd7e2e5d856edc5b191a9c42212b52214d..35171895abfb183199f2395b66fa621baa7940e5 100644 (file)
@@ -250,7 +250,7 @@ class MagicEnvelope
     {
         $dom = new DOMDocument();
         if (!$dom->loadXML(Magicsig::base64_url_decode($this->data))) {
-            throw new ServerException('Malformed XML in Salmon payload');
+            throw new ClientException('Malformed XML in Salmon payload');
         }
 
         switch ($this->data_type) {
@@ -274,7 +274,7 @@ class MagicEnvelope
             $dom->documentElement->appendChild($prov);
             break;
         default:
-            throw new ServerException('Unknown Salmon payload data type');
+            throw new ClientException('Unknown Salmon payload data type');
         }
         return $dom;
     }
index a2703f1647fbef952baa3f9b310bf9f35bb51f8d..6855fd1b180af27c9a2de155503fab2451c0df48 100644 (file)
@@ -55,13 +55,13 @@ class SalmonAction extends Action
             break;
         default:
             // TRANS: Client error. Do not translate the quoted "application/[type]" strings.
-            $this->clientError(_m('Salmon requires "application/magic-envelope+xml". For Diaspora we also accept "application/x-www-form-urlencoded" with an "xml" parameter.', 415));
+            throw new ClientException(_m('Salmon requires "application/magic-envelope+xml". For Diaspora we also accept "application/x-www-form-urlencoded" with an "xml" parameter.', 415));
         }
 
+        if (empty($envxml)) {
+            throw new ClientException('No magic envelope supplied in POST.');
+        }
         try {
-            if (empty($envxml)) {
-                throw new ClientException('No magic envelope supplied in POST.');
-            }
             $magic_env = new MagicEnvelope($envxml);   // parse incoming XML as a MagicEnvelope
 
             $entry = $magic_env->getPayload();  // Not cryptographically verified yet!
@@ -70,13 +70,14 @@ class SalmonAction extends Action
                 common_log(LOG_ERR, "broken actor: " . var_export($this->activity->actor->id, true));
                 common_log(LOG_ERR, "activity with no actor: " . var_export($this->activity, true));
                 // TRANS: Exception.
-                throw new Exception(_m('Received a salmon slap from unidentified actor.'));
+                throw new ClientException(_m('Activity in salmon slap has no actor id.'));
             }
             // ensureProfiles sets $this->actor and $this->oprofile
             $this->ensureProfiles();
         } catch (Exception $e) {
             common_debug('Salmon envelope parsing failed with: '.$e->getMessage());
-            $this->clientError($e->getMessage());
+            // convert exception to ClientException
+            throw new ClientException($e->getMessage());
         }
 
         // Cryptographic verification test, throws exception on failure
@@ -93,7 +94,23 @@ class SalmonAction extends Action
     {
         parent::handle();
 
+        assert($this->activity instanceof Activity);
+        assert($this->target instanceof Profile);
+
         common_log(LOG_DEBUG, "Got a " . $this->activity->verb);
+        try {
+            $options = [ 'source' => 'ostatus' ];
+            common_debug('Save salmon slap directly with Notice::saveActivity for actor=='.$this->actor->getID());
+            $stored = Notice::saveActivity($this->activity, $this->actor, $options);
+            common_debug('Save salmon slap finished, notice id=='.$stored->getID());
+            return true;
+        } catch (AlreadyFulfilledException $e) {
+            // The action's results are already fulfilled. Maybe it was a
+            // duplicate? Maybe someone's database is out of sync?
+            // Let's just accept it and move on.
+            common_log(LOG_INFO, 'Salmon slap carried an event which had already been fulfilled.');
+        }
+
         try {
             if (Event::handle('StartHandleSalmonTarget', array($this->activity, $this->target)) &&
                     Event::handle('StartHandleSalmon', array($this->activity))) {