]> git.mxchange.org Git - friendica.git/commitdiff
Two new search options "media:card" and "media:post"
authorMichael <heluecht@pirati.ca>
Mon, 5 Feb 2024 22:21:58 +0000 (22:21 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 5 Feb 2024 22:21:58 +0000 (22:21 +0000)
doc/Channels.md
src/Model/Post/Engagement.php
src/Model/Post/SearchIndex.php

index 2e00e1a1c6a8efee44cd0e39c3cda713901745b0..bc47f631abf196dcdc9c1b6a1225b5a1df20f14c 100644 (file)
@@ -75,6 +75,8 @@ Alternatives are presented with "|".
     * media:image | media:photo | media:picture - The post contains an image
     * media:video - The post contains a video
     * media:audio - The post contains audio
+    * media:card - The post contains a link preview card
+    * media:post - The post links another post, means it is a quoted post
 * 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 e4647f43ed0bcc178dc041348978e9a6e2f467d6..d13fef7c4be708c1c4851e2a1b2322ca5e8e4cd5 100644 (file)
@@ -60,8 +60,10 @@ class Engagement
                        return 0;
                }
 
-               $parent = Post::selectFirst(['uri-id', 'created', 'author-id', 'owner-id', 'uid', 'private', 'contact-contact-type', 'language', 'network',
-                       'title', 'content-warning', 'body', 'author-contact-type', 'author-nick', 'author-addr', 'author-gsid', 'owner-contact-type', 'owner-nick', 'owner-addr', 'owner-gsid'],
+               $parent = Post::selectFirst(['uri-id', 'created', 'uid', 'private', 'quote-uri-id',
+                       'contact-contact-type', 'network', 'title', 'content-warning', 'body', 'language',
+                       'author-id', 'author-contact-type', 'author-nick', 'author-addr', 'author-gsid',
+                       'owner-id', 'owner-contact-type', 'owner-nick', 'owner-addr', 'owner-gsid'],
                        ['uri-id' => $item['parent-uri-id']]);
 
                if ($parent['created'] < self::getCreationDateLimit(false)) {
@@ -89,7 +91,7 @@ class Engagement
                        }
                }
 
-               $mediatype = self::getMediaType($item['parent-uri-id']);
+               $mediatype = self::getMediaType($item['parent-uri-id'], $parent['quote-uri-id']);
 
                if (!$store) {
                        $store = !empty($mediatype);
@@ -166,6 +168,7 @@ class Engagement
                        'owner-nick'          => $author['nick'],
                        'owner-addr'          => $author['addr'],
                        'owner-gsid'          => $author['gsid'],
+                       'quote-uri-id'        => 0,
                ];
 
                foreach ($receivers as $receiver) {
@@ -187,12 +190,12 @@ class Engagement
                }
 
                $post = Post::selectFirstPost(['uri-id', 'network', 'title', 'content-warning', 'body', 'private',
-                       'author-id', 'author-contact-type', 'author-nick', 'author-addr', 'author-gsid',
+                       'author-id', 'author-contact-type', 'author-nick', 'author-addr', 'author-gsid', 'quote-uri-id',
                        'owner-id', 'owner-contact-type', 'owner-nick', 'owner-addr', 'owner-gsid'], ['uri-id' => $uri_id]);
                if (empty($post['uri-id'])) {
                        return '';
                }
-               $mediatype = self::getMediaType($uri_id);
+               $mediatype = self::getMediaType($uri_id, $post['quote-uri-id']);
                return self::getSearchTextForItem($post, $mediatype);
        }
 
@@ -301,6 +304,14 @@ class Engagement
                        $body .= ' media_audio';
                }
 
+               if ($mediatype & 8) {
+                       $body .= ' media_card';
+               }
+
+               if ($mediatype & 16) {
+                       $body .= ' media_post';
+               }
+
                $body .= ' ' . $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body'];
 
                return BBCode::toSearchText($body, $item['uri-id']);
@@ -331,10 +342,10 @@ class Engagement
                return $text;
        }
 
-       public static function getMediaType(int $uri_id): int
+       public static function getMediaType(int $uri_id, int $quote_uri_id = null): int
        {
                $media = Post\Media::getByURIId($uri_id);
-               $type  = 0;
+               $type  = !empty($quote_uri_id) ? 16 : 0;
                foreach ($media as $entry) {
                        if ($entry['type'] == Post\Media::IMAGE) {
                                $type = $type | 1;
@@ -342,6 +353,10 @@ class Engagement
                                $type = $type | 2;
                        } elseif ($entry['type'] == Post\Media::AUDIO) {
                                $type = $type | 4;
+                       } elseif ($entry['type'] == Post\Media::HTML) {
+                               $type = $type | 8;
+                       } elseif ($entry['type'] == Post\Media::ACTIVITY) {
+                               $type = $type | 16;
                        }
                }
                return $type;
index 98a82cae63114332fac44a0b64e09b04fff13aa0..554a1b90a7d2758c67f12e266318e3ea7344d05b 100644 (file)
@@ -47,13 +47,13 @@ class SearchIndex
                        return;
                }
 
-               $item = Post::selectFirstPost(['created', 'owner-id', 'private', 'language', 'network', 'title', 'content-warning', 'body'], ['uri-id' => $uri_id]);
+               $item = Post::selectFirstPost(['created', 'owner-id', 'private', 'language', 'network', 'title', 'content-warning', 'body', 'quote-uri-id'], ['uri-id' => $uri_id]);
 
                $search = [
                        'uri-id'     => $uri_id,
                        'owner-id'   => $item['owner-id'],
-                       'media-type' => Engagement::getMediaType($uri_id),
-                       'language'   => !empty($item['language']) ? (array_key_first(json_decode($item['language'], true)) ?? L10n::UNDETERMINED_LANGUAGE) : L10n::UNDETERMINED_LANGUAGE,
+                       'media-type' => Engagement::getMediaType($uri_id, $item['quote-uri-id']),
+                       'language'   => substr(!empty($item['language']) ? (array_key_first(json_decode($item['language'], true)) ?? L10n::UNDETERMINED_LANGUAGE) : L10n::UNDETERMINED_LANGUAGE, 0, 2),
                        'searchtext' => Post\Engagement::getSearchTextForUriId($uri_id, $refresh),
                        'size'       => Engagement::getContentSize($item),
                        'created'    => $item['created'],