]> git.mxchange.org Git - friendica.git/commitdiff
Store implicit mentions
authorMichael <heluecht@pirati.ca>
Mon, 20 Apr 2020 05:43:13 +0000 (05:43 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 20 Apr 2020 05:43:13 +0000 (05:43 +0000)
src/Model/Tag.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/DFRN.php

index 7ef4a2d82e220266d27e3b8a20231ba3e8e3994b..f99a83daefa8d45a3388c463d58526ee83735505 100644 (file)
@@ -115,7 +115,18 @@ class Tag
                        }
                }
 
-               DBA::insert('post-tag', ['uri-id' => $uriid, 'type' => $type, 'tid' => $tagid, 'cid' => $cid], true);
+               $fields = ['uri-id' => $uriid, 'type' => $type, 'tid' => $tagid, 'cid' => $cid];
+
+               if (in_array($type, [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION])) {
+                       $condition = $fields;
+                       $condition['type'] = [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION];
+                       if (DBA::exists('post-tag', $condition)) {
+                               Logger::info('Tag already exists', $fields);
+                               return;
+                       }
+               }
+
+               DBA::insert('post-tag', $fields, true);
 
                Logger::info('Stored tag/mention', ['uri-id' => $uriid, 'tag-id' => $tagid, 'contact-id' => $cid, 'callstack' => System::callstack(8)]);
        }
index b770e8a0de5713d2b9fef371ba2496ee93463340..2c0176257ff09a6713da37ab023b44672c1cb06f 100644 (file)
@@ -407,6 +407,7 @@ class Processor
 
                $item['tag'] = self::constructTagString($activity['tags'], $activity['sensitive']);
 
+               Tag::storeFromBody($item['uri-id'], $item['body'], '@!');
                self::storeTags($item['uri-id'], $activity['tags']);
 
                $item['location'] = $activity['location'];
@@ -602,9 +603,8 @@ class Processor
                                        Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION],
                                        Tag::TAG_CHARACTER[Tag::IMPLICIT_MENTION]])) {
                                        $tag['name'] = substr($tag['name'], 1);
-                               } else {
-                                       $hash = '#';
                                }
+                               $type = Tag::IMPLICIT_MENTION;
 
                                if (!empty($tag['href'])) {
                                        $apcontact = APContact::getByURL($tag['href']);
@@ -613,18 +613,17 @@ class Processor
                                        }
                                }
                        } elseif ($tag['type'] == 'Hashtag') {
-                               if (substr($tag['name'], 0, 1) == Term::TAG_CHARACTER[Term::HASHTAG]) {
+                               if ($hash == Tag::TAG_CHARACTER[Tag::HASHTAG]) {
                                        $tag['name'] = substr($tag['name'], 1);
-                               } else {
-                                       $hash = '@';
                                }
+                               $type = Tag::HASHTAG;
                        }
 
                        if (empty($tag['name'])) {
                                continue;
                        }
                        
-                       Tag::storeByHash($uriid, $hash, $tag['name'], $tag['href']);
+                       Tag::store($uriid, $type, $tag['name'], $tag['href']);
                }
        }
 
index 653e5c242beed68d2a8189c9ee1b9b34499272d1..83010f811e073901851b8ddd8af7c42db7b71cdc 100644 (file)
@@ -2410,7 +2410,7 @@ class DFRN
 
                $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
 
-               Tag::storeFromBody($item['uri-id'], $item["body"], '#');
+               Tag::storeFromBody($item['uri-id'], $item["body"]);
 
                // We store the data from "dfrn:diaspora_signature" in a different table, this is done in "Item::insert"
                $dsprsig = XML::unescape(XML::getFirstNodeValue($xpath, "dfrn:diaspora_signature/text()", $entry));
@@ -2466,7 +2466,7 @@ class DFRN
 
                                                $item["tag"] .= $termhash . "[url=" . $termurl . "]" . $term . "[/url]";
 
-                                               Tag::storeByHash($item['uri-id'], $termhash, $term, $termurl);
+                                               Tag::store($item['uri-id'], Tag::IMPLICIT_MENTION, $term, $termurl);
                                        }
                                }
                        }