better navigation

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/985/head
Maxence Lange 2020-09-03 17:49:55 -01:00
rodzic 3cc446aa9d
commit c827dd3ef2
8 zmienionych plików z 509 dodań i 10 usunięć

Wyświetl plik

@ -40,9 +40,9 @@ return [
['name' => 'Config#local', 'url' => '/local/', 'verb' => 'GET'],
['name' => 'Config#remote', 'url' => '/test/{account}/', 'verb' => 'GET'],
[
'name' => 'Navigation#timeline', 'url' => '/timeline/{path}', 'verb' => 'GET',
'name' => 'Navigation#timeline', 'url' => '/timeline/{path}', 'verb' => 'GET',
'requirements' => ['path' => '.+'],
'defaults' => ['path' => '']
'defaults' => ['path' => '']
],
['name' => 'Navigation#documentGet', 'url' => '/document/get', 'verb' => 'GET'],
['name' => 'Navigation#documentGetPublic', 'url' => '/document/public', 'verb' => 'GET'],
@ -76,12 +76,12 @@ return [
['name' => 'OAuth#appsCredentials', 'url' => '/api/v1/apps/verify_credentials', 'verb' => 'GET'],
// Api for 3rd party
[
'name' => 'Api#verifyCredentials', 'url' => '/api/v1/accounts/verify_credentials',
'verb' => 'GET'
],
['name' => 'Api#verifyCredentials', 'url' => '/api/v1/accounts/verify_credentials', 'verb' => 'GET'],
['name' => 'Api#instance', 'url' => '/api/v1/instance/', 'verb' => 'GET'],
['name' => 'Api#customEmojis', 'url' => '/api/v1/custom_emojis', 'verb' => 'GET'],
['name' => 'Api#savedSearches', 'url' => '/api/saved_searches/list.json', 'verb' => 'GET'],
['name' => 'Api#timelines', 'url' => '/api/v1/timelines/{timeline}/', 'verb' => 'GET'],
['name' => 'Api#notifications', 'url' => '/api/v1/notifications', 'verb' => 'GET'],
// Api for local front-end
// TODO: front-end should be using the new ApiController

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;
@ -160,6 +161,51 @@ class ApiController extends Controller {
}
/**
* @NoCSRFRequired
* @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
@ -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) {

Wyświetl plik

@ -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;
@ -322,11 +323,41 @@ 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 {

Wyświetl plik

@ -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);

Wyświetl plik

@ -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;
}
}

Wyświetl plik

@ -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()
];
}
}

Wyświetl plik

@ -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);