]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Fix missing attached links in posts
[friendica.git] / src / Protocol / Diaspora.php
index 19954d9b963bb6f3240bb014ee4a3f687289b0a3..91eb1cc2c412717878f48a9827a2fd5e2a84781e 100644 (file)
@@ -792,7 +792,7 @@ class Diaspora
         */
        private static function key(WebFingerUri $uri): string
        {
-               Logger::notice('Fetching diaspora key', ['handle' => $uri->getAddr(), 'callstack' => System::callstack(20)]);
+               Logger::info('Fetching diaspora key', ['handle' => $uri->getAddr(), 'callstack' => System::callstack(20)]);
                try {
                        return DI::dsprContact()->getByAddr($uri)->pubKey;
                } catch (HTTPException\NotFoundException|\InvalidArgumentException $e) {
@@ -2855,7 +2855,7 @@ class Diaspora
 
                $namespaces = ['me' => ActivityNamespace::SALMON_ME];
 
-               return XML::fromArray($xmldata, $xml, false, $namespaces);
+               return XML::fromArray($xmldata, $dummy, false, $namespaces);
        }
 
        /**
@@ -2958,7 +2958,7 @@ class Diaspora
                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']);
+                       GServer::setReachableById($contact['gsid'], Protocol::DIASPORA);
                }
 
                Logger::notice('transmit: ' . $logid . '-' . $guid . ' to ' . $dest_url . ' returns: ' . $return_code);
@@ -2974,12 +2974,11 @@ class Diaspora
         * @param array  $message The message data
         *
         * @return string The post XML
+        * @throws \Exception
         */
        public static function buildPostXml(string $type, array $message): string
        {
-               $data = [$type => $message];
-
-               return XML::fromArray($data, $xml);
+               return XML::fromArray([$type => $message]);
        }
 
        /**
@@ -3317,8 +3316,17 @@ class Diaspora
 
                        $type = 'reshare';
                } else {
+                       $native_photos = DI::config()->get('diaspora', 'native_photos');
+                       if ($native_photos) {
+                               $item['body'] = Post\Media::removeFromEndOfBody($item['body']);
+                               $attach_media = [Post\Media::AUDIO, Post\Media::VIDEO];
+                       } else {
+                               $attach_media = [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO];
+                       }
+
                        $title = $item['title'];
-                       $body  = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
+                       $body  = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item), $attach_media);
+                       $body  = Post\Media::addHTMLLinkToBody($item['uri-id'], $body);
 
                        // Fetch the title from an attached link - if there is one
                        if (empty($item['title']) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
@@ -3366,6 +3374,10 @@ class Diaspora
                                'location' => $location
                        ];
 
+                       if ($native_photos) {
+                               $message = self::addPhotos($item, $message);
+                       }
+
                        // Diaspora rejects messages when they contain a location without "lat" or "lng"
                        if (!isset($location['lat']) || !isset($location['lng'])) {
                                unset($message['location']);
@@ -3400,6 +3412,44 @@ class Diaspora
                return $msg;
        }
 
+       /**
+        * Add photo elements to the message array
+        *
+        * @param array $item
+        * @param array $message
+        * @return array
+        */
+       private static function addPhotos(array $item, array $message): array
+       {
+               $medias = Post\Media::getByURIId($item['uri-id'], [Post\Media::IMAGE]);
+               $public = ($item['private'] == Item::PRIVATE ? 'false' : 'true');
+
+               $counter = 0;
+               foreach ($medias as $media) {
+                       if (Item::containsLink($item['body'], $media['preview'] ?? $media['url'], $media['type'])) {
+                               continue;
+                       }
+
+                       $name = basename($media['url']);
+                       $path = str_replace($name, '', $media['url']);
+
+                       $message[++$counter . ':photo'] = [
+                               'guid'                => Item::guid(['uri' => $media['url']], false),
+                               'author'              => $item['author-addr'],
+                               'public'              => $public,
+                               'created_at'          => $item['created'],
+                               'remote_photo_path'   => $path,
+                               'remote_photo_name'   => $name,
+                               'status_message_guid' => $item['guid'],
+                               'height'              => $media['height'],
+                               'width'               => $media['width'],
+                               'text'                => $media['description'],
+                       ];
+               }
+
+               return $message;
+       }
+
        private static function prependParentAuthorMention(string $body, string $profile_url): string
        {
                $profile = Contact::getByURL($profile_url, false, ['addr', 'name']);
@@ -3536,6 +3586,7 @@ class Diaspora
                }
 
                $body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
+               $body = Post\Media::addHTMLLinkToBody($item['uri-id'], $body);
 
                // The replied to autor mention is prepended for clarity if:
                // - Item replied isn't yours