]> git.mxchange.org Git - friendica.git/commitdiff
Store mentioned contacts in another way
authorMichael <heluecht@pirati.ca>
Sat, 18 Apr 2020 14:41:26 +0000 (14:41 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 18 Apr 2020 14:41:26 +0000 (14:41 +0000)
src/Model/Tag.php
static/dbstructure.config.php

index f0bddb25c0d7e7edf9ea1b9285aa60668b9938ea..7627872590ed08b52cc7181a15d67b15d21455c6 100644 (file)
@@ -23,7 +23,7 @@ namespace Friendica\Model;
 
 use Friendica\Core\Logger;
 use Friendica\Database\DBA;
-use Friendica\Content\Text\BBCode;
+use Friendica\Model\Contact;
 
 /**
  * Class Tag
@@ -69,28 +69,45 @@ class Tag
                        return;
                }
 
-               $fields = ['name' => substr($name, 0, 96), 'type' => $type];
+               if (in_array($type, [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION])) {
+                       if (empty($url)) {
+                               // No mention without a contact url
+                               return;
+                       }
 
-               if (!empty($url) && ($url != $name)) {
-                       $fields['url'] = strtolower($url);
-               }
+                       Logger::info('Get ID for contact', ['url' => $url]);
 
-               $tag = DBA::selectFirst('tag', ['id'], $fields);
-               if (!DBA::isResult($tag)) {
-                       DBA::insert('tag', $fields, true);
-                       $tagid = DBA::lastInsertId();
+                       $cid = Contact::getIdForURL($url, 0, true);
+                       if (empty($cid)) {
+                               Logger::error('No contact found', ['url' => $url]);
+                               return;
+                       }
+                       $tagid = 0;
                } else {
-                       $tagid = $tag['id'];
-               }
+                       $fields = ['name' => substr($name, 0, 96)];
 
-               if (empty($tagid)) {
-                       Logger::error('No tag id created', $fields);
-                       return;
+                       if (!empty($url) && ($url != $name)) {
+                               $fields['url'] = strtolower($url);
+                       }
+       
+                       $tag = DBA::selectFirst('tag', ['id'], $fields);
+                       if (!DBA::isResult($tag)) {
+                               DBA::insert('tag', $fields, true);
+                               $tagid = DBA::lastInsertId();
+                       } else {
+                               $tagid = $tag['id'];
+                       }
+       
+                       if (empty($tagid)) {
+                               Logger::error('No tag id created', $fields);
+                               return;
+                       }
+                       $cid = 0;
                }
 
-               DBA::insert('post-tag', ['uri-id' => $uriid, 'tid' => $tagid], true);
+               DBA::insert('post-tag', ['uri-id' => $uriid, 'type' => $type, 'tid' => $tagid, 'cid' => $cid], true);
 
-               Logger::info('Stored tag/mention', ['uri-id' => $uriid, 'tag-id' => $tagid, 'tag' => $fields]);
+               Logger::info('Stored tag/mention', ['uri-id' => $uriid, 'tag-id' => $tagid, 'contact-id' => $cid]);
        }
 
        /**
@@ -127,7 +144,7 @@ class Tag
         */
        public static function storeFromBody(int $uriid, string $body, string $tags = '#@!')
        {
-               if (!preg_match_all("/([" . $tags . "])\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism", $body, $result, PREG_SET_ORDER)) {
+               if (!preg_match_all("/([" . $tags . "])\[url\=([^\[\]]*)\]([^\[\]]*)\[\/url\]/ism", $body, $result, PREG_SET_ORDER)) {
                        return;
                }
 
index a1d72322a89a6d8bfec3ca312128aca4600fddc0..e0c3c5b70e154627d71bbfca58ddcc299585b681 100755 (executable)
@@ -1296,24 +1296,26 @@ return [
                "comment" => "tags and mentions",
                "fields" => [
                        "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
-                       "type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
                        "name" => ["type" => "varchar(96)", "not null" => "1", "default" => "", "comment" => ""],
                        "url" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => ""]
                ],
                "indexes" => [
-                       "PRIMARY" => ["id"],                    
-                       "type_name_url" => ["UNIQUE", "type", "name", "url"]
+                       "PRIMARY" => ["id"],
+                       "type_name_url" => ["UNIQUE", "name", "url"]
                ]
        ],
        "post-tag" => [
                "comment" => "post relation to tags",
                "fields" => [
-                       "tid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["tag" => "id"], "primary" => "1", "comment" => ""],
                        "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+                       "type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "comment" => ""],
+                       "tid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["tag" => "id"], "primary" => "1", "comment" => ""],
+                       "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["contact" => "id"], "comment" => "Contact id of the mentioned public contact"],
                ],
                "indexes" => [
-                       "PRIMARY" => ["tid", "uri-id"],
-                       "uri-id" => ["uri-id"]
+                       "PRIMARY" => ["uri-id", "type", "tid", "cid"],
+                       "uri-id" => ["tid"],
+                       "cid" => ["tid"]
                ]
        ],
        "thread" => [