]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Merge remote-tracking branch 'upstream/develop' into quote
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index baa5c1350b91170498b53dfc86c2fd711d7aeb14..6a601b6f98636e2791dfbb67414f2ffb3977a20b 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace Friendica\Protocol\ActivityPub;
 
+use Friendica\App;
 use Friendica\Content\Feature;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Cache\Enum\Duration;
@@ -40,6 +41,7 @@ use Friendica\Model\User;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Relay;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\HTTPSignature;
@@ -415,7 +417,7 @@ class Transmitter
        {
                return [
                        'type' => 'Service',
-                       'name' =>  FRIENDICA_PLATFORM . " '" . FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
+                       'name' =>  App::PLATFORM . " '" . App::CODENAME . "' " . App::VERSION . '-' . DB_UPDATE_VERSION,
                        'url' => DI::baseUrl()->get()
                ];
        }
@@ -1621,6 +1623,8 @@ class Transmitter
 
                $permission_block = self::createPermissionBlockForItem($item, false);
 
+               $real_quote = false;
+
                $body = $item['body'];
 
                if ($type == 'Note') {
@@ -1662,10 +1666,15 @@ class Transmitter
 
                        $body = BBCode::setMentionsToNicknames($body);
 
-                       $shared = BBCode::fetchShareAttributes($body);
-                       if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
-                               $body = self::replaceSharedData($body);
-                               $data['quoteUrl'] = $shared['link'];
+                       if (!empty($item['quote-uri-id'])) {
+                               $body = BBCode::removeSharedData($body);
+                               if (Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
+                                       $real_quote = true;
+                                       $data['quoteUrl'] = $item['quote-uri'];
+                                       $body = DI::contentItem()->addShareLink($body, $item['quote-uri-id']);
+                               } else {
+                                       $body = DI::contentItem()->addSharedPost($item, $body);
+                               }
                        }
 
                        $data['content'] = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
@@ -1677,12 +1686,14 @@ class Transmitter
                $language = self::getLanguage($item);
                if (!empty($language)) {
                        $richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
-
-                       $shared = BBCode::fetchShareAttributes($richbody);
-                       if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
-                               $richbody = self::replaceSharedData($richbody);
+                       if (!empty($item['quote-uri-id'])) {
+                               $richbody = BBCode::removeSharedData($richbody);
+                               if ($real_quote) {
+                                       $richbody = DI::contentItem()->addShareLink($richbody, $item['quote-uri-id']);
+                               } else {
+                                       $richbody = DI::contentItem()->addSharedPost($item, $richbody);
+                               }
                        }
-
                        $richbody = BBCode::removeAttachment($richbody);
 
                        $data['contentMap'][$language] = BBCode::convertForUriId($item['uri-id'], $richbody, BBCode::EXTERNAL);
@@ -1710,22 +1721,6 @@ class Transmitter
                return $data;
        }
 
-       /**
-        * Replace the share block with a link
-        *
-        * @param string $body
-        * @return string
-        */
-       private static function replaceSharedData(string $body): string
-       {
-               return BBCode::convertShare(
-                       $body,
-                       function (array $attributes) {
-                               return '♲ ' . $attributes['link'];
-                       }
-               );
-       }
-
        /**
         * Fetches the language from the post, the user or the system.
         *
@@ -1821,28 +1816,23 @@ class Transmitter
         * @param array $item
         * @return array Announcement array
         */
-       public static function getAnnounceArray(array $item): array
+       private static function getAnnounceArray(array $item): array
        {
-               $reshared = Item::getShareArray($item);
-               if (empty($reshared['guid'])) {
-                       return [];
-               }
-
-               $reshared_item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['guid' => $reshared['guid']]);
-               if (!DBA::isResult($reshared_item)) {
+               $reshared = DI::contentItem()->getSharedPost($item, Item::DELIVER_FIELDLIST);
+               if (empty($reshared)) {
                        return [];
                }
 
-               if (!in_array($reshared_item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
+               if (!in_array($reshared['post']['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
                        return [];
                }
 
-               $profile = APContact::getByURL($reshared_item['author-link'], false);
+               $profile = APContact::getByURL($reshared['post']['author-link'], false);
                if (empty($profile)) {
                        return [];
                }
 
-               return ['object' => $reshared_item, 'actor' => $profile, 'comment' => $reshared['comment']];
+               return ['object' => $reshared['post'], 'actor' => $profile, 'comment' => $reshared['comment']];
        }
 
        /**