summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-09-12 11:49:51 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-09-25 14:06:47 +0200
commit686f193c997e273fe1e7f6cd661b15fa9846dfd8 (patch)
tree46cfa2a4e19d8cc47b05f640f98b4a9a9d08d4f9 /lib
parentb1c50f91f61cf21e88e909b9c626aa883daf032d (diff)
add pagination
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/LocalController.php6
-rw-r--r--lib/Db/CoreRequestBuilder.php14
-rw-r--r--lib/Db/StreamRequest.php21
-rw-r--r--lib/Service/StreamService.php6
4 files changed, 30 insertions, 17 deletions
diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php
index bf1671e6..d642d59b 100644
--- a/lib/Controller/LocalController.php
+++ b/lib/Controller/LocalController.php
@@ -220,14 +220,16 @@ class LocalController extends Controller {
* @NoCSRFRequired
*
* @param string $id
+ * @param int $since
+ * @param int $limit
*
* @return DataResponse
*/
- public function postReplies(string $id): DataResponse {
+ public function postReplies(string $id, int $since = 0, int $limit = 5): DataResponse {
try {
$this->initViewer(true);
- return $this->success($this->streamService->getRepliesByParentId($id, true));
+ return $this->success($this->streamService->getRepliesByParentId($id, $since, $limit, true));
} catch (Exception $e) {
return $this->fail($e);
}
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php
index e1e09a34..4e9f1888 100644
--- a/lib/Db/CoreRequestBuilder.php
+++ b/lib/Db/CoreRequestBuilder.php
@@ -506,13 +506,17 @@ class CoreRequestBuilder {
* @param int $since
* @param int $limit
*
- * @throws Exception
+ * @throws DateTimeException
*/
protected function limitPaginate(IQueryBuilder &$qb, int $since = 0, int $limit = 5) {
- if ($since > 0) {
- $dTime = new DateTime();
- $dTime->setTimestamp($since);
- $this->limitToDBFieldDateTime($qb, 'published_time', $dTime);
+ try {
+ if ($since > 0) {
+ $dTime = new DateTime();
+ $dTime->setTimestamp($since);
+ $this->limitToDBFieldDateTime($qb, 'published_time', $dTime);
+ }
+ } catch (\Exception $e) {
+ throw new DateTimeException();
}
$qb->setMaxResults($limit);
diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php
index 56165c4b..1d120ebe 100644
--- a/lib/Db/StreamRequest.php
+++ b/lib/Db/StreamRequest.php
@@ -257,18 +257,23 @@ class StreamRequest extends StreamRequestBuilder {
/**
* @param string $id
+ * @param int $since
+ * @param int $limit
* @param bool $asViewer
*
* @return Stream[]
* @throws StreamNotFoundException
+ * @throws DateTimeException
*/
- public function getRepliesByParentId(string $id, bool $asViewer = false): array {
+ public function getRepliesByParentId(string $id, int $since = 0, int $limit = 5, bool $asViewer = false
+ ): array {
if ($id === '') {
throw new StreamNotFoundException();
};
$qb = $this->getStreamSelectSql();
$this->limitToInReplyTo($qb, $id);
+ $this->limitPaginate($qb, $since, $limit);
$this->leftJoinCacheActors($qb, 'attributed_to');
if ($asViewer) {
@@ -353,7 +358,7 @@ class StreamRequest extends StreamRequestBuilder {
* @param int $limit
*
* @return Stream[]
- * @throws Exception
+ * @throws DateTimeException
*/
public function getTimelineHome(Person $actor, int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
@@ -387,7 +392,7 @@ class StreamRequest extends StreamRequestBuilder {
* @param int $limit
*
* @return Stream[]
- * @throws Exception
+ * @throws DateTimeException
*/
public function getTimelineNotifications(Person $actor, int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
@@ -413,7 +418,7 @@ class StreamRequest extends StreamRequestBuilder {
* @param int $limit
*
* @return Stream[]
- * @throws Exception
+ * @throws DateTimeException
*/
public function getTimelineAccount(string $actorId, int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
@@ -439,7 +444,7 @@ class StreamRequest extends StreamRequestBuilder {
* @param int $limit
*
* @return Stream[]
- * @throws Exception
+ * @throws DateTimeException
*/
public function getTimelineDirect(Person $actor, int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
@@ -466,7 +471,7 @@ class StreamRequest extends StreamRequestBuilder {
* @param bool $localOnly
*
* @return Stream[]
- * @throws Exception
+ * @throws DateTimeException
*/
public function getTimelineGlobal(int $since = 0, int $limit = 5, bool $localOnly = true
): array {
@@ -495,7 +500,7 @@ class StreamRequest extends StreamRequestBuilder {
* @param bool $localOnly
*
* @return Stream[]
- * @throws Exception
+ * @throws DateTimeException
*/
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true): array {
$qb = $this->getStreamSelectSql();
@@ -524,7 +529,7 @@ class StreamRequest extends StreamRequestBuilder {
* @param int $limit
*
* @return Stream[]
- * @throws Exception
+ * @throws DateTimeException
*/
public function getTimelineTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
): array {
diff --git a/lib/Service/StreamService.php b/lib/Service/StreamService.php
index 499af4c1..fd1e5f17 100644
--- a/lib/Service/StreamService.php
+++ b/lib/Service/StreamService.php
@@ -391,13 +391,15 @@ class StreamService {
/**
* @param string $id
+ * @param int $since
+ * @param int $limit
* @param bool $asViewer
*
* @return Stream[]
* @throws StreamNotFoundException
*/
- public function getRepliesByParentId(string $id, bool $asViewer = false): array {
- return $this->streamRequest->getRepliesByParentId($id, $asViewer);
+ public function getRepliesByParentId(string $id, int $since = 0, int $limit = 5, bool $asViewer = false): array {
+ return $this->streamRequest->getRepliesByParentId($id, $since, $limit, $asViewer);
}