summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2020-09-03 17:49:55 -0100
committerMaxence Lange <maxence@artificial-owl.com>2020-09-03 17:49:55 -0100
commitc827dd3ef2ec0d2ed475f65c8f70471b0ad6788b (patch)
treec2d50ff00619cb8dd448bfba33d1d8b59d0f1497 /lib
parent3cc446aa9d39d209d2d96d92783e92120a4a7f52 (diff)
better navigation
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Timeline.php2
-rw-r--r--lib/Controller/ApiController.php52
-rw-r--r--lib/Db/SocialLimitsQueryBuilder.php31
-rw-r--r--lib/Db/StreamRequest.php36
-rw-r--r--lib/Model/Client/Options/CoreOptions.php69
-rw-r--r--lib/Model/Client/Options/TimelineOptions.php296
-rw-r--r--lib/Service/StreamService.php21
7 files changed, 503 insertions, 4 deletions
diff --git a/lib/Command/Timeline.php b/lib/Command/Timeline.php
index e7062ba1..d8334b34 100644
--- a/lib/Command/Timeline.php
+++ b/lib/Command/Timeline.php
@@ -149,7 +149,7 @@ class Timeline extends ExtendedBase {
$this->streamRequest->setViewer($actor);
switch ($timeline) {
case 'home':
- $stream = $this->streamRequest->getTimelineHome(0, $this->count);
+ $stream = $this->streamRequest->getTimelineHome_dep(0, $this->count);
$this->outputStreams($stream);
break;
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php
index 32dc1fa4..ea369955 100644
--- a/lib/Controller/ApiController.php
+++ b/lib/Controller/ApiController.php
@@ -39,6 +39,7 @@ use OCA\Social\Exceptions\InstanceDoesNotExistException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Stream;
+use OCA\Social\Model\Client\Options\TimelineOptions;
use OCA\Social\Service\AccountService;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\ClientService;
@@ -165,6 +166,51 @@ class ApiController extends Controller {
* @PublicPage
*
* @return DataResponse
+ */
+ public function customEmojis(): DataResponse {
+ return new DataResponse([], Http::STATUS_OK);
+ }
+
+
+ /**
+ * @NoCSRFRequired
+ * @PublicPage
+ *
+ * @return DataResponse
+ */
+ public function savedSearches(): DataResponse {
+ try {
+ $this->initViewer(true);
+
+ return new DataResponse([], Http::STATUS_OK);
+ } catch (Exception $e) {
+ return $this->fail($e);
+ }
+ }
+
+
+ /**
+ * @NoCSRFRequired
+ * @PublicPage
+ *
+ * @return DataResponse
+ */
+ public function notifications(): DataResponse {
+ try {
+ $this->initViewer(true);
+
+ return new DataResponse([], Http::STATUS_OK);
+ } catch (Exception $e) {
+ return $this->fail($e);
+ }
+ }
+
+
+ /**
+ * @NoCSRFRequired
+ * @PublicPage
+ *
+ * @return DataResponse
* @throws InstanceDoesNotExistException
*/
public function instance(): DataResponse {
@@ -184,9 +230,13 @@ class ApiController extends Controller {
* @return DataResponse
*/
public function timelines(string $timeline, int $limit = 20): DataResponse {
+ $options = new TimelineOptions($this->request);
+ $options->setFormat(Stream::FORMAT_LOCAL);
+ $options->setTimeline($timeline);
+
try {
$this->initViewer(true);
- $posts = $this->streamService->getStreamHome(0, $limit, Stream::FORMAT_LOCAL);
+ $posts = $this->streamService->getTimeline($options);
return new DataResponse($posts, Http::STATUS_OK);
} catch (Exception $e) {
diff --git a/lib/Db/SocialLimitsQueryBuilder.php b/lib/Db/SocialLimitsQueryBuilder.php
index 16a8bd04..5a356a26 100644
--- a/lib/Db/SocialLimitsQueryBuilder.php
+++ b/lib/Db/SocialLimitsQueryBuilder.php
@@ -36,6 +36,7 @@ use DateInterval;
use DateTime;
use Exception;
use OCA\Social\Model\ActivityPub\ACore;
+use OCA\Social\Model\Client\Options\TimelineOptions;
use OCP\DB\QueryBuilder\ICompositeExpression;
@@ -323,10 +324,40 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
/**
+ * @param TimelineOptions $options
+ *
+ */
+ public function paginate(TimelineOptions $options) {
+ $expr = $this->expr();
+ $pf = $this->getDefaultSelectAlias();
+
+ if ($options->getSinceId() > 0) {
+ $this->andWhere($expr->gt($pf . '.nid', $this->createNamedParameter($options->getSinceId())));
+ }
+
+ $options->setMinId(16000);
+ if ($options->getMaxId() > 0) {
+ $this->andWhere($expr->lt($pf . '.nid', $this->createNamedParameter($options->getMaxId())));
+ }
+
+ if ($options->getMinId() > 0) {
+ $options->setInverted(true);
+ $this->andWhere($expr->gt($pf . '.nid', $this->createNamedParameter($options->getMaxId())));
+ }
+
+
+ //TODO : manage min_id: Return results immediately newer than id
+ $this->setMaxResults($options->getLimit());
+ $this->orderBy($pf . '.nid', ($options->isInverted()) ? 'asc' : 'desc');
+ }
+
+
+ /**
* @param int $since
* @param int $limit
*
* @throws DateTimeException
+ * @deprecated - use paginate()
*/
public function limitPaginate(int $since = 0, int $limit = 5) {
try {
diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php
index 1ab0cc5b..8ccfe6b1 100644
--- a/lib/Db/StreamRequest.php
+++ b/lib/Db/StreamRequest.php
@@ -42,6 +42,7 @@ use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
+use OCA\Social\Model\Client\Options\TimelineOptions;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -382,6 +383,38 @@ class StreamRequest extends StreamRequestBuilder {
* * Own posts,
* * Followed accounts
*
+ * @param TimelineOptions $options
+ *
+ * @return Stream[]
+ */
+ public function getTimelineHome(TimelineOptions $options): array {
+ $qb = $this->getStreamSelectSql($options->getFormat());
+ $qb->setChunk(1);
+
+ $qb->filterType(SocialAppNotification::TYPE);
+ $qb->paginate($options);
+
+ $qb->limitToViewer('sd', 'f', false);
+ $this->timelineHomeLinkCacheActor($qb, 'ca', 'f');
+
+ $qb->leftJoinStreamAction('sa');
+ $qb->filterDuplicate();
+
+ $result = $this->getStreamsFromRequest($qb);
+ if ($options->isInverted()) {
+ $result = array_reverse($result);
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * Should returns:
+ * * Own posts,
+ * * Followed accounts
+ *
+ * @deprecated - use GetTimeline()
* @param int $since
* @param int $limit
* @param int $format
@@ -389,7 +422,8 @@ class StreamRequest extends StreamRequestBuilder {
* @return Stream[]
* @throws DateTimeException
*/
- public function getTimelineHome(int $since = 0, int $limit = 5, int $format = Stream::FORMAT_ACTIVITYPUB
+ public function getTimelineHome_dep(
+ int $since = 0, int $limit = 5, int $format = Stream::FORMAT_ACTIVITYPUB
): array {
$qb = $this->getStreamSelectSql($format);
$qb->setChunk(1);
diff --git a/lib/Model/Client/Options/CoreOptions.php b/lib/Model/Client/Options/CoreOptions.php
new file mode 100644
index 00000000..d53c3937
--- /dev/null
+++ b/lib/Model/Client/Options/CoreOptions.php
@@ -0,0 +1,69 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Social\Model\Client\Options;
+
+
+use OCA\Social\Model\ActivityPub\ACore;
+
+
+/**
+ * Class TimelineOptions
+ *
+ * @package OCA\Social\Model\Client\Options
+ */
+class CoreOptions {
+
+
+ /** @var int */
+ private $format = ACore::FORMAT_ACTIVITYPUB;
+
+
+ /**
+ * @return int
+ */
+ public function getFormat(): int {
+ return $this->format;
+ }
+
+ /**
+ * @param int $format
+ *
+ * @return CoreOptions
+ */
+ public function setFormat(int $format): self {
+ $this->format = $format;
+
+ return $this;
+ }
+
+
+}
+
diff --git a/lib/Model/Client/Options/TimelineOptions.php b/lib/Model/Client/Options/TimelineOptions.php
new file mode 100644
index 00000000..3b3b6db4
--- /dev/null
+++ b/lib/Model/Client/Options/TimelineOptions.php
@@ -0,0 +1,296 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Social\Model\Client\Options;
+
+
+use daita\MySmallPhpTools\Traits\TArrayTools;
+use JsonSerializable;
+use OCP\IRequest;
+
+
+/**
+ * Class TimelineOptions
+ *
+ * @package OCA\Social\Model\Client\Options
+ */
+class TimelineOptions extends CoreOptions implements JsonSerializable {
+
+
+ use TArrayTools;
+
+
+ /** @var string */
+ private $timeline = '';
+
+ /** @var bool */
+ private $local = false;
+
+ /** @var bool */
+ private $remote = false;
+
+ /** @var bool */
+ private $onlyMedia = false;
+
+ /** @var int */
+ private $minId = 0;
+
+ /** @var int */
+ private $maxId = 0;
+
+ /** @var int */
+ private $sinceId = 0;
+
+ /** @var int */
+ private $limit = 20;
+
+ /** @var bool */
+ private $inverted = false;
+
+
+ /**
+ * TimelineOptions constructor.
+ *
+ * @param IRequest|null $request
+ */
+ public function __construct(IRequest $request = null) {
+ if ($request !== null) {
+ $this->fromArray($request->getParams());
+ }
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getTimeline(): string {
+ return $this->timeline;
+ }
+
+ /**
+ * @param string $timeline
+ *
+ * @return TimelineOptions
+ */
+ public function setTimeline(string $timeline): self {
+ $this->timeline = $timeline;
+
+ return $this;
+ }
+
+
+ /**
+ * @return bool
+ */
+ public function isLocal(): bool {
+ return $this->local;
+ }
+
+ /**
+ * @param bool $local
+ *
+ * @return TimelineOptions
+ */
+ public function setLocal(bool $local): self {
+ $this->local = $local;
+
+ return $this;
+ }
+
+
+ /**
+ * @return bool
+ */
+ public function isRemote(): bool {
+ return $this->remote;
+ }
+
+ /**
+ * @param bool $remote
+ *
+ * @return TimelineOptions
+ */
+ public function setRemote(bool $remote): self {
+ $this->remote = $remote;
+
+ return $this;
+ }
+
+
+ /**
+ * @return bool
+ */
+ public function isOnlyMedia(): bool {
+ return $this->onlyMedia;
+ }
+
+ /**
+ * @param bool $onlyMedia
+ *
+ * @return TimelineOptions
+ */
+ public function setOnlyMedia(bool $onlyMedia): self {
+ $this->onlyMedia = $onlyMedia;
+
+ return $this;
+ }
+
+
+ /**
+ * @return int
+ */
+ public function getMinId(): int {
+ return $this->minId;
+ }
+
+ /**
+ * @param int $minId
+ *
+ * @return TimelineOptions
+ */
+ public function setMinId(int $minId): self {
+ $this->minId = $minId;
+
+ return $this;
+ }
+
+
+ /**
+ * @return int
+ */
+ public function getMaxId(): int {
+ return $this->maxId;
+ }
+
+ /**
+ * @param int $maxId
+ *
+ * @return TimelineOptions
+ */
+ public function setMaxId(int $maxId): self {
+ $this->maxId = $maxId;
+
+ return $this;
+ }
+
+
+ /**
+ * @return int
+ */
+ public function getSinceId(): int {
+ return $this->sinceId;
+ }
+
+ /**
+ * @param int $sinceId
+ *
+ * @return TimelineOptions
+ */
+ public function setSinceId(int $sinceId): self {
+ $this->sinceId = $sinceId;
+
+ return $this;
+ }
+
+
+ /**
+ * @return int
+ */
+ public function getLimit(): int {
+ return $this->limit;
+ }
+
+ /**
+ * @param int $limit
+ *
+ * @return TimelineOptions
+ */
+ public function setLimit(int $limit): self {
+ $this->limit = $limit;
+
+ return $this;
+ }
+
+
+ /**
+ * @return bool
+ */
+ public function isInverted(): bool {
+ return $this->inverted;
+ }
+
+ /**
+ * @param bool $inverted
+ *
+ * @return TimelineOptions
+ */
+ public function setInverted(bool $inverted): self {
+ $this->inverted = $inverted;
+
+ return $this;
+ }
+
+
+ /**
+ * @param array $arr
+ *
+ * @return TimelineOptions
+ */
+ public function fromArray(array $arr): self {
+ $this->setLocal($this->getBool('local', $arr, $this->isLocal()));
+ $this->setRemote($this->getBool('remote', $arr, $this->isRemote()));
+ $this->setRemote($this->getBool('only_media', $arr, $this->isOnlyMedia()));
+ $this->setMinId($this->getInt('min_id', $arr, $this->getMinId()));
+ $this->setMaxId($this->getInt('max_id', $arr, $this->getMaxId()));
+ $this->setSinceId($this->getInt('since_id', $arr, $this->getSinceId()));
+ $this->setLimit($this->getInt('limit', $arr, $this->getLimit()));
+
+ return $this;
+ }
+
+
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array {
+ return
+ [
+ 'local' => $this->isLocal(),
+ 'remote' => $this->isRemote(),
+ 'only_media' => $this->isOnlyMedia(),
+ 'min_id' => $this->getMinId(),
+ 'max_id' => $this->getMaxId(),
+ 'since_id' => $this->getSinceId(),
+ 'limit' => $this->getLimit()
+ ];
+ }
+
+}
+
diff --git a/lib/Service/StreamService.php b/lib/Service/StreamService.php
index 45aa1370..8c37cf54 100644
--- a/lib/Service/StreamService.php
+++ b/lib/Service/StreamService.php
@@ -51,6 +51,7 @@ use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
+use OCA\Social\Model\Client\Options\TimelineOptions;
use OCA\Social\Model\InstancePath;
@@ -409,19 +410,34 @@ class StreamService {
*
* @return Note[]
* @throws DateTimeException
+ * @deprecated
*/
public function getStreamHome(int $since = 0, int $limit = 5, int $format = Stream::FORMAT_ACTIVITYPUB
): array {
- return $this->streamRequest->getTimelineHome($since, $limit, $format);
+ return $this->streamRequest->getTimelineHome_dep($since, $limit, $format);
}
/**
+ * @param TimelineOptions $options
+ *
+ * @return Note[]
+ */
+ public function getTimeline(TimelineOptions $options): array {
+ if ($options->getTimeline() === 'home') {
+ return $this->streamRequest->getTimelineHome($options);
+ }
+
+
+ }
+
+ /**
* @param int $since
* @param int $limit
*
* @return Note[]
* @throws Exception
+ * @deprecated
*/
public function getStreamNotifications(int $since = 0, int $limit = 5): array {
return $this->streamRequest->getTimelineNotifications($since, $limit);
@@ -435,6 +451,7 @@ class StreamService {
*
* @return Note[]
* @throws Exception
+ * @deprecated
*/
public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array {
return $this->streamRequest->getTimelineAccount($actorId, $since, $limit);
@@ -447,6 +464,7 @@ class StreamService {
*
* @return Note[]
* @throws Exception
+ * @deprecated
*/
public function getStreamDirect(int $since = 0, int $limit = 5): array {
return $this->streamRequest->getTimelineDirect($since, $limit);
@@ -459,6 +477,7 @@ class StreamService {
*
* @return Note[]
* @throws Exception
+ * @deprecated
*/
public function getStreamLocalTimeline(int $since = 0, int $limit = 5): array {
return $this->streamRequest->getTimelineGlobal($since, $limit, true);