]> git.mxchange.org Git - friendica.git/commitdiff
Set the quote-uri-id when a post is linked
authorMichael <heluecht@pirati.ca>
Thu, 2 Jan 2025 16:57:30 +0000 (16:57 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 2 Jan 2025 16:57:30 +0000 (16:57 +0000)
src/Model/Item.php
src/Model/Post/Media.php

index c9024c9cc6aa7081958a92a37bbe0d347713cfc9..594185c451ed7447e9b2a0981805e0ee2cd6f3fb 100644 (file)
@@ -233,6 +233,14 @@ class Item
 
                                $content_fields = ['raw-body' => trim($fields['raw-body'] ?? $fields['body'])];
 
+                               if ($item['origin'] && empty($item['quote-uri-id'])) {
+                                       $quote_id = Post\Media::getActivityUriId($item['uri-id']);
+                                       if (!empty($quote_id)) {
+                                               Logger::notice('Found attached post', ['id' => $quote_id, 'guid' => $item['guid'], 'uri-id' => $item['uri-id']]);
+                                               $content_fields['quote-uri-id'] = $quote_id;
+                                       }
+                               }
+
                                // Remove all media attachments from the body and store them in the post-media table
                                // @todo On shared postings (Diaspora style and commented reshare) don't fetch content from the shared part
                                $content_fields['raw-body'] = Post\Media::insertFromBody($item['uri-id'], $content_fields['raw-body']);
@@ -1221,6 +1229,14 @@ class Item
                        Post\Media::insertFromAttachment($item['uri-id'], $item['attach']);
                }
 
+               if ($item['origin'] && empty($item['quote-uri-id'])) {
+                       $quote_id = Post\Media::getActivityUriId($item['uri-id']);
+                       if (!empty($quote_id)) {
+                               Logger::notice('Found attached post', ['id' => $quote_id, 'guid' => $item['guid'], 'uri-id' => $item['uri-id']]);
+                               $item['quote-uri-id'] = $quote_id;
+                       }
+               }
+
                if (empty($item['event-id'])) {
                        unset($item['event-id']);
 
@@ -4247,9 +4263,10 @@ class Item
        }
 
        /**
-        * Fetch the uri-id of a quote
+        * Fetch the uri-id of a quoted post by searching for data in the body or attached media
         *
-        * @param string $body
+        * @param string $body   The body of the 
+        * @param int    $uid    The id of the user
         * @return integer
         */
        public static function getQuoteUriId(string $body, int $uid = 0): int
index 7e4c950d3a9872a7acf0c7f8d8b162101dba7c7a..6e258bc17492268618e12e06f6d890bb8ac9e763 100644 (file)
@@ -1130,4 +1130,19 @@ class Media
                        (Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') .
                        $id;
        }
+
+       /**
+        * Fetch the uri-id of an attached uri-post for a given uri-id
+        *
+        * @param integer $uri_id Uri-Id of the post
+        * @return integer uri-id of the first attached post
+        */
+       public static function getActivityUriId(int $uri_id): int
+       {
+               $posts = self::getByURIId($uri_id, [self::ACTIVITY]);
+               if (!$posts) {
+                       return 0;
+               }
+               return reset($posts)['media-uri-id'];
+       }
 }