]> git.mxchange.org Git - friendica.git/commitdiff
"media" is added to the search text
authorMichael <heluecht@pirati.ca>
Fri, 2 Feb 2024 10:46:20 +0000 (10:46 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 2 Feb 2024 10:46:20 +0000 (10:46 +0000)
doc/Channels.md
src/Model/Post/Engagement.php

index 3f9e474918c46a7e514c1bd16db6c959aa5b4902..2e00e1a1c6a8efee44cd0e39c3cda713901745b0 100644 (file)
@@ -71,6 +71,10 @@ Alternatives are presented with "|".
     * source:service | source:news - The posts originates from a service account. This source type is often used to mark bot accounts.
     * source:application | source:relay - The post is created by an application. This is most likely unused in the fediverse for post creation.
 * tag - Use "tag:tagname" to search for a specific tag.
+* media - With this keyword you can search for attached media.
+    * media:image | media:photo | media:picture - The post contains an image
+    * media:video - The post contains a video
+    * media:audio - The post contains audio
 * network | net - Use this to include or exclude some networks from your channel.
     * network:apub | network:activitypub - ActivityPub (Used by the systems in the Fediverse)
     * network:dfrn | network:friendica - Legacy Friendica protocol. Nowayday Friendica mostly uses ActivityPub.
index 213550f9c61039b201c153c5e7f8468654ffd50c..e4647f43ed0bcc178dc041348978e9a6e2f467d6 100644 (file)
@@ -39,10 +39,12 @@ use Friendica\Util\DateTimeFormat;
 
 class Engagement
 {
-       const KEYWORDS     = ['source', 'server', 'from', 'to', 'group', 'application', 'tag', 'network', 'platform', 'visibility', 'language'];
+       const KEYWORDS     = ['source', 'server', 'from', 'to', 'group', 'application', 'tag', 'network', 'platform', 'visibility', 'language', 'media'];
        const SHORTCUTS    = ['lang' => 'language', 'net' => 'network', 'relay' => 'application'];
        const ALTERNATIVES = ['source:news' => 'source:service', 'source:relay' => 'source:application',
-               'network:activitypub' => 'network:apub', 'network:friendica' => 'network:dfrn', 'network:diaspora' => 'network:dspr', 'network:ostatus' => 'network:stat',
+               'media:picture' => 'media:image', 'media:photo' => 'media:image',
+               'network:activitypub' => 'network:apub', 'network:friendica' => 'network:dfrn',
+               'network:diaspora' => 'network:dspr', 'network:ostatus' => 'network:stat',
                'network:discourse' => 'network:dscs', 'network:tumblr' => 'network:tmbl', 'network:bluesky' => 'network:bsky'];
 
        /**
@@ -93,7 +95,7 @@ class Engagement
                        $store = !empty($mediatype);
                }
 
-               $searchtext = self::getSearchTextForItem($parent);
+               $searchtext = self::getSearchTextForItem($parent, $mediatype);
                $language   = !empty($parent['language']) ? (array_key_first(json_decode($parent['language'], true)) ?? L10n::UNDETERMINED_LANGUAGE) : L10n::UNDETERMINED_LANGUAGE;
                if (!$store) {
                        $store = DI::userDefinedChannel()->match($searchtext, $language);
@@ -172,7 +174,7 @@ class Engagement
                        }
                }
 
-               return self::getSearchText($item, $receivers, $tags);
+               return self::getSearchText($item, $receivers, $tags, 0);
        }
 
        public static function getSearchTextForUriId(int $uri_id, bool $refresh = false): string
@@ -190,17 +192,18 @@ class Engagement
                if (empty($post['uri-id'])) {
                        return '';
                }
-               return self::getSearchTextForItem($post);
+               $mediatype = self::getMediaType($uri_id);
+               return self::getSearchTextForItem($post, $mediatype);
        }
 
-       private static function getSearchTextForItem(array $item): string
+       private static function getSearchTextForItem(array $item, int $mediatype): string
        {
                $receivers = array_column(Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION, Tag::AUDIENCE]), 'url');
                $tags      = array_column(Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]), 'name');
-               return self::getSearchText($item, $receivers, $tags);
+               return self::getSearchText($item, $receivers, $tags, $mediatype);
        }
 
-       private static function getSearchText(array $item, array $receivers, array $tags): string
+       private static function getSearchText(array $item, array $receivers, array $tags, int $mediatype): string
        {
                $body = '[nosmile]network_' . $item['network'];
 
@@ -286,6 +289,18 @@ class Engagement
                        $body .= ' language_' . array_key_first($languages);
                }
 
+               if ($mediatype & 1) {
+                       $body .= ' media_image';
+               }
+
+               if ($mediatype & 2) {
+                       $body .= ' media_video';
+               }
+
+               if ($mediatype & 4) {
+                       $body .= ' media_audio';
+               }
+
                $body .= ' ' . $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body'];
 
                return BBCode::toSearchText($body, $item['uri-id']);