From fc05daefb5b23e7c120ea74fb4302165b694c8ad Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 2 Feb 2024 10:46:20 +0000 Subject: [PATCH] "media" is added to the search text --- doc/Channels.md | 4 ++++ src/Model/Post/Engagement.php | 31 +++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/doc/Channels.md b/doc/Channels.md index 3f9e474918..2e00e1a1c6 100644 --- a/doc/Channels.md +++ b/doc/Channels.md @@ -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. diff --git a/src/Model/Post/Engagement.php b/src/Model/Post/Engagement.php index 213550f9c6..e4647f43ed 100644 --- a/src/Model/Post/Engagement.php +++ b/src/Model/Post/Engagement.php @@ -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']);