]> git.mxchange.org Git - friendica.git/commitdiff
Avoid quoting the own post
authorMichael <heluecht@pirati.ca>
Sun, 24 Sep 2023 10:18:50 +0000 (10:18 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 24 Sep 2023 10:18:50 +0000 (10:18 +0000)
src/Content/Item.php
src/Content/Text/Plaintext.php
src/Model/Item.php
src/Model/Post/Media.php
src/Model/Post/UserNotification.php
src/Protocol/ActivityPub/Transmitter.php

index 163db89aa472c6b698cffb5ca92d244d9d7b4b4f..c94ec1299b3f5bc0bb9482cc1e8844cc2b91e705 100644 (file)
@@ -638,7 +638,7 @@ class Item
                        $body = $item['body'];
                }
 
-               if (empty($item['quote-uri-id'])) {
+               if (empty($item['quote-uri-id']) || ($item['quote-uri-id'] == $item['uri-id'])) {
                        return $body;
                }
 
@@ -729,7 +729,7 @@ class Item
         */
        public function getSharedPost(array $item, array $fields = []): array
        {
-               if (!empty($item['quote-uri-id'])) {
+               if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
                        $shared = Post::selectFirst($fields, ['uri-id' => $item['quote-uri-id'], 'uid' => [0, $item['uid'] ?? 0]]);
                        if (is_array($shared)) {
                                return [
@@ -770,7 +770,7 @@ class Item
                        return $attributes;
                }
 
-               if (!empty($item['quote-uri-id'])) {
+               if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
                        $shared = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'uri', 'body'], ['uri-id' => $item['quote-uri-id']]);
                        if (!empty($shared)) {
                                return [
index 86d720a02a4e33f85a4c3616ec053924d5ec45d6..3b531f01bc20bafda6432de86cbe3e0f8b28d5e7 100644 (file)
@@ -324,7 +324,7 @@ class Plaintext
                $post['text'] = Post\Media::removeFromBody($post['text']);
 
                $images = Post\Media::getByURIId($item['uri-id'], [Post\Media::IMAGE]);
-               if (!empty($item['quote-uri-id'])) {
+               if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
                        $images = array_merge($images, Post\Media::getByURIId($item['quote-uri-id'], [Post\Media::IMAGE]));
                }
                foreach ($images as $image) {
@@ -355,7 +355,7 @@ class Plaintext
 
                // Look for audio or video links
                $media = Post\Media::getByURIId($item['uri-id'], [Post\Media::AUDIO, Post\Media::VIDEO]);
-               if (!empty($item['quote-uri-id'])) {
+               if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
                        $media = array_merge($media, Post\Media::getByURIId($item['quote-uri-id'], [Post\Media::AUDIO, Post\Media::VIDEO]));
                }
 
index de8c2e6da62900171113983fb68c48f1dd7ace8a..41aae04134374ef0a0a7b504d5f991556f0e1518 100644 (file)
@@ -1184,6 +1184,11 @@ class Item
                        }
                }
 
+               if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] == $item['uri-id'])) {
+                       Logger::info('Quote-Uri-Id is identical to Uri-Id', ['uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
+                       unset($item['quote-uri-id']);
+               }
+
                if (!empty($item['quote-uri-id'])) {
                        $item['raw-body'] = BBCode::removeSharedData($item['raw-body']);
                        $item['body']     = BBCode::removeSharedData($item['body']);
@@ -3125,7 +3130,7 @@ class Item
                        $item['body'] = BBCode::removeSharedData($item['body']);
                } elseif (empty($shared_item['uri-id']) && empty($item['quote-uri-id']) && ($item['network'] != Protocol::DIASPORA)) {
                        $media = Post\Media::getByURIId($item['uri-id'], [Post\Media::ACTIVITY]);
-                       if (!empty($media)) {
+                       if (!empty($media) && ($media[0]['media-uri-id'] != $item['uri-id'])) {
                                $shared_item = Post::selectFirst($fields, ['uri-id' => $media[0]['media-uri-id'], 'uid' => [$item['uid'], 0]]);
                                if (empty($shared_item['uri-id'])) {
                                        $shared_item = Post::selectFirst($fields, ['plink' => $media[0]['url'], 'uid' => [$item['uid'], 0]]);
index a0d55b6e0036990c82fcac9f6db72eb303447019..e0c8d3561fdae90f8fc8a805bca7577752c62405 100644 (file)
@@ -265,6 +265,11 @@ class Media
                        return $media;
                }
 
+               if ($item['uri-id'] == $media['uri-id']) {
+                       Logger::info('Media-Uri-Id is identical to Uri-Id', ['uri-id' => $media['uri-id']]);
+                       return $media;
+               }
+
                if (
                        !empty($item['plink']) && Strings::compareLink($item['plink'], $media['url']) &&
                        parse_url($item['plink'], PHP_URL_HOST) != parse_url($item['uri'], PHP_URL_HOST)
index 726e82d7e0ac46f396ec52e9d4e930c0f99487ce..41c8b503122c172fc05577bcd8326f63efbf458f 100644 (file)
@@ -602,7 +602,7 @@ class UserNotification
         */
        private static function checkQuoted(array $item, array $contacts): bool
        {
-               if (empty($item['quote-uri-id'])) {
+               if (empty($item['quote-uri-id']) || ($item['quote-uri-id'] == $item['uri-id'])) {
                        return false;
                }
                $condition = ['uri-id' => $item['quote-uri-id'], 'uid' => $item['uid'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => [item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]];
index 4b0450a0cd89d711596c66fc92bf5bb4a4dfd783..72a9c929fab53493d1e91adf97703ca3ea099e12 100644 (file)
@@ -1752,7 +1752,7 @@ class Transmitter
 
                        $body = BBCode::setMentionsToNicknames($body);
 
-                       if (!empty($item['quote-uri-id'])) {
+                       if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
                                if (Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
                                        $real_quote = true;
                                        $data['quoteUrl'] = $item['quote-uri'];
@@ -1772,7 +1772,7 @@ class Transmitter
                if (!empty($language)) {
                        $richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
                        $richbody = Post\Media::removeFromEndOfBody($richbody);
-                       if (!empty($item['quote-uri-id'])) {
+                       if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
                                if ($real_quote) {
                                        $richbody = DI::contentItem()->addShareLink($richbody, $item['quote-uri-id']);
                                } else {
@@ -1784,7 +1784,7 @@ class Transmitter
                        $data['contentMap'][$language] = BBCode::convertForUriId($item['uri-id'], $richbody, BBCode::EXTERNAL);
                }
 
-               if (!empty($item['quote-uri-id'])) {
+               if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
                        $source = DI::contentItem()->addSharedPost($item, $item['body']);
                } else {
                        $source = $item['body'];