]> git.mxchange.org Git - friendica.git/commitdiff
New field "quote-uri-id" for quoted posts
authorMichael <heluecht@pirati.ca>
Mon, 10 Oct 2022 22:39:30 +0000 (22:39 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 10 Oct 2022 22:39:30 +0000 (22:39 +0000)
database.sql
doc/database/db_post-content.md
src/Content/Text/BBCode.php
src/Model/Item.php
src/Protocol/ActivityPub/Transmitter.php
static/dbstructure.config.php
static/dbview.config.php

index 48de2fcaef848dce71d36db99948010eb6d9dc6c..119228656e509a95616bdc2b5f06e92c52a975f8 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2022.09-rc (Giant Rhubarb)
--- DB_UPDATE_VERSION 1484
+-- DB_UPDATE_VERSION 1485
 -- ------------------------------------------
 
 
@@ -1186,6 +1186,7 @@ CREATE TABLE IF NOT EXISTS `post-content` (
        `content-warning` varchar(255) NOT NULL DEFAULT '' COMMENT '',
        `body` mediumtext COMMENT 'item body content',
        `raw-body` mediumtext COMMENT 'Body without embedded media links',
+       `quote-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the quoted uri',
        `location` varchar(255) NOT NULL DEFAULT '' COMMENT 'text location where this item originated',
        `coord` varchar(255) NOT NULL DEFAULT '' COMMENT 'longitude/latitude pair representing location where this item originated',
        `language` text COMMENT 'Language information about this post',
@@ -1202,7 +1203,9 @@ CREATE TABLE IF NOT EXISTS `post-content` (
         INDEX `plink` (`plink`(191)),
         INDEX `resource-id` (`resource-id`),
         FULLTEXT INDEX `title-content-warning-body` (`title`,`content-warning`,`body`),
-       FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
+        INDEX `quote-uri-id` (`quote-uri-id`),
+       FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
+       FOREIGN KEY (`quote-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
 
 --
@@ -1807,6 +1810,8 @@ CREATE VIEW `post-user-view` AS SELECT
        `post-user`.`thr-parent-id` AS `thr-parent-id`,
        `conversation-item-uri`.`uri` AS `conversation`,
        `post-thread-user`.`conversation-id` AS `conversation-id`,
+       `quote-item-uri`.`uri` AS `quote-uri`,
+       `post-content`.`quote-uri-id` AS `quote-uri-id`,
        `item-uri`.`guid` AS `guid`,
        `post-user`.`wall` AS `wall`,
        `post-user`.`gravity` AS `gravity`,
@@ -1962,6 +1967,7 @@ CREATE VIEW `post-user-view` AS SELECT
                        LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
                        LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
                        LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
+                       LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
                        LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
                        LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-user`.`uri-id`
                        LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
@@ -1985,6 +1991,8 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `post-user`.`thr-parent-id` AS `thr-parent-id`,
        `conversation-item-uri`.`uri` AS `conversation`,
        `post-thread-user`.`conversation-id` AS `conversation-id`,
+       `quote-item-uri`.`uri` AS `quote-uri`,
+       `post-content`.`quote-uri-id` AS `quote-uri-id`,
        `item-uri`.`guid` AS `guid`,
        `post-thread-user`.`wall` AS `wall`,
        `post-user`.`gravity` AS `gravity`,
@@ -2138,6 +2146,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
                        LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
                        LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
                        LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
+                       LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
                        LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
                        LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread-user`.`uri-id`
                        LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
@@ -2157,6 +2166,8 @@ CREATE VIEW `post-view` AS SELECT
        `post`.`thr-parent-id` AS `thr-parent-id`,
        `conversation-item-uri`.`uri` AS `conversation`,
        `post-thread`.`conversation-id` AS `conversation-id`,
+       `quote-item-uri`.`uri` AS `quote-uri`,
+       `post-content`.`quote-uri-id` AS `quote-uri-id`,
        `item-uri`.`guid` AS `guid`,
        `post`.`gravity` AS `gravity`,
        `external-item-uri`.`uri` AS `extid`,
@@ -2279,6 +2290,7 @@ CREATE VIEW `post-view` AS SELECT
                        LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
                        LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
                        LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
+                       LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
                        LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post`.`uri-id`
                        LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
                        LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
@@ -2296,6 +2308,8 @@ CREATE VIEW `post-thread-view` AS SELECT
        `post`.`thr-parent-id` AS `thr-parent-id`,
        `conversation-item-uri`.`uri` AS `conversation`,
        `post-thread`.`conversation-id` AS `conversation-id`,
+       `quote-item-uri`.`uri` AS `quote-uri`,
+       `post-content`.`quote-uri-id` AS `quote-uri-id`,
        `item-uri`.`guid` AS `guid`,
        `post`.`gravity` AS `gravity`,
        `external-item-uri`.`uri` AS `extid`,
@@ -2418,6 +2432,7 @@ CREATE VIEW `post-thread-view` AS SELECT
                        LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
                        LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
                        LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
+                       LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
                        LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread`.`uri-id`
                        LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
                        LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`;
index 86714c5ec91d4d1dfbdbe6025ef8c4978ef1b122..27b372093a5480d5b7a0f2926a9f75f1eb7f90dd 100644 (file)
@@ -13,6 +13,7 @@ Fields
 | content-warning |                                                                                                                           | varchar(255)   | NO   |     |         |       |
 | body            | item body content                                                                                                         | mediumtext     | YES  |     | NULL    |       |
 | raw-body        | Body without embedded media links                                                                                         | mediumtext     | YES  |     | NULL    |       |
+| quote-uri-id    | Id of the item-uri table that contains the quoted uri                                                                     | int unsigned   | YES  |     | NULL    |       |
 | location        | text location where this item originated                                                                                  | varchar(255)   | NO   |     |         |       |
 | coord           | longitude/latitude pair representing location where this item originated                                                  | varchar(255)   | NO   |     |         |       |
 | language        | Language information about this post                                                                                      | text           | YES  |     | NULL    |       |
@@ -35,6 +36,7 @@ Indexes
 | plink                      | plink(191)                             |
 | resource-id                | resource-id                            |
 | title-content-warning-body | FULLTEXT, title, content-warning, body |
+| quote-uri-id               | quote-uri-id                           |
 
 Foreign Keys
 ------------
@@ -42,5 +44,6 @@ Foreign Keys
 | Field | Target Table | Target Field |
 |-------|--------------|--------------|
 | uri-id | [item-uri](help/database/db_item-uri) | id |
+| quote-uri-id | [item-uri](help/database/db_item-uri) | id |
 
 Return to [database documentation](help/database)
index 43d4127ea99c51bf136283b22657681dd08c3535..59b2e77a4a9e51c3e4a06c426c4f4091dc4e6e5c 100644 (file)
@@ -1069,6 +1069,22 @@ class BBCode
                return $attributes;
        }
 
+       /**
+        * Replace the share block with a link
+        *
+        * @param string $body
+        * @return string
+        */
+       public static function replaceSharedData(string $body): string
+       {
+               return BBCode::convertShare(
+                       $body,
+                       function (array $attributes) {
+                               return '♲ ' . $attributes['link'];
+                       }
+               );
+       }
+
        /**
         * This function converts a [share] block to text according to a provided callback function whose signature is:
         *
index 38191853551dc37203cfc8904a209369095042c7..797def3bd877e804abd3b777ce8f00e14cff6cfb 100644 (file)
@@ -93,7 +93,7 @@ class Item
                'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
                'wall', 'private', 'starred', 'origin', 'parent-origin', 'title', 'body', 'language',
                'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
-               'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'mention', 'global',
+               'quote-uri', 'quote-uri-id', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'mention', 'global',
                'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network', 'author-updated', 'author-gsid', 'author-addr', 'author-uri-id',
                'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network', 'owner-contact-type', 'owner-updated',
                'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type', 'causer-network',
@@ -115,7 +115,7 @@ class Item
                        'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
                        'author-id', 'author-link', 'author-name', 'author-avatar', 'owner-id', 'owner-link', 'contact-uid',
                        'signed_text', 'network', 'wall', 'contact-id', 'plink', 'origin',
-                       'thr-parent-id', 'parent-uri-id', 'postopts', 'pubmail',
+                       'thr-parent-id', 'parent-uri-id', 'quote-uri', 'quote-uri-id', 'postopts', 'pubmail',
                        'event-created', 'event-edited', 'event-start', 'event-finish',
                        'event-summary', 'event-desc', 'event-location', 'event-type',
                        'event-nofinish', 'event-ignore', 'event-id'];
@@ -123,7 +123,7 @@ class Item
        // All fields in the item table
        const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent',
                        'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'conversation', 'vid',
-                       'contact-id', 'wall', 'gravity', 'extid', 'psid',
+                       'quote-uri', 'quote-uri-id', 'contact-id', 'wall', 'gravity', 'extid', 'psid',
                        'created', 'edited', 'commented', 'received', 'changed', 'verb',
                        'postopts', 'plink', 'resource-id', 'event-id', 'inform',
                        'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type', 'post-reason',
@@ -1119,6 +1119,11 @@ class Item
                $item['raw-body'] = Post\Media::insertFromBody($item['uri-id'], $item['raw-body']);
                $item['raw-body'] = self::setHashtags($item['raw-body']);
 
+               if ($quote_id = self::getQuoteUriId($item['body'])) {
+                       $item['quote-uri-id'] = $quote_id;
+                       $item['raw-body'] = BBCode::replaceSharedData($item['raw-body']);
+               }
+
                if (!DBA::exists('contact', ['id' => $item['author-id'], 'network' => Protocol::DFRN])) {
                        Post\Media::insertFromRelevantUrl($item['uri-id'], $item['raw-body']);
                }
@@ -3629,4 +3634,19 @@ class Item
                Logger::debug('New shared data', ['uri-id' => $item['uri-id'], 'link' => $link, 'guid' => $item['guid']]);
                return $item['body'];
        }
+
+       /**
+        * Fetch the uri-id of a quote
+        *
+        * @param string $body
+        * @return integer
+        */
+       private static function getQuoteUriId(string $body): int
+       {
+               $shared = BBCode::fetchShareAttributes($body);
+               if (empty($shared['message_id'])) {
+                       return 0;
+               }
+               return ItemURI::getIdByURI($shared['message_id']);
+       }
 }
index 38482d3ec95f83dab1191745305e794b49b824dc..de9a3535f3060246c96c3145777b147502bf8690 100644 (file)
@@ -1662,10 +1662,9 @@ 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'])) {
+                               $body = BBCode::replaceSharedData($body);
+                               $data['quoteUrl'] = $item['quote-uri'];
                        }
 
                        $data['content'] = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
@@ -1680,7 +1679,7 @@ class Transmitter
 
                        $shared = BBCode::fetchShareAttributes($richbody);
                        if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
-                               $richbody = self::replaceSharedData($richbody);
+                               $richbody = BBCode::replaceSharedData($richbody);
                        }
 
                        $richbody = BBCode::removeAttachment($richbody);
@@ -1710,22 +1709,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.
         *
index 90fea5bcfcb07f09a55e5b9536939511eafe57bc..5da1c17715b214d2525cdeafe8f661e8b9b3f6d9 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1484);
+       define('DB_UPDATE_VERSION', 1485);
 }
 
 return [
@@ -1218,6 +1218,7 @@ return [
                        "content-warning" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
                        "body" => ["type" => "mediumtext", "comment" => "item body content"],
                        "raw-body" => ["type" => "mediumtext", "comment" => "Body without embedded media links"],
+                       "quote-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the quoted uri"],
                        "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "text location where this item originated"],
                        "coord" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "longitude/latitude pair representing location where this item originated"],
                        "language" => ["type" => "text", "comment" => "Language information about this post"],
@@ -1236,6 +1237,7 @@ return [
                        "plink" => ["plink(191)"],
                        "resource-id" => ["resource-id"],
                        "title-content-warning-body" => ["FULLTEXT", "title", "content-warning", "body"],
+                       "quote-uri-id" => ["quote-uri-id"],
                ]
        ],
        "post-delivery" => [
index 2a7cb54feb67de92ef8985fb977e11fe1f6507ee..c12cccb4cc22e591ed2b63a941049bd0f54518d2 100644 (file)
@@ -72,6 +72,8 @@
                        "thr-parent-id" => ["post-user", "thr-parent-id"],
                        "conversation" => ["conversation-item-uri", "uri"],
                        "conversation-id" => ["post-thread-user", "conversation-id"],
+                       "quote-uri" => ["quote-item-uri", "uri"],
+                       "quote-uri-id" => ["post-content", "quote-uri-id"],
                        "guid" => ["item-uri", "guid"],
                        "wall" => ["post-user", "wall"],
                        "gravity" => ["post-user", "gravity"],
                        LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
                        LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
                        LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
+                       LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
                        LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id` AND `post-user`.`origin`
                        LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-user`.`uri-id`
                        LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
                        "thr-parent-id" => ["post-user", "thr-parent-id"],
                        "conversation" => ["conversation-item-uri", "uri"],
                        "conversation-id" => ["post-thread-user", "conversation-id"],
+                       "quote-uri" => ["quote-item-uri", "uri"],
+                       "quote-uri-id" => ["post-content", "quote-uri-id"],
                        "guid" => ["item-uri", "guid"],
                        "wall" => ["post-thread-user", "wall"],
                        "gravity" => ["post-user", "gravity"],
                        LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
                        LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
                        LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
+                       LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
                        LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
                        LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread-user`.`uri-id`
                        LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
                        "thr-parent-id" => ["post", "thr-parent-id"],
                        "conversation" => ["conversation-item-uri", "uri"],
                        "conversation-id" => ["post-thread", "conversation-id"],
+                       "quote-uri" => ["quote-item-uri", "uri"],
+                       "quote-uri-id" => ["post-content", "quote-uri-id"],
                        "guid" => ["item-uri", "guid"],
                        "gravity" => ["post", "gravity"],
                        "extid" => ["external-item-uri", "uri"],
                        LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
                        LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
                        LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
+                       LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
                        LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post`.`uri-id`
                        LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
                        LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`"
                        "thr-parent-id" => ["post", "thr-parent-id"],
                        "conversation" => ["conversation-item-uri", "uri"],
                        "conversation-id" => ["post-thread", "conversation-id"],
+                       "quote-uri" => ["quote-item-uri", "uri"],
+                       "quote-uri-id" => ["post-content", "quote-uri-id"],
                        "guid" => ["item-uri", "guid"],
                        "gravity" => ["post", "gravity"],
                        "extid" => ["external-item-uri", "uri"],
                        LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
                        LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
                        LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
+                       LEFT JOIN `item-uri` AS `quote-item-uri` ON `quote-item-uri`.`id` = `post-content`.`quote-uri-id`
                        LEFT JOIN `post-question` ON `post-question`.`uri-id` = `post-thread`.`uri-id`
                        LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
                        LEFT JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`"