]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Use deferred workers instead of the queue mechanism
[friendica.git] / src / Protocol / Diaspora.php
index ca66aa0a67d73e820999fe21f5809952f2043304..768b4c7b07e8789ad36ef7745ab2487a42ffa9f0 100644 (file)
@@ -1135,8 +1135,11 @@ class Diaspora
                //      Logger::log("defining user ".$contact["nick"]." as friend");
                //}
 
-               // We don't seem to like that person
-               if ($contact["blocked"]) {
+               // Contact server is blocked
+               if (Network::isUrlBlocked($contact['url'])) {
+                       return false;
+                       // We don't seem to like that person
+               } elseif ($contact["blocked"]) {
                        // Maybe blocked, don't accept.
                        return false;
                        // We are following this person?
@@ -2625,6 +2628,54 @@ class Diaspora
                return false;
        }
 
+       /**
+        * @brief Stores a reshare activity
+        *
+        * @param array   $item              Array of reshare post
+        * @param integer $parent_message_id Id of the parent post
+        * @param string  $guid              GUID string of reshare action
+        * @param string  $author            Author handle
+        */
+       private static function addReshareActivity($item, $parent_message_id, $guid, $author)
+       {
+               $parent = Item::selectFirst(['uri', 'guid'], ['id' => $parent_message_id]);
+
+               $datarray = [];
+
+               $datarray['uid'] = $item['uid'];
+               $datarray['contact-id'] = $item['contact-id'];
+               $datarray['network'] = $item['network'];
+
+               $datarray['author-link'] = $item['author-link'];
+               $datarray['author-id'] = $item['author-id'];
+
+               $datarray['owner-link'] = $datarray['author-link'];
+               $datarray['owner-id'] = $datarray['author-id'];
+
+               $datarray['guid'] = $parent['guid'] . '-' . $guid;
+               $datarray['uri'] = self::getUriFromGuid($author, $datarray['guid']);
+               $datarray['parent-uri'] = $parent['uri'];
+
+               $datarray['verb'] = $datarray['body'] = ACTIVITY2_ANNOUNCE;
+               $datarray['gravity'] = GRAVITY_ACTIVITY;
+               $datarray['object-type'] = ACTIVITY_OBJ_NOTE;
+
+               $datarray['protocol'] = $item['protocol'];
+
+               $datarray['plink'] = self::plink($author, $datarray['guid']);
+               $datarray['private'] = $item['private'];
+               $datarray['changed'] = $datarray['created'] = $datarray['edited'] = $item['created'];
+
+               $message_id = Item::insert($datarray);
+
+               if ($message_id) {
+                       Logger::info('Stored reshare activity.', ['guid' => $guid, 'id' => $message_id]);
+                       if ($datarray['uid'] == 0) {
+                               Item::distribute($message_id);
+                       }
+               }
+       }
+
        /**
         * @brief Processes a reshare message
         *
@@ -2708,6 +2759,11 @@ class Diaspora
 
                self::sendParticipation($contact, $datarray);
 
+               $root_message_id = self::messageExists($importer["uid"], $root_guid);
+               if ($root_message_id) {
+                       self::addReshareActivity($datarray, $root_message_id, $guid, $author);
+               }
+
                if ($message_id) {
                        Logger::log("Stored reshare ".$datarray["guid"]." with message id ".$message_id, Logger::DEBUG);
                        if ($datarray['uid'] == 0) {
@@ -3167,9 +3223,9 @@ class Diaspora
 
                if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeader(), "retry-after")))) {
                        if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::TYPE_RELAY)) {
-                               Logger::log("queue message");
-                               // queue message for redelivery
-                               Queue::add($contact["id"], Protocol::DIASPORA, $envelope, $public_batch, $guid);
+                               Logger::info('defer message', ['log' => $logid, 'guid' => $guid, 'destination' => $dest_url]);
+                               // defer message for redelivery
+                               Worker::defer();
                        }
 
                        // The message could not be delivered. We mark the contact as "dead"
@@ -3207,13 +3263,12 @@ class Diaspora
         * @param array  $message      The message data
         * @param bool   $public_batch Is it a public post?
         * @param string $guid         message guid
-        * @param bool   $spool        Should the transmission be spooled or transmitted?
         *
         * @return int Result of the transmission
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function buildAndTransmit(array $owner, array $contact, $type, $message, $public_batch = false, $guid = "", $spool = false)
+       private static function buildAndTransmit(array $owner, array $contact, $type, $message, $public_batch = false, $guid = "")
        {
                $msg = self::buildPostXml($type, $message);
 
@@ -3227,12 +3282,7 @@ class Diaspora
 
                $envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch);
 
-               if ($spool) {
-                       Queue::add($contact['id'], Protocol::DIASPORA, $envelope, $public_batch, $guid);
-                       return true;
-               } else {
-                       $return_code = self::transmit($owner, $contact, $envelope, $public_batch, false, $guid);
-               }
+               $return_code = self::transmit($owner, $contact, $envelope, $public_batch, false, $guid);
 
                Logger::log("guid: ".$guid." result ".$return_code, Logger::DEBUG);
 
@@ -4228,7 +4278,7 @@ class Diaspora
 
                foreach ($recips as $recip) {
                        Logger::log("Send updated profile data for user ".$uid." to contact ".$recip["id"], Logger::DEBUG);
-                       self::buildAndTransmit($owner, $recip, "profile", $message, false, "", false);
+                       self::buildAndTransmit($owner, $recip, "profile", $message, false);
                }
        }