X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FDiaspora.php;h=271b71b893e1b20120a93a5bcf2da293d0a14443;hb=cef063e4fd07e673138186c1726887c3c18806ef;hp=fe5b27d334f313d0b1817ac1bafb46e09b925113;hpb=27c738f90f5961ffcdc438810a93407e4544eead;p=friendica.git diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index fe5b27d334..271b71b893 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1,6 +1,6 @@ $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 { @@ -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) { @@ -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); } @@ -2285,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 * @@ -2436,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) { @@ -2918,7 +2855,7 @@ class Diaspora $namespaces = ['me' => ActivityNamespace::SALMON_ME]; - return XML::fromArray($xmldata, $xml, false, $namespaces); + return XML::fromArray($xmldata, $dummy, false, $namespaces); } /** @@ -3018,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; @@ -3031,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]); } /** @@ -3374,8 +3316,16 @@ 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); // Fetch the title from an attached link - if there is one if (empty($item['title']) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) { @@ -3423,6 +3373,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']); @@ -3457,6 +3411,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']);