diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-11-28 09:39:31 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-11-28 09:39:31 -0100 |
commit | b36e56cee92560692aee247e5e08da5e6fa0f5e6 (patch) | |
tree | 827b169aeff398fb65f2fa42ec779c3fbd1a42c5 /lib/Db | |
parent | 15358d0e478e7de4ba7efdc2fe5d6e0c2c30d8c7 (diff) |
displays post with current user as author
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Db')
-rw-r--r-- | lib/Db/CoreRequestBuilder.php | 34 | ||||
-rw-r--r-- | lib/Db/NotesRequest.php | 13 |
2 files changed, 38 insertions, 9 deletions
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index 104cbd5f..e62d72fe 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -307,13 +307,19 @@ class CoreRequestBuilder { /** * @param IQueryBuilder $qb * @param string $recipient + * @param bool $asAuthor */ - protected function limitToRecipient(IQueryBuilder &$qb, string $recipient) { + protected function limitToRecipient( + IQueryBuilder &$qb, string $recipient, bool $asAuthor = false + ) { $expr = $qb->expr(); $orX = $expr->orX(); $dbConn = $this->dbConnection; - $orX->add($expr->eq('attributed_to', $qb->createNamedParameter($recipient))); + if ($asAuthor === true) { + $orX->add($expr->eq('attributed_to', $qb->createNamedParameter($recipient))); + } + $orX->add($expr->eq('to', $qb->createNamedParameter($recipient))); $orX->add( $expr->like( @@ -373,6 +379,23 @@ class CoreRequestBuilder { protected function limitToDBField( IQueryBuilder &$qb, string $field, string $value, bool $cs = true, string $alias = '' ) { + $expr = $this->exprLimitToDBField($qb, $field, $value, $cs, $alias); + $qb->andWhere($expr); + } + + + /** + * @param IQueryBuilder $qb + * @param string $field + * @param string $value + * @param bool $cs + * @param string $alias + * + * @return string + */ + protected function exprLimitToDBField( + IQueryBuilder &$qb, string $field, string $value, bool $cs = true, string $alias = '' + ): string { $expr = $qb->expr(); $pf = ''; @@ -382,12 +405,11 @@ class CoreRequestBuilder { $field = $pf . $field; if ($cs) { - $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value))); + return $expr->eq($field, $qb->createNamedParameter($value)); } else { $func = $qb->func(); - $qb->andWhere( - $expr->eq($func->lower($field), $func->lower($qb->createNamedParameter($value))) - ); + + return $expr->eq($func->lower($field), $func->lower($qb->createNamedParameter($value))); } } diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 3c176a85..e2c7d9c8 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -139,14 +139,18 @@ class NotesRequest extends NotesRequestBuilder { /** * @param string $actorId + * @param int $since + * @param int $limit * * @return array */ - public function getHomeNotesForActorId(string $actorId, $since, $limit): array { + public function getHomeNotesForActorId(string $actorId, int $since = 0, int $limit = 5): array { $qb = $this->getNotesSelectSql(); $this->rightJoinFollowing($qb); $this->limitToActorId($qb, $actorId, 'f'); + $qb->orWhere($this->exprLimitToDBField($qb, 'attributed_to', $actorId)); + $this->limitPaginate($qb, $since, $limit); $this->leftJoinCacheActors($qb, 'attributed_to'); @@ -190,12 +194,15 @@ class NotesRequest extends NotesRequestBuilder { /** * @param string $actorId + * @param int $since + * @param int $limit * * @return array */ - public function getDirectNotesForActorId(string $actorId, $since, $limit): array { + public function getDirectNotesForActorId(string $actorId, int $since = 0, int $limit = 5 + ): array { $qb = $this->getNotesSelectSql(); - $this->limitToRecipient($qb, $actorId); + $this->limitToRecipient($qb, $actorId, true); $this->limitPaginate($qb, $since, $limit); $this->leftJoinCacheActors($qb, 'attributed_to'); |