From 4a1366b8b61ccfe4d32c3895c93ad9098022b659 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Sat, 8 Dec 2018 11:22:27 -0100 Subject: [PATCH] Display on to:PUBLIC message --- lib/Db/NotesRequest.php | 2 +- lib/Db/NotesRequestBuilder.php | 43 ++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 9e687e25..d9cf8427 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -265,7 +265,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