diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index fdd1313b..8d2a6ea1 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -266,7 +266,7 @@ class NotesRequest extends NotesRequestBuilder { } $this->leftJoinCacheActors($qb, 'attributed_to'); // TODO: to: = real public, cc: = unlisted !? - $this->limitToRecipient($qb, ActivityService::TO_PUBLIC); + $this->limitToRecipient($qb, ActivityService::TO_PUBLIC, true, ['to']); $notes = []; $cursor = $qb->execute(); diff --git a/lib/Db/NotesRequestBuilder.php b/lib/Db/NotesRequestBuilder.php index 872004fa..4f651211 100644 --- a/lib/Db/NotesRequestBuilder.php +++ b/lib/Db/NotesRequestBuilder.php @@ -230,11 +230,12 @@ class NotesRequestBuilder extends CoreRequestBuilder { * @param IQueryBuilder $qb * @param string $recipient * @param bool $asAuthor + * @param array $type */ protected function limitToRecipient( - IQueryBuilder &$qb, string $recipient, bool $asAuthor = false + IQueryBuilder &$qb, string $recipient, bool $asAuthor = false, array $type = [] ) { - $qb->andWhere($this->exprLimitToRecipient($qb, $recipient, $asAuthor)); + $qb->andWhere($this->exprLimitToRecipient($qb, $recipient, $asAuthor, $type)); } @@ -242,11 +243,12 @@ class NotesRequestBuilder extends CoreRequestBuilder { * @param IQueryBuilder $qb * @param string $recipient * @param bool $asAuthor + * @param array $type * * @return ICompositeExpression */ protected function exprLimitToRecipient( - IQueryBuilder &$qb, string $recipient, bool $asAuthor = false + IQueryBuilder &$qb, string $recipient, bool $asAuthor = false, array $type = [] ): ICompositeExpression { $expr = $qb->expr(); @@ -262,15 +264,42 @@ class NotesRequestBuilder extends CoreRequestBuilder { ); } - $limit->add($expr->eq('to', $qb->createNamedParameter($recipient))); - $limit->add($this->exprValueWithinJsonFormat($qb, 'to_array', $recipient)); - $limit->add($this->exprValueWithinJsonFormat($qb, 'cc', $recipient)); - $limit->add($this->exprValueWithinJsonFormat($qb, 'bcc', $recipient)); + if ($type === []) { + $type = ['to', 'cc', 'bcc']; + } + + $this->addLimitToRecipient($qb, $limit, $type, $recipient); return $limit; } + /** + * @param IQueryBuilder $qb + * @param ICompositeExpression $limit + * @param array $type + * @param string $to + */ + private function addLimitToRecipient( + IQueryBuilder $qb, ICompositeExpression &$limit, array $type, string $to + ) { + + $expr = $qb->expr(); + if (in_array('to', $type)) { + $limit->add($expr->eq('to', $qb->createNamedParameter($to))); + $limit->add($this->exprValueWithinJsonFormat($qb, 'to_array', $to)); + } + + if (in_array('cc', $type)) { + $limit->add($this->exprValueWithinJsonFormat($qb, 'cc', $to)); + } + + if (in_array('bcc', $type)) { + $limit->add($this->exprValueWithinJsonFormat($qb, 'bcc', $to)); + } + } + + /** * @param IQueryBuilder $qb * @param string $recipient