]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/classes/Ostatus_profile.php
- break OMB profile update pings to a background queue
[quix0rs-gnu-social.git] / plugins / OStatus / classes / Ostatus_profile.php
index 9f9efb96ee98f3e3b219258c4c8859ed3490c6fb..61505206ece5ec5369f9e5f8ba5d150fd7080354 100644 (file)
@@ -431,21 +431,57 @@ class Ostatus_profile extends Memcached_DataObject
         return false;
     }
 
-    public function notifyActivity($activity)
+    /**
+     * Send a Salmon notification ping immediately, and confirm that we got
+     * an acceptable response from the remote site.
+     *
+     * @param mixed $entry XML string, Notice, or Activity
+     * @return boolean success
+     */
+    public function notifyActivity($entry)
     {
         if ($this->salmonuri) {
+            $salmon = new Salmon();
+            return $salmon->post($this->salmonuri, $this->notifyPrepXml($entry));
+        }
 
-            $xml = '<?xml version="1.0" encoding="UTF-8" ?' . '>' .
-                          $activity->asString(true);
+        return false;
+    }
 
-            $salmon = new Salmon(); // ?
+    /**
+     * Queue a Salmon notification for later. If queues are disabled we'll
+     * send immediately but won't get the return value.
+     *
+     * @param mixed $entry XML string, Notice, or Activity
+     * @return boolean success
+     */
+    public function notifyDeferred($entry)
+    {
+        if ($this->salmonuri) {
+            $data = array('salmonuri' => $this->salmonuri,
+                          'entry' => $this->notifyPrepXml($entry));
 
-            return $salmon->post($this->salmonuri, $xml);
+            $qm = QueueManager::get();
+            return $qm->enqueue($data, 'salmon');
         }
 
         return false;
     }
 
+    protected function notifyPrepXml($entry)
+    {
+        $preamble = '<?xml version="1.0" encoding="UTF-8" ?' . '>';
+        if (is_string($entry)) {
+            return $entry;
+        } else if ($entry instanceof Activity) {
+            return $preamble . $entry->asString(true);
+        } else if ($entry instanceof Notice) {
+            return $preamble . $entry->asAtomEntry(true, true);
+        } else {
+            throw new ServerException("Invalid type passed to Ostatus_profile::notify; must be XML string or Activity entry");
+        }
+    }
+
     function getBestName()
     {
         if ($this->isGroup()) {