]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Merge pull request #12586 from MrPetovan/task/entitize-delivery-queue
[friendica.git] / src / Protocol / Diaspora.php
index 3c60f4041ba98ae374dbcce1f5021bf6c5064e7b..bf6bfdd63dcefd078ff2fa36e4e86d40e198b15c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -43,13 +43,13 @@ use Friendica\Model\User;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 use Friendica\Network\HTTPException;
 use Friendica\Network\Probe;
+use Friendica\Protocol\Delivery;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
-use Friendica\Worker\Delivery;
 use GuzzleHttp\Psr7\Uri;
 use SimpleXMLElement;
 
@@ -499,7 +499,7 @@ class Diaspora
                }
 
                if (!($fields = self::validPosting($msg))) {
-                       Logger::warning('Invalid posting', ['msg' => $msg]);
+                       Logger::notice('Invalid posting', ['msg' => $msg]);
                        return false;
                }
 
@@ -534,7 +534,7 @@ class Diaspora
                if (is_null($fields)) {
                        $private = true;
                        if (!($fields = self::validPosting($msg))) {
-                               Logger::warning('Invalid posting', ['msg' => $msg]);
+                               Logger::notice('Invalid posting', ['msg' => $msg]);
                                return false;
                        }
                } else {
@@ -812,6 +812,7 @@ class Diaspora
         */
        private static function contactByHandle(int $uid, WebFingerUri $uri): array
        {
+               Contact::updateByUrlIfNeeded($uri->getAddr());
                return Contact::getByURL($uri->getAddr(), null, [], $uid);
        }
 
@@ -826,9 +827,15 @@ class Diaspora
         */
        public static function isSupportedByContactUrl(string $url, ?bool $update = null): bool
        {
-               $contact = Contact::getByURL($url, $update);
+               $contact = Contact::getByURL($url, $update, ['uri-id', 'network']);
 
-               return DI::dsprContact()->existsByUriId($contact['uri-id'] ?? 0);
+               $supported = DI::dsprContact()->existsByUriId($contact['uri-id'] ?? 0);
+
+               if (!$supported && is_null($update) && ($contact['network'] == Protocol::DFRN)) {
+                       $supported = self::isSupportedByContactUrl($url, true);
+               }
+
+               return $supported;
        }
 
        /**
@@ -2279,65 +2286,6 @@ class Diaspora
                return true;
        }
 
-       /**
-        * 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 WebFingerUri $author            Author handle
-        * @return false|void
-        * @throws InternalServerErrorException
-        * @throws \ImagickException
-        */
-       private static function addReshareActivity(array $item, int $parent_message_id, string $guid, WebFingerUri $author)
-       {
-               $parent = Post::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($datarray['guid'], $author);
-               $datarray['thr-parent'] = $parent['uri'];
-
-               $datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE;
-               $datarray['gravity'] = Item::GRAVITY_ACTIVITY;
-               $datarray['object-type'] = Activity\ObjectType::NOTE;
-
-               $datarray['protocol'] = $item['protocol'];
-               $datarray['source'] = $item['source'];
-               $datarray['direction'] = $item['direction'];
-               $datarray['post-reason'] = $item['post-reason'];
-
-               $datarray['plink'] = self::plink($author, $datarray['guid']);
-               $datarray['private'] = $item['private'];
-               $datarray['changed'] = $datarray['created'] = $datarray['edited'] = $item['created'];
-
-               if (Item::isTooOld($datarray)) {
-                       Logger::info('Reshare activity is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
-                       return false;
-               }
-
-               $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);
-                       }
-               }
-       }
-
        /**
         * Processes a reshare message
         *
@@ -2430,11 +2378,6 @@ 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::info('Stored reshare ' . $datarray['guid'] . ' with message id ' . $message_id);
                        if ($datarray['uid'] == 0) {
@@ -3012,6 +2955,12 @@ class Diaspora
                        return 200;
                }
 
+               if (!empty($contact['gsid']) && (empty($return_code) || $postResult->isTimeout())) {
+                       GServer::setFailureById($contact['gsid']);
+               } elseif (!empty($contact['gsid']) && ($return_code >= 200) && ($return_code <= 299)) {
+                       GServer::setReachableById($contact['gsid'], Protocol::DIASPORA);
+               }
+
                Logger::notice('transmit: ' . $logid . '-' . $guid . ' to ' . $dest_url . ' returns: ' . $return_code);
 
                return $return_code ? $return_code : -1;
@@ -4064,7 +4013,7 @@ class Diaspora
                        return false;
                }
 
-               if (!self::isSupportedByContactUrl($parent_post['author-link'], false)) {
+               if (!self::isSupportedByContactUrl($parent_post['author-link'])) {
                        Logger::info('Parent author is no Diaspora contact.', ['parent-id' => $parent_id]);
                        return false;
                }