"media" is added to the search text

This commit is contained in:
Michael 2024-02-02 10:46:20 +00:00
parent 7faa42882b
commit fc05daefb5
2 changed files with 27 additions and 8 deletions

View 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: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. * 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. * 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 | 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:apub | network:activitypub - ActivityPub (Used by the systems in the Fediverse)
* network:dfrn | network:friendica - Legacy Friendica protocol. Nowayday Friendica mostly uses ActivityPub. * network:dfrn | network:friendica - Legacy Friendica protocol. Nowayday Friendica mostly uses ActivityPub.

View File

@ -39,10 +39,12 @@ use Friendica\Util\DateTimeFormat;
class Engagement 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 SHORTCUTS = ['lang' => 'language', 'net' => 'network', 'relay' => 'application'];
const ALTERNATIVES = ['source:news' => 'source:service', 'source:relay' => 'source: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']; 'network:discourse' => 'network:dscs', 'network:tumblr' => 'network:tmbl', 'network:bluesky' => 'network:bsky'];
/** /**
@ -93,7 +95,7 @@ class Engagement
$store = !empty($mediatype); $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; $language = !empty($parent['language']) ? (array_key_first(json_decode($parent['language'], true)) ?? L10n::UNDETERMINED_LANGUAGE) : L10n::UNDETERMINED_LANGUAGE;
if (!$store) { if (!$store) {
$store = DI::userDefinedChannel()->match($searchtext, $language); $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 public static function getSearchTextForUriId(int $uri_id, bool $refresh = false): string
@ -190,17 +192,18 @@ class Engagement
if (empty($post['uri-id'])) { if (empty($post['uri-id'])) {
return ''; 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'); $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'); $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']; $body = '[nosmile]network_' . $item['network'];
@ -286,6 +289,18 @@ class Engagement
$body .= ' language_' . array_key_first($languages); $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']; $body .= ' ' . $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body'];
return BBCode::toSearchText($body, $item['uri-id']); return BBCode::toSearchText($body, $item['uri-id']);