Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2021-01-19 20:10:59 +0300
committerGitHub <noreply@github.com>2021-01-19 20:10:59 +0300
commitc284bb3966fc6c12ac86a5e3169ba87b5ad43557 (patch)
tree69054c174f9a0a1b1ab3f21284c2bacc1a3932ab /lib/Service
parent94f2736e855230438f5f82feb52108d3ca2af2d7 (diff)
parentbf9e58106a73e7ed0591c6b2216e5263247e1360 (diff)
Merge pull request #4362 from nextcloud/enhancement/priority-inbox-enhanced
Allow complex expressions in message search queries and enhance the PI
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/Search/FilterStringParser.php49
-rw-r--r--lib/Service/Search/FlagExpression.php80
-rw-r--r--lib/Service/Search/SearchQuery.php16
3 files changed, 145 insertions, 0 deletions
diff --git a/lib/Service/Search/FilterStringParser.php b/lib/Service/Search/FilterStringParser.php
index 64ecbe976..54698a374 100644
--- a/lib/Service/Search/FilterStringParser.php
+++ b/lib/Service/Search/FilterStringParser.php
@@ -68,6 +68,55 @@ class FilterStringParser {
$query->addFlag($type === 'is' ? $flag : $flag->invert());
return true;
}
+ if ($param === 'pi-important') {
+ // We assume this is about 'is' and not 'not'
+ // imp && ~read
+ $query->addFlagExpression(
+ FlagExpression::and(
+ Flag::is(Flag::IMPORTANT),
+ Flag::not(Flag::SEEN)
+ )
+ );
+
+ return true;
+ }
+ if ($param === 'pi-starred') {
+ // We assume this is about 'is' and not 'not'
+ // fav /\ (~imp \/ (imp /\ read))
+ $query->addFlagExpression(
+ FlagExpression::and(
+ Flag::is(Flag::FLAGGED),
+ FlagExpression::or(
+ Flag::not(Flag::IMPORTANT),
+ FlagExpression::or(
+ Flag::is(Flag::IMPORTANT),
+ Flag::is(Flag::SEEN)
+ )
+ )
+ )
+ );
+
+ return true;
+ }
+ if ($param === 'pi-other') {
+ // We assume this is about 'is' and not 'not'
+ // ~fav && (~imp || (imp && read))
+ $query->addFlagExpression(
+ FlagExpression::and(
+ Flag::not(Flag::FLAGGED),
+ FlagExpression::or(
+ Flag::not(Flag::IMPORTANT),
+ FlagExpression::and(
+ Flag::is(Flag::IMPORTANT),
+ Flag::is(Flag::SEEN)
+ )
+ )
+ )
+ );
+
+ return true;
+ }
+
break;
case 'from':
$query->addFrom($param);
diff --git a/lib/Service/Search/FlagExpression.php b/lib/Service/Search/FlagExpression.php
new file mode 100644
index 000000000..a219b8c8b
--- /dev/null
+++ b/lib/Service/Search/FlagExpression.php
@@ -0,0 +1,80 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\Mail\Service\Search;
+
+class FlagExpression {
+
+ /**
+ * @var string
+ * @psalm-var "and"|"or"
+ */
+ private $operator;
+
+ /**
+ * @var array
+ * @psalm-var (Flag|FlagExpression)[]
+ */
+ private $operands;
+
+ /**
+ * @psalm-param "and"|"or" $operator
+ * @param array $operands
+ */
+ private function __construct(string $operator, array $operands) {
+ $this->operator = $operator;
+ $this->operands = $operands;
+ }
+
+ /**
+ * @param Flag|FlagExpression ...$operands
+ *
+ * @return static
+ */
+ public static function and(...$operands): self {
+ return new self("and", $operands);
+ }
+
+ /**
+ * @param Flag|FlagExpression ...$operands
+ *
+ * @return static
+ */
+ public static function or(...$operands): self {
+ return new self("or", $operands);
+ }
+
+ public function getOperator(): string {
+ return $this->operator;
+ }
+
+ /**
+ * @return array
+ * @psalm-return (Flag|FlagExpression)[]
+ */
+ public function getOperands(): array {
+ return $this->operands;
+ }
+}
diff --git a/lib/Service/Search/SearchQuery.php b/lib/Service/Search/SearchQuery.php
index 10be01e69..57af668a4 100644
--- a/lib/Service/Search/SearchQuery.php
+++ b/lib/Service/Search/SearchQuery.php
@@ -33,6 +33,9 @@ class SearchQuery {
/** @var Flag[] */
private $flags = [];
+ /** @var FlagExpression[] */
+ private $flagExpressions = [];
+
/** @var string[] */
private $to = [];
@@ -53,6 +56,7 @@ class SearchQuery {
/**
* @return int|null
+ * @psalm-mutation-free
*/
public function getCursor(): ?int {
return $this->cursor;
@@ -67,6 +71,7 @@ class SearchQuery {
/**
* @return Flag[]
+ * @psalm-mutation-free
*/
public function getFlags(): array {
return $this->flags;
@@ -77,6 +82,17 @@ class SearchQuery {
}
/**
+ * @return FlagExpression[]
+ */
+ public function getFlagExpressions(): array {
+ return $this->flagExpressions;
+ }
+
+ public function addFlagExpression(FlagExpression $expression) {
+ $this->flagExpressions[] = $expression;
+ }
+
+ /**
* @return string[]
*/
public function getTo(): array {