]> git.mxchange.org Git - friendica.git/commitdiff
Improve quote share ("message_id" added)
authorMichael <heluecht@pirati.ca>
Thu, 6 Oct 2022 21:50:20 +0000 (21:50 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 6 Oct 2022 21:50:20 +0000 (21:50 +0000)
mod/item.php
mod/share.php
src/App/Router.php
src/Content/Text/BBCode.php
src/Model/Item.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/Diaspora.php
src/Protocol/Email.php

index 6793d44342dea2ccca82988fc3d2e2ab248a94c3..4dc1d77ce31708fc7541b7f7d585d9987a9dfec3 100644 (file)
@@ -621,6 +621,7 @@ function item_post(App $a) {
                $datarray["author-uri-id"] = ItemURI::getIdByURI($datarray["author-link"]);
                $datarray["owner-updated"] = '';
                $datarray["has-media"] = false;
+               $datarray['body'] = Item::improveSharedDataInBody($datarray);
 
                $o = DI::conversation()->create([array_merge($contact_record, $datarray)], 'search', false, true);
 
@@ -661,6 +662,7 @@ function item_post(App $a) {
        }
 
        $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
+       $datarray['body']   = Item::improveSharedDataInBody($datarray);
 
        if ($orig_post) {
                $fields = [
index 2f836c5aa06cc64aed2e9e2eedce9c88c59ecca9..09097f070f3c6738200ebee43d6043d441a58f0d 100644 (file)
@@ -20,7 +20,6 @@
  */
 
 use Friendica\App;
-use Friendica\Content\Text\BBCode;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
@@ -34,8 +33,7 @@ function share_init(App $a) {
                System::exit();
        }
 
-       $fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar',
-               'guid', 'created', 'plink', 'title'];
+       $fields = ['private', 'body', 'uri'];
        $item = Post::selectFirst($fields, ['id' => $post_id]);
 
        if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) {
@@ -46,14 +44,7 @@ function share_init(App $a) {
                $pos = strpos($item['body'], "[share");
                $o = substr($item['body'], $pos);
        } else {
-               $o = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']);
-
-               if ($item['title']) {
-                       $o .= '[h3]'.$item['title'].'[/h3]'."\n";
-               }
-
-               $o .= $item['body'];
-               $o .= "[/share]";
+               $o = "[share message_id='" . $item['uri'] . "'][/share]";
        }
 
        echo $o;
index 9906568925b4aa9e5f23b7df4cdf7ddc11f5078e..a4fe4f94117ab1f098f82a75cab32d7c84c26b1c 100644 (file)
@@ -339,7 +339,7 @@ class Router
                        if ($this->dice_profiler_threshold > 0) {
                                $dur = floatval(microtime(true) - $stamp);
                                if ($dur >= $this->dice_profiler_threshold) {
-                                       $this->logger->warning('Dice module creation lasts too long.', ['duration' => round($dur, 3), 'module' => $module_class, 'parameters' => $module_parameters]);
+                                       $this->logger->notice('Dice module creation lasts too long.', ['duration' => round($dur, 3), 'module' => $module_class, 'parameters' => $module_parameters]);
                                }
                        }
                }
index 0a07e18f40716b6f53acc86f8bf5adf3f6ac002d..f7358330365f73c7b6bcf2d38ffa84864d8612a9 100644 (file)
@@ -1047,7 +1047,7 @@ class BBCode
        private static function extractShareAttributes(string $shareString): array
        {
                $attributes = [];
-               foreach (['author', 'profile', 'avatar', 'link', 'posted', 'guid'] as $field) {
+               foreach (['author', 'profile', 'avatar', 'link', 'posted', 'guid', 'message_id'] as $field) {
                        preg_match("/$field=(['\"])(.+?)\\1/ism", $shareString, $matches);
                        $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8');
                }
@@ -2458,10 +2458,11 @@ class BBCode
         * @param string      $link    Post source URL
         * @param string      $posted  Post created date
         * @param string|null $guid    Post guid (if any)
+        * @param string|null $uri     Post uri (if any)
         * @return string
         * @TODO Rewrite to handle over whole record array
         */
-       public static function getShareOpeningTag(string $author, string $profile, string $avatar, string $link, string $posted, string $guid = null): string
+       public static function getShareOpeningTag(string $author, string $profile, string $avatar, string $link, string $posted, string $guid = null, string $uri = null): string
        {
                DI::profiler()->startRecording('rendering');
                $header = "[share author='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $author) .
@@ -2474,6 +2475,10 @@ class BBCode
                        $header .= "' guid='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $guid);
                }
 
+               if ($uri) {
+                       $header .= "' message_id='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $uri);
+               }
+
                $header  .= "']";
 
                DI::profiler()->stopRecording();
index acd2360ef8550efbad433370b0d8e5b6c1901982..6cce806bed9434288af740e76b274a7b0c3b850f 100644 (file)
@@ -3667,22 +3667,22 @@ class Item
        public static function improveSharedDataInBody(array $item): string
        {
                $shared = BBCode::fetchShareAttributes($item['body']);
-               if (empty($shared['link'])) {
+               if (empty($shared['link']) && empty($shared['message_id'])) {
                        return $item['body'];
                }
 
-               $id = self::fetchByLink($shared['link']);
-               Logger::info('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'callstack' => System::callstack()]);
+               $id = self::fetchByLink($shared['link'] ?: $shared['message_id']);
+               Logger::debug('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'uri' => $shared['message_id'], 'callstack' => System::callstack()]);
                if (!$id) {
                        return $item['body'];
                }
 
-               $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'title', 'body'], ['id' => $id]);
+               $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'uri', 'title', 'body'], ['id' => $id]);
                if (!DBA::isResult($shared_item)) {
                        return $item['body'];
                }
 
-               $shared_content = BBCode::getShareOpeningTag($shared_item['author-name'], $shared_item['author-link'], $shared_item['author-avatar'], $shared_item['plink'], $shared_item['created'], $shared_item['guid']);
+               $shared_content = BBCode::getShareOpeningTag($shared_item['author-name'], $shared_item['author-link'], $shared_item['author-avatar'], $shared_item['plink'], $shared_item['created'], $shared_item['guid'], $shared_item['uri']);
 
                if (!empty($shared_item['title'])) {
                        $shared_content .= '[h3]'.$shared_item['title'].'[/h3]'."\n";
@@ -3691,7 +3691,7 @@ class Item
                $shared_content .= $shared_item['body'];
 
                $item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $shared_content . '[/share]', $item['body']);
-               Logger::info('New shared data', ['uri-id' => $item['uri-id'], 'id' => $id, 'shared_item' => $shared_item]);
+               Logger::debug('New shared data', ['uri-id' => $item['uri-id'], 'id' => $id, 'shared_item' => $shared_item]);
                return $item['body'];
        }
 }
index f75e6189b88a08187bdb038ee50b1ffae1c9129f..bfd70f2babc71f61993529c079f52a3fa9af7353 100644 (file)
@@ -883,7 +883,7 @@ class Processor
                        return '';
                }
 
-               $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'title', 'body'], ['id' => $id]);
+               $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'uri', 'title', 'body'], ['id' => $id]);
                if (!DBA::isResult($shared_item)) {
                        return '';
                }
@@ -894,7 +894,8 @@ class Processor
                        $shared_item['author-avatar'],
                        $shared_item['plink'],
                        $shared_item['created'],
-                       $shared_item['guid']
+                       $shared_item['guid'],
+                       $shared_item['uri'],
                );
 
                if (!empty($shared_item['title'])) {
index 781ae57a36796493c9d739201c543211b79e938a..bcf049945ff544ce6c3530e82d1121bf1636b402 100644 (file)
@@ -2483,7 +2483,8 @@ class Diaspora
                        $original_item['author-avatar'],
                        $original_item['plink'],
                        $original_item['created'],
-                       $original_item['guid']
+                       $original_item['guid'],
+                       $original_item['uri'],
                );
 
                if (!empty($original_item['title'])) {
@@ -4181,7 +4182,7 @@ class Diaspora
 
        public static function performReshare(int $UriId, int $uid): int
        {
-               $fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
+               $fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'uri'];
                $item = Post::selectFirst($fields, ['uri-id' => $UriId, 'uid' => [$uid, 0], 'private' => [Item::PUBLIC, Item::UNLISTED]]);
                if (!DBA::isResult($item)) {
                        return 0;
@@ -4191,7 +4192,7 @@ class Diaspora
                        $pos = strpos($item['body'], '[share');
                        $post = substr($item['body'], $pos);
                } else {
-                       $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']);
+                       $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid'], $item['uri']);
 
                        if (!empty($item['title'])) {
                                $post .= '[h3]' . $item['title'] . "[/h3]\n";
index bcde2b4e294e016fff813b5fa78f0644661ef072..be10ca0815e34bd490706f5b13e48bb3f0e8e8e5 100644 (file)
@@ -51,12 +51,12 @@ class Email
 
                $errors = imap_errors();
                if (!empty($errors)) {
-                       Logger::warning('IMAP Errors occured', ['errors' => $errors]);
+                       Logger::notice('IMAP Errors occured', ['errors' => $errors]);
                }
 
                $alerts = imap_alerts();
                if (!empty($alerts)) {
-                       Logger::warning('IMAP Alerts occured: ', ['alerts' => $alerts]);
+                       Logger::notice('IMAP Alerts occured: ', ['alerts' => $alerts]);
                }
 
                return $mbox;