diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-01-07 09:09:53 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2019-02-05 15:10:24 -0100 |
commit | 8cb56b0710dc3ddc71b0961d2ab649fba3619456 (patch) | |
tree | 25a9c7e6b353ba4e12b56c31e82966176fba5916 /lib | |
parent | 6f3f8fb86dcd42ac4288b0c9c505e98295cfe4a0 (diff) |
limit to viewable notes
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/LocalController.php | 4 | ||||
-rw-r--r-- | lib/Db/NotesRequest.php | 11 | ||||
-rw-r--r-- | lib/Db/NotesRequestBuilder.php | 26 | ||||
-rw-r--r-- | lib/Service/NoteService.php | 5 |
4 files changed, 34 insertions, 12 deletions
diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index a48461c1..8c01df3a 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -307,6 +307,7 @@ class LocalController extends Controller { * @NoCSRFRequired * @NoAdminRequired * + * @param string $hashtag * @param int $since * @param int $limit * @@ -314,7 +315,8 @@ class LocalController extends Controller { */ public function streamTag(string $hashtag, int $since = 0, int $limit = 5): DataResponse { try { - $posts = $this->noteService->getStreamLocalTag($hashtag, $since, $limit); + $this->initViewer(true); + $posts = $this->noteService->getStreamLocalTag($this->viewer, $hashtag, $since, $limit); return $this->success($posts); } catch (Exception $e) { diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 5701e319..ccfbb58d 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -313,20 +313,25 @@ class NotesRequest extends NotesRequestBuilder { * - direct message related to a tag (not yet) * - message to followers related to a tag (not yet) * + * @param Person $actor * @param string $hashtag * @param int $since * @param int $limit * * @return array */ - public function getStreamTag(string $hashtag, int $since = 0, int $limit = 5): array { + public function getStreamTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5 + ): array { $qb = $this->getNotesSelectSql(); -// // TODO: LIMIT TO NOTE RELATED TO THE VIEWER+PUBLIC + $on = $this->exprJoinFollowing($qb, $actor); + $on->add($this->exprLimitToRecipient($qb, ACore::CONTEXT_PUBLIC, false)); + $on->add($this->exprLimitToRecipient($qb, $actor->getId(), true)); + $qb->join($this->defaultSelectAlias, CoreRequestBuilder::TABLE_SERVER_FOLLOWS, 'f', $on); - $this->limitPaginate($qb, $since, $limit); $qb->andWhere($this->exprValueWithinJsonFormat($qb, 'hashtags', '#' . $hashtag)); + $this->limitPaginate($qb, $since, $limit); $this->leftJoinCacheActors($qb, 'attributed_to'); $notes = []; diff --git a/lib/Db/NotesRequestBuilder.php b/lib/Db/NotesRequestBuilder.php index c8c8868f..ee5845c5 100644 --- a/lib/Db/NotesRequestBuilder.php +++ b/lib/Db/NotesRequestBuilder.php @@ -80,11 +80,12 @@ class NotesRequestBuilder extends CoreRequestBuilder { $qb = $this->dbConnection->getQueryBuilder(); /** @noinspection PhpMethodParametersCountMismatchInspection */ - $qb->select( - 'sn.id', 'sn.type', 'sn.to', 'sn.to_array', 'sn.cc', 'sn.bcc', 'sn.content', - 'sn.summary', 'sn.hashtags', 'sn.published', 'sn.published_time', 'sn.attributed_to', - 'sn.in_reply_to', 'sn.source', 'sn.local', 'sn.instances', 'sn.creation' - ) + $qb->selectDistinct('sn.id') + ->addSelect( + 'sn.type', 'sn.to', 'sn.to_array', 'sn.cc', 'sn.bcc', 'sn.content', + 'sn.summary', 'sn.hashtags', 'sn.published', 'sn.published_time', 'sn.attributed_to', + 'sn.in_reply_to', 'sn.source', 'sn.local', 'sn.instances', 'sn.creation' + ) ->from(self::TABLE_SERVER_NOTES, 'sn'); $this->defaultSelectAlias = 'sn'; @@ -131,6 +132,19 @@ class NotesRequestBuilder extends CoreRequestBuilder { return; } + $on = $this->exprJoinFollowing($qb, $actor); + + $qb->join($this->defaultSelectAlias, CoreRequestBuilder::TABLE_SERVER_FOLLOWS, 'f', $on); + } + + + /** + * @param IQueryBuilder $qb + * @param Person $actor + * + * @return ICompositeExpression + */ + protected function exprJoinFollowing(IQueryBuilder $qb, Person $actor) { $expr = $qb->expr(); $func = $qb->func(); $pf = $this->defaultSelectAlias . '.'; @@ -152,7 +166,7 @@ class NotesRequestBuilder extends CoreRequestBuilder { $crossFollows->add($this->exprLimitToDBFieldInt($qb, 'accepted', 1, 'f')); $on->add($crossFollows); - $qb->join($this->defaultSelectAlias, CoreRequestBuilder::TABLE_SERVER_FOLLOWS, 'f', $on); + return $on; } diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php index 5518874d..78508dec 100644 --- a/lib/Service/NoteService.php +++ b/lib/Service/NoteService.php @@ -384,14 +384,15 @@ class NoteService { /** + * @param Person $actor * @param string $hashtag * @param int $since * @param int $limit * * @return Note[] */ - public function getStreamLocalTag(string $hashtag, int $since = 0, int $limit = 5): array { - return $this->notesRequest->getStreamTag($hashtag, $since, $limit); + public function getStreamLocalTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5): array { + return $this->notesRequest->getStreamTag($actor, $hashtag, $since, $limit); } |