Merge pull request #1531 from nextcloud/enh/noid/timelineoptions-on-direct

new direct timeline
pull/1517/head
Maxence Lange 2022-11-21 14:52:12 -01:00 zatwierdzone przez GitHub
commit b1a8d2b52a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 67 dodań i 45 usunięć

Wyświetl plik

@ -34,11 +34,11 @@ namespace OCA\Social\Command;
use Exception;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\UnknownTimelineException;
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\ConfigService;
use OCA\Social\Tools\Exceptions\DateTimeException;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -145,18 +145,12 @@ class Timeline extends ExtendedBase {
/**
* @param Person $actor
* @param string $timeline
* @param TimelineOptions $options
*
* @throws Exception
* @throws DateTimeException
*/
private function displayUnsupportedStream(TimelineOptions $options) {
switch ($options->getTimeline()) {
case 'direct':
$stream = $this->streamRequest->getTimelineDirect(0, $options->getLimit());
$this->outputStreams($stream);
break;
case 'notifications':
$stream = $this->streamRequest->getTimelineNotifications(0, $options->getLimit());
$this->outputStreams($stream);

Wyświetl plik

@ -334,22 +334,33 @@ class StreamRequest extends StreamRequestBuilder {
public function getTimeline(TimelineOptions $options): array {
switch (strtolower($options->getTimeline())) {
case 'home':
return $this->getTimelineHome($options);
$result = $this->getTimelineHome($options);
break;
case 'direct':
$result = $this->getTimelineDirect($options);
break;
case 'public':
$options->setLocal(false);
return $this->getTimelinePublic($options);
$result = $this->getTimelinePublic($options);
break;
case 'local':
$options->setLocal(true);
$result = $this->getTimelinePublic($options);
break;
return $this->getTimelinePublic($options);
default:
return [];
}
return [];
if ($options->isInverted()) {
$result = array_reverse($result);
}
return $result;
}
/**
* Should returns:
* Should return:
* * Own posts,
* * Followed accounts
*
@ -357,7 +368,7 @@ class StreamRequest extends StreamRequestBuilder {
*
* @return Stream[]
*/
public function getTimelineHome(TimelineOptions $options): array {
private function getTimelineHome(TimelineOptions $options): array {
$qb = $this->getStreamSelectSql($options->getFormat());
$qb->filterType(SocialAppNotification::TYPE);
@ -369,17 +380,37 @@ class StreamRequest extends StreamRequestBuilder {
$qb->leftJoinStreamAction('sa');
$qb->filterDuplicate();
$result = $this->getStreamsFromRequest($qb);
if ($options->isInverted()) {
$result = array_reverse($result);
}
return $result;
return $this->getStreamsFromRequest($qb);
}
/**
* Should returns:
* Should return:
* * Private message.
* - group messages. (not yet)
*
* @param TimelineOptions $options
*
* @return Stream[]
*/
private function getTimelineDirect(TimelineOptions $options): array {
$qb = $this->getStreamSelectSql();
$qb->filterType(SocialAppNotification::TYPE);
$qb->paginate($options);
$qb->linkToCacheActors('ca', 's.attributed_to_prim');
$viewer = $qb->getViewer();
$qb->selectDestFollowing('sd', '');
$qb->limitToDest($viewer->getId(), 'dm', '', 'sd');
return $this->getStreamsFromRequest($qb);
}
/**
* Should return:
* * Own posts,
* * Followed accounts
*
@ -410,7 +441,7 @@ class StreamRequest extends StreamRequestBuilder {
/**
* Should returns:
* Should return:
* * Public/Unlisted/Followers-only post where current $actor is tagged,
* - Events: (not yet)
* - people liking or re-posting your posts (not yet)
@ -442,7 +473,7 @@ class StreamRequest extends StreamRequestBuilder {
/**
* Should returns:
* Should return:
* * public message from actorId.
* - to followers-only if follower is logged. (not yet (check ?))
*
@ -472,7 +503,7 @@ class StreamRequest extends StreamRequestBuilder {
/**
* Should returns:
* Should return:
* * Private message.
* - group messages. (not yet)
*
@ -482,7 +513,7 @@ class StreamRequest extends StreamRequestBuilder {
* @return Stream[]
* @throws DateTimeException
*/
public function getTimelineDirect(int $since = 0, int $limit = 5): array {
public function getTimelineDirect_dep(int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
$qb->filterType(SocialAppNotification::TYPE);
@ -504,9 +535,8 @@ class StreamRequest extends StreamRequestBuilder {
* @param TimelineOptions $options
*
* @return Stream[]
* @throws DateTimeException
*/
public function getTimelinePublic(TimelineOptions $options): array {
private function getTimelinePublic(TimelineOptions $options): array {
$qb = $this->getStreamSelectSql($options->getFormat());
$qb->paginate($options);
@ -522,12 +552,7 @@ class StreamRequest extends StreamRequestBuilder {
$qb->innerJoinSteamDest('recipient', 'id_prim', 'sd', 's');
$qb->limitToDest(ACore::CONTEXT_PUBLIC, 'recipient', 'to', 'sd');
$result = $this->getStreamsFromRequest($qb);
if ($options->isInverted()) {
$result = array_reverse($result);
}
return $result;
return $this->getStreamsFromRequest($qb);
}
@ -596,7 +621,7 @@ class StreamRequest extends StreamRequestBuilder {
/**
* Should returns:
* Should return:
* - All public post related to a tag (not yet)
* - direct message related to a tag (not yet)
* - message to followers related to a tag (not yet)

Wyświetl plik

@ -30,13 +30,6 @@ declare(strict_types=1);
namespace OCA\Social\Service;
use OCA\Social\Tools\Exceptions\DateTimeException;
use OCA\Social\Tools\Exceptions\MalformedArrayException;
use OCA\Social\Tools\Exceptions\RequestContentException;
use OCA\Social\Tools\Exceptions\RequestNetworkException;
use OCA\Social\Tools\Exceptions\RequestResultNotJsonException;
use OCA\Social\Tools\Exceptions\RequestResultSizeException;
use OCA\Social\Tools\Exceptions\RequestServerException;
use Exception;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\InvalidOriginException;
@ -53,6 +46,13 @@ 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;
use OCA\Social\Tools\Exceptions\DateTimeException;
use OCA\Social\Tools\Exceptions\MalformedArrayException;
use OCA\Social\Tools\Exceptions\RequestContentException;
use OCA\Social\Tools\Exceptions\RequestNetworkException;
use OCA\Social\Tools\Exceptions\RequestResultNotJsonException;
use OCA\Social\Tools\Exceptions\RequestResultSizeException;
use OCA\Social\Tools\Exceptions\RequestServerException;
class StreamService {
private StreamRequest $streamRequest;
@ -400,7 +400,10 @@ class StreamService {
* @throws DateTimeException
* @deprecated
*/
public function getStreamHome(int $since = 0, int $limit = 5, int $format = Stream::FORMAT_ACTIVITYPUB
public function getStreamHome(
int $since = 0,
int $limit = 5,
int $format = Stream::FORMAT_ACTIVITYPUB
): array {
return $this->streamRequest->getTimelineHome_dep($since, $limit, $format);
}
@ -451,7 +454,7 @@ class StreamService {
* @deprecated
*/
public function getStreamDirect(int $since = 0, int $limit = 5): array {
return $this->streamRequest->getTimelineDirect($since, $limit);
return $this->streamRequest->getTimelineDirect_dep($since, $limit);
}