From a8a9f93e09c0923427509bfe16dd9bcaf0ac14e7 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 22 Sep 2023 10:28:00 +0000 Subject: [PATCH] Special search keywords added --- database.sql | 4 +++ src/Model/Post/Engagement.php | 53 +++++++++++++++++++++++++--- src/Module/Conversation/Timeline.php | 6 +++- src/Module/Settings/Channels.php | 2 +- static/dbview.config.php | 4 +++ 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/database.sql b/database.sql index 25f94cac8..a2b588775 100644 --- a/database.sql +++ b/database.sql @@ -2090,6 +2090,7 @@ CREATE VIEW `post-user-view` AS SELECT `author`.`blocked` AS `author-blocked`, `author`.`hidden` AS `author-hidden`, `author`.`updated` AS `author-updated`, + `author`.`contact-type` AS `author-contact-type`, `author`.`gsid` AS `author-gsid`, `author`.`baseurl` AS `author-baseurl`, `post-user`.`owner-id` AS `owner-id`, @@ -2274,6 +2275,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT `author`.`blocked` AS `author-blocked`, `author`.`hidden` AS `author-hidden`, `author`.`updated` AS `author-updated`, + `author`.`contact-type` AS `author-contact-type`, `author`.`gsid` AS `author-gsid`, `post-thread-user`.`owner-id` AS `owner-id`, `owner`.`uri-id` AS `owner-uri-id`, @@ -2442,6 +2444,7 @@ CREATE VIEW `post-view` AS SELECT `author`.`blocked` AS `author-blocked`, `author`.`hidden` AS `author-hidden`, `author`.`updated` AS `author-updated`, + `author`.`contact-type` AS `author-contact-type`, `author`.`gsid` AS `author-gsid`, `post`.`owner-id` AS `owner-id`, `owner`.`uri-id` AS `owner-uri-id`, @@ -2587,6 +2590,7 @@ CREATE VIEW `post-thread-view` AS SELECT `author`.`blocked` AS `author-blocked`, `author`.`hidden` AS `author-hidden`, `author`.`updated` AS `author-updated`, + `author`.`contact-type` AS `author-contact-type`, `author`.`gsid` AS `author-gsid`, `post-thread`.`owner-id` AS `owner-id`, `owner`.`uri-id` AS `owner-uri-id`, diff --git a/src/Model/Post/Engagement.php b/src/Model/Post/Engagement.php index 3aec0c1e1..a23fe0184 100644 --- a/src/Model/Post/Engagement.php +++ b/src/Model/Post/Engagement.php @@ -53,8 +53,8 @@ class Engagement return; } - $parent = Post::selectFirst(['uri-id', 'created', 'owner-id', 'uid', 'private', 'contact-contact-type', 'language', - 'title', 'content-warning', 'body', 'author-name', 'author-nick', 'author-addr', 'owner-name', 'owner-nick', 'owner-addr'], + $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', 'owner-contact-type', 'owner-nick', 'owner-addr'], ['uri-id' => $item['parent-uri-id']]); if ($parent['created'] < DateTimeFormat::utc('now - ' . DI::config()->get('channel', 'engagement_hours') . ' hour')) { @@ -110,9 +110,52 @@ class Engagement private static function getSearchText(array $item): string { - $body = $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body'] . ' ' . - $item['author-name'] . ' ' . $item['author-nick'] . ' ' . $item['author-addr'] . ' ' . - $item['owner-name'] . ' ' . $item['owner-nick'] . ' ' . $item['owner-addr']; + $body = '[nosmile]network:' . $item['network']; + + switch ($item['private']) { + case Item::PUBLIC: + $body .= ' visibility:public'; + break; + case Item::UNLISTED: + $body .= ' visibility:unlisted'; + break; + case Item::PRIVATE: + $body .= ' visibility:private'; + break; + } + + if ($item['author-contact-type'] == Contact::TYPE_COMMUNITY) { + $body .= ' group:' . $item['author-nick'] . ' group:' . $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']; + } + + if ($item['author-id'] != $item['owner-id']) { + if ($item['owner-contact-type'] == Contact::TYPE_COMMUNITY) { + $body .= ' group:' . $item['owner-nick'] . ' group:' . $item['owner-addr']; + } elseif (in_array($item['owner-contact-type'], [Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION])) { + $body .= ' from:' . $item['owner-nick'] . ' from:' . $item['owner-addr']; + } + } + + foreach (Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION, Tag::AUDIENCE]) as $tag) { + $contact = Contact::getByURL($tag['name'], false, ['nick', 'addr', 'contact-type']); + if (empty($contact)) { + continue; + } + + if (($contact['contact-type'] == Contact::TYPE_COMMUNITY) && !strpos($body, 'group:' . $contact['addr'])) { + $body .= ' group:' . $contact['nick'] . ' group:' . $contact['addr']; + } elseif (in_array($contact['contact-type'], [Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION])) { + $body .= ' to:' . $contact['nick'] . ' to:' . $contact['addr']; + } + } + + foreach (Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]) as $tag) { + $body .= ' tag:' . $tag['name']; + } + + $body .= ' ' . $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body']; $body = Post\Media::addAttachmentsToBody($item['uri-id'], $body); $text = BBCode::toPlaintext($body, false); diff --git a/src/Module/Conversation/Timeline.php b/src/Module/Conversation/Timeline.php index 44149d1ec..a33bee4d0 100644 --- a/src/Module/Conversation/Timeline.php +++ b/src/Module/Conversation/Timeline.php @@ -376,7 +376,11 @@ class Timeline extends BaseModule $condition = []; if (!empty($channel->fullTextSearch)) { - $condition = DBA::mergeConditions($condition, ["MATCH (`searchtext`) AGAINST (? IN BOOLEAN MODE)", $channel->fullTextSearch]); + $search = $channel->fullTextSearch; + foreach (['from', 'to', 'group', 'tag', 'network', 'visibility'] as $keyword) { + $search = preg_replace('~(' . $keyword . ':.[\w@\.-]+)~', '"$1"', $search); + } + $condition = DBA::mergeConditions($condition, ["MATCH (`searchtext`) AGAINST (? IN BOOLEAN MODE)", $search]); } if (!empty($channel->includeTags)) { diff --git a/src/Module/Settings/Channels.php b/src/Module/Settings/Channels.php index ca9e8d168..0d4f47e14 100644 --- a/src/Module/Settings/Channels.php +++ b/src/Module/Settings/Channels.php @@ -134,7 +134,7 @@ class Channels extends BaseSettings 'access_key' => ["new_access_key", $this->t("Access Key"), '', $this->t('When you want to access this channel via an access key, you can define it here. Pay attentioon to not use an already used one.')], 'include_tags' => ["new_include_tags", $this->t("Include Tags"), '', $this->t('Comma separated list of tags. A post will be used when it contains any of the listed tags.')], 'exclude_tags' => ["new_exclude_tags", $this->t("Exclude Tags"), '', $this->t('Comma separated list of tags. If a post contain any of these tags, then it will not be part of nthis channel.')], - 'text_search' => ["new_text_search", $this->t("Full Text Search"), '', $this->t('Search terms for the body.')], + 'text_search' => ["new_text_search", $this->t("Full Text Search"), '', $this->t('Search terms for the body.')], // @todo Add dcumentation for the keywords 'image' => ['new_image', $this->t("Images"), false, $this->t("Check to display images in the channel.")], 'video' => ["new_video", $this->t("Videos"), false, $this->t("Check to display videos in the channel.")], 'audio' => ["new_audio", $this->t("Audio"), false, $this->t("Check to display audio in the channel.")], diff --git a/static/dbview.config.php b/static/dbview.config.php index d688cef3f..057c8fccc 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -184,6 +184,7 @@ "author-blocked" => ["author", "blocked"], "author-hidden" => ["author", "hidden"], "author-updated" => ["author", "updated"], + "author-contact-type" => ["author", "contact-type"], "author-gsid" => ["author", "gsid"], "author-baseurl" => ["author", "baseurl"], "owner-id" => ["post-user", "owner-id"], @@ -366,6 +367,7 @@ "author-blocked" => ["author", "blocked"], "author-hidden" => ["author", "hidden"], "author-updated" => ["author", "updated"], + "author-contact-type" => ["author", "contact-type"], "author-gsid" => ["author", "gsid"], "owner-id" => ["post-thread-user", "owner-id"], "owner-uri-id" => ["owner", "uri-id"], @@ -532,6 +534,7 @@ "author-blocked" => ["author", "blocked"], "author-hidden" => ["author", "hidden"], "author-updated" => ["author", "updated"], + "author-contact-type" => ["author", "contact-type"], "author-gsid" => ["author", "gsid"], "owner-id" => ["post", "owner-id"], "owner-uri-id" => ["owner", "uri-id"], @@ -675,6 +678,7 @@ "author-blocked" => ["author", "blocked"], "author-hidden" => ["author", "hidden"], "author-updated" => ["author", "updated"], + "author-contact-type" => ["author", "contact-type"], "author-gsid" => ["author", "gsid"], "owner-id" => ["post-thread", "owner-id"], "owner-uri-id" => ["owner", "uri-id"],