]> git.mxchange.org Git - friendica.git/commitdiff
Searchtext functionality added
authorMichael <heluecht@pirati.ca>
Mon, 29 Jan 2024 11:02:13 +0000 (11:02 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 29 Jan 2024 11:02:13 +0000 (11:02 +0000)
src/Model/Post/Engagement.php

index 17ccd414e84ef6eba5bfef5b72c04a63fd28cb8e..388ab67b5e26fb731ff566c71b6f76e294739ae2 100644 (file)
@@ -38,7 +38,7 @@ use Friendica\Util\DateTimeFormat;
 
 class Engagement
 {
-       const KEYWORDS = ['source', 'server', 'from', 'to', 'group', 'tag', 'network', 'platform', 'visibility', 'language'];
+       const KEYWORDS = ['source', 'server', 'from', 'to', 'group', 'application', 'tag', 'network', 'platform', 'visibility', 'language'];
 
        /**
         * Store engagement data from an item array
@@ -230,6 +230,8 @@ class Engagement
 
                if ($item['author-contact-type'] == Contact::TYPE_COMMUNITY) {
                        $body .= ' group_' . $item['author-nick'] . ' group_' . $item['author-addr'];
+               } elseif ($item['author-contact-type'] == Contact::TYPE_RELAY) {
+                       $body .= ' application_' . $item['author-nick'] . ' application_' . $item['author-addr'];
                } elseif (in_array($item['author-contact-type'], [Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION])) {
                        $body .= ' from_' . $item['author-nick'] . ' from_' . $item['author-addr'];
                }
@@ -242,6 +244,8 @@ class Engagement
                        }
                }
 
+               $body = self::addResharers($body, $item['uri-id']);
+
                foreach ($receivers as $receiver) {
                        $contact = Contact::getByURL($receiver, false, ['nick', 'addr', 'contact-type']);
                        if (empty($contact)) {
@@ -269,6 +273,31 @@ class Engagement
                return BBCode::toSearchText($body, $item['uri-id']);
        }
 
+       private static function addResharers(string $text, int $uri_id): string
+       {
+               $result = Post::selectPosts(['author-addr', 'author-nick', 'author-contact-type'],
+                       ['thr-parent-id' => $uri_id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE, 'author-contact-type' => [Contact::TYPE_RELAY, Contact::TYPE_COMMUNITY]]);
+               while ($reshare = Post::fetch($result)) {
+                       switch ($reshare['author-contact-type']) {
+                               case Contact::TYPE_RELAY:
+                                       $prefix = ' application_';
+                                       break;
+                               case Contact::TYPE_COMMUNITY:
+                                       $prefix = ' group_';
+                                       break;
+                               }
+                               $nick = $prefix . $reshare['author-nick'];
+                               $addr = $prefix . $reshare['author-addr'];
+
+                               if (stripos($text, $addr) === false) {
+                                       $text .= $nick . $addr;
+                               }
+               }
+               DBA::close($result);
+
+               return $text;
+       }
+
        private static function getMediaType(int $uri_id): int
        {
                $media = Post\Media::getByURIId($uri_id);