]> 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 11a64504b9d261a0657fd608a07dba77948d780e..6a601b6f98636e2791dfbb67414f2ffb3977a20b 100644 (file)
@@ -268,7 +268,7 @@ class Transmitter
                $condition = array_merge($condition, [
                        'uid'           => $owner['uid'],
                        'author-id'      => Contact::getIdForURL($owner['url'], 0, false),
-                       'gravity'        => [GRAVITY_PARENT, GRAVITY_COMMENT],
+                       'gravity'        => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
                        'network'        => Protocol::FEDERATED,
                        'parent-network' => Protocol::FEDERATED,
                        'origin'         => true,
@@ -353,7 +353,7 @@ class Transmitter
                        'uid'           => $owner['uid'],
                        'author-id'      => $owner_cid,
                        'private'        => [Item::PUBLIC, Item::UNLISTED],
-                       'gravity'        => [GRAVITY_PARENT, GRAVITY_COMMENT],
+                       'gravity'        => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
                        'network'        => Protocol::FEDERATED,
                        'parent-network' => Protocol::FEDERATED,
                        'origin'         => true,
@@ -579,7 +579,7 @@ class Transmitter
                $item_profile = APContact::getByURL($item['author-link']);
                $exclude[] = $item['author-link'];
 
-               if ($item['gravity'] == GRAVITY_PARENT) {
+               if ($item['gravity'] == Item::GRAVITY_PARENT) {
                        $exclude[] = $item['owner-link'];
                }
 
@@ -667,7 +667,7 @@ class Transmitter
 
                $data = ['to' => [], 'cc' => [], 'bcc' => []];
 
-               if ($item['gravity'] == GRAVITY_PARENT) {
+               if ($item['gravity'] == Item::GRAVITY_PARENT) {
                        $actor_profile = APContact::getByURL($item['owner-link']);
                } else {
                        $actor_profile = APContact::getByURL($item['author-link']);
@@ -755,10 +755,10 @@ class Transmitter
                if (!empty($item['parent'])) {
                        $parents = Post::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']], ['order' => ['id']]);
                        while ($parent = Post::fetch($parents)) {
-                               if ($parent['gravity'] == GRAVITY_PARENT) {
+                               if ($parent['gravity'] == Item::GRAVITY_PARENT) {
                                        $profile = APContact::getByURL($parent['owner-link'], false);
                                        if (!empty($profile)) {
-                                               if ($item['gravity'] != GRAVITY_PARENT) {
+                                               if ($item['gravity'] != Item::GRAVITY_PARENT) {
                                                        // Comments to forums are directed to the forum
                                                        // But comments to forums aren't directed to the followers collection
                                                        // This rule is only valid when the actor isn't the forum.
@@ -973,7 +973,7 @@ class Transmitter
 
                $inboxes = [];
 
-               if ($item['gravity'] == GRAVITY_ACTIVITY) {
+               if ($item['gravity'] == Item::GRAVITY_ACTIVITY) {
                        $item_profile = APContact::getByURL($item['author-link'], false);
                } else {
                        $item_profile = APContact::getByURL($item['owner-link'], false);
@@ -1062,7 +1062,7 @@ class Transmitter
                $mail['parent-uri']       = $reply['uri'];
                $mail['parent-uri-id']    = $reply['uri-id'];
                $mail['parent-author-id'] = Contact::getIdForURL($reply['from-url'], 0, false);
-               $mail['gravity']          = ($mail['reply'] ? GRAVITY_COMMENT: GRAVITY_PARENT);
+               $mail['gravity']          = ($mail['reply'] ? Item::GRAVITY_COMMENT: Item::GRAVITY_PARENT);
                $mail['event-type']       = '';
                $mail['language']         = '';
                $mail['parent']           = 0;
@@ -1247,7 +1247,7 @@ class Transmitter
                if (!$object_mode) {
                        $data = ['@context' => $context ?? ActivityPub::CONTEXT];
 
-                       if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) {
+                       if ($item['deleted'] && ($item['gravity'] == Item::GRAVITY_ACTIVITY)) {
                                $type = 'Undo';
                        } elseif ($item['deleted']) {
                                $type = 'Delete';
@@ -1258,7 +1258,7 @@ class Transmitter
 
                if ($type == 'Delete') {
                        $data['id'] = Item::newURI($item['guid']) . '/' . $type;;
-               } elseif (($item['gravity'] == GRAVITY_ACTIVITY) && ($type != 'Undo')) {
+               } elseif (($item['gravity'] == Item::GRAVITY_ACTIVITY) && ($type != 'Undo')) {
                        $data['id'] = $item['uri'];
                } else {
                        $data['id'] = $item['uri'] . '/' . $type;
@@ -1266,7 +1266,7 @@ class Transmitter
 
                $data['type'] = $type;
 
-               if (($type != 'Announce') || ($item['gravity'] != GRAVITY_PARENT)) {
+               if (($type != 'Announce') || ($item['gravity'] != Item::GRAVITY_PARENT)) {
                        $data['actor'] = $item['author-link'];
                } else {
                        $data['actor'] = $item['owner-link'];
@@ -1559,7 +1559,7 @@ class Transmitter
                // We are treating posts differently when they are directed to a community.
                // This is done to better support Lemmy. Most of the changes should work with other systems as well.
                // But to not risk compatibility issues we currently perform the changes only for communities.
-               if ($item['gravity'] == GRAVITY_PARENT) {
+               if ($item['gravity'] == Item::GRAVITY_PARENT) {
                        $isCommunityPost = !empty(Tag::getByURIId($item['uri-id'], [Tag::EXCLUSIVE_MENTION]));
                        $links = Post\Media::getByURIId($item['uri-id'], [Post\Media::HTML]);
                        if ($isCommunityPost && (count($links) == 1)) {
@@ -1666,17 +1666,15 @@ class Transmitter
 
                        $body = BBCode::setMentionsToNicknames($body);
 
-                       if (!empty($item['quote-uri']) && Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
-                               $real_quote = true;
-                               if (Diaspora::isReshare($body, false)) {
-                                       $body = BBCode::replaceSharedData($body);
-                               } elseif (strpos($body, $item['quote-uri']) === false) {
-                                       $body .= "\n♲ " . $item['quote-uri'];
+                       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['quoteUrl'] = $item['quote-uri'];
-                       } elseif (!empty($item['quote-uri']) && !Diaspora::isReshare($body, false)) {
-                               $body .= "\n" . DI::contentItem()->createSharedPostByUriId($item['quote-uri-id'], $item['uid'], true);
-                               $item['body'] = Item::improveSharedDataInBody($item, true);
                        }
 
                        $data['content'] = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
@@ -1688,14 +1686,14 @@ class Transmitter
                $language = self::getLanguage($item);
                if (!empty($language)) {
                        $richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
-
-                       if ($real_quote) {
-                               $shared = BBCode::fetchShareAttributes($richbody);
-                               if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
-                                       $richbody = BBCode::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);
@@ -1818,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']];
        }
 
        /**