]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Added processing of incoming block notices
[friendica.git] / src / Protocol / Diaspora.php
index 7ca01f9966abb4074558d87a13c2cc047b257c8c..154d65f6f985ba3aedfb282763b7a0642194bf35 100644 (file)
@@ -41,6 +41,7 @@ use Friendica\Model\Mail;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
+use Friendica\Network\HTTPClient\Client\HttpClient;
 use Friendica\Network\Probe;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
@@ -454,7 +455,7 @@ class Diaspora
         * Dispatches public messages and find the fitting receivers
         *
         * @param array $msg       The post that will be dispatched
-        * @param int   $direction Indicates if the message had been fetched or pushed
+        * @param int   $direction Indicates if the message had been fetched or pushed (self::PUSHED, self::FETCHED, self::FORCED_FETCH)
         *
         * @return int The message id of the generated message, "true" or "false" if there was an error
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -485,7 +486,7 @@ class Diaspora
         * @param array            $importer  Array of the importer user
         * @param array            $msg       The post that will be dispatched
         * @param SimpleXMLElement $fields    SimpleXML object that contains the message
-        * @param int              $direction Indicates if the message had been fetched or pushed
+        * @param int              $direction Indicates if the message had been fetched or pushed (self::PUSHED, self::FETCHED, self::FORCED_FETCH)
         *
         * @return int The message id of the generated message, "true" or "false" if there was an error
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -1059,7 +1060,7 @@ class Diaspora
 
                Logger::info("Fetch post from ".$source_url);
 
-               $envelope = DI::httpClient()->fetch($source_url);
+               $envelope = DI::httpClient()->fetch($source_url, 0, HttpClient::ACCEPT_MAGIC);
                if ($envelope) {
                        Logger::info("Envelope was fetched.");
                        $x = self::verifyMagicEnvelope($envelope);
@@ -1449,7 +1450,7 @@ class Diaspora
         * @param string $sender    The sender of the message
         * @param object $data      The message object
         * @param string $xml       The original XML of the message
-        * @param int    $direction Indicates if the message had been fetched or pushed
+        * @param int    $direction Indicates if the message had been fetched or pushed (self::PUSHED, self::FETCHED, self::FORCED_FETCH)
         *
         * @return int The message id of the generated comment or "false" if there was an error
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -1705,7 +1706,7 @@ class Diaspora
         * @param array  $importer  Array of the importer user
         * @param string $sender    The sender of the message
         * @param object $data      The message object
-        * @param int    $direction Indicates if the message had been fetched or pushed
+        * @param int    $direction Indicates if the message had been fetched or pushed (self::PUSHED, self::FETCHED, self::FORCED_FETCH)
         *
         * @return int The message id of the generated like or "false" if there was an error
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -1892,7 +1893,7 @@ class Diaspora
         *
         * @param array  $importer  Array of the importer user
         * @param object $data      The message object
-        * @param int    $direction Indicates if the message had been fetched or pushed
+        * @param int    $direction Indicates if the message had been fetched or pushed (self::PUSHED, self::FETCHED, self::FORCED_FETCH)
         *
         * @return bool success
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -2385,7 +2386,7 @@ class Diaspora
         * @param array  $importer  Array of the importer user
         * @param object $data      The message object
         * @param string $xml       The original XML of the message
-        * @param int    $direction Indicates if the message had been fetched or pushed
+        * @param int    $direction Indicates if the message had been fetched or pushed (self::PUSHED, self::FETCHED, self::FORCED_FETCH)
         *
         * @return int the message id
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -2616,31 +2617,30 @@ class Diaspora
        /**
         * Checks if an incoming message is wanted
         *
-        * @param string $url
-        * @param integer $uriid
+        * @param array  $item
         * @param string $author
         * @param string $body
-        * @param int    $direction Indicates if the message had been fetched or pushed
+        * @param int    $direction Indicates if the message had been fetched or pushed (self::PUSHED, self::FETCHED, self::FORCED_FETCH)
         *
         * @return boolean Is the message wanted?
         */
-       private static function isSolicitedMessage(string $url, int $uriid, string $author, string $body, int $direction)
+       private static function isSolicitedMessage(array $item, string $author, string $body, int $direction)
        {
                $contact = Contact::getByURL($author);
                if (DBA::exists('contact', ["`nurl` = ? AND `uid` != ? AND `rel` IN (?, ?)",
                        $contact['nurl'], 0, Contact::FRIEND, Contact::SHARING])) {
-                       Logger::debug('Author has got followers - accepted', ['url' => $url, 'author' => $author]);
+                       Logger::debug('Author has got followers - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri'], 'author' => $author]);
                        return true;
                }
 
                if ($direction == self::FORCED_FETCH) {
-                       Logger::debug('Post is a forced fetch - accepted', ['url' => $url, 'author' => $author]);
+                       Logger::debug('Post is a forced fetch - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri'], 'author' => $author]);
                        return true;
                }
 
-               $tags = array_column(Tag::getByURIId($uriid, [Tag::HASHTAG]), 'name');
-               if (Relay::isSolicitedPost($tags, $body, $contact['id'], $url, Protocol::DIASPORA)) {
-                       Logger::debug('Post is accepted because of the relay settings', ['url' => $url, 'author' => $author]);
+               $tags = array_column(Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]), 'name');
+               if (Relay::isSolicitedPost($tags, $body, $contact['id'], $item['uri'], Protocol::DIASPORA)) {
+                       Logger::debug('Post is accepted because of the relay settings', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri'], 'author' => $author]);
                        return true;
                } else {
                        return false;
@@ -2673,7 +2673,7 @@ class Diaspora
         * @param array            $importer  Array of the importer user
         * @param SimpleXMLElement $data      The message object
         * @param string           $xml       The original XML of the message
-        * @param int              $direction Indicates if the message had been fetched or pushed
+        * @param int              $direction Indicates if the message had been fetched or pushed (self::PUSHED, self::FETCHED, self::FORCED_FETCH)
         *
         * @return int The message id of the newly created item
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -2771,7 +2771,7 @@ class Diaspora
                self::storeMentions($datarray['uri-id'], $text);
                Tag::storeRawTagsFromBody($datarray['uri-id'], $datarray["body"]);
 
-               if (!self::isSolicitedMessage($datarray["uri"], $datarray['uri-id'], $author, $body, $direction)) {
+               if (!self::isSolicitedMessage($datarray, $author, $body, $direction)) {
                        DBA::delete('item-uri', ['uri' => $datarray['uri']]);
                        return false;
                }