Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/1633/head
Maxence Lange 2023-03-08 00:17:31 -01:00
rodzic 8d4ea5eec2
commit 9cbfa96f40
15 zmienionych plików z 320 dodań i 121 usunięć

Wyświetl plik

@ -93,6 +93,8 @@ return [
['name' => 'Api#statusAction', 'url' => '/api/v1/statuses/{nid}/{act}', 'verb' => 'POST'], ['name' => 'Api#statusAction', 'url' => '/api/v1/statuses/{nid}/{act}', 'verb' => 'POST'],
['name' => 'Api#accountStatuses', 'url' => '/api/v1/accounts/{account}/statuses', 'verb' => 'GET'], ['name' => 'Api#accountStatuses', 'url' => '/api/v1/accounts/{account}/statuses', 'verb' => 'GET'],
['name' => 'Api#accountFollowers', 'url' => '/api/v1/accounts/{account}/followers', 'verb' => 'GET'],
['name' => 'Api#accountFollowing', 'url' => '/api/v1/accounts/{account}/following', 'verb' => 'GET'],
// Api for local front-end // Api for local front-end
// TODO: front-end should be using the new ApiController // TODO: front-end should be using the new ApiController
@ -124,14 +126,14 @@ return [
['name' => 'Local#currentFollowing', 'url' => '/api/v1/current/following', 'verb' => 'GET'], ['name' => 'Local#currentFollowing', 'url' => '/api/v1/current/following', 'verb' => 'GET'],
['name' => 'Local#accountInfo', 'url' => '/api/v1/account/{username}/info', 'verb' => 'GET'], ['name' => 'Local#accountInfo', 'url' => '/api/v1/account/{username}/info', 'verb' => 'GET'],
[ // [
'name' => 'Local#accountFollowers', 'url' => '/api/v1/account/{username}/followers', // 'name' => 'Local#accountFollowers', 'url' => '/api/v1/account/{username}/followers',
'verb' => 'GET' // 'verb' => 'GET'
], // ],
[ // [
'name' => 'Local#accountFollowing', 'url' => '/api/v1/account/{username}/following', // 'name' => 'Local#accountFollowing', 'url' => '/api/v1/account/{username}/following',
'verb' => 'GET' // 'verb' => 'GET'
], // ],
['name' => 'Local#globalAccountInfo', 'url' => '/api/v1/global/account/info', 'verb' => 'GET'], ['name' => 'Local#globalAccountInfo', 'url' => '/api/v1/global/account/info', 'verb' => 'GET'],
['name' => 'Local#globalActorInfo', 'url' => '/api/v1/global/actor/info', 'verb' => 'GET'], ['name' => 'Local#globalActorInfo', 'url' => '/api/v1/global/actor/info', 'verb' => 'GET'],

Wyświetl plik

@ -34,7 +34,7 @@ namespace OCA\Social\Command;
use Exception; use Exception;
use OCA\Social\Db\StreamRequest; use OCA\Social\Db\StreamRequest;
use OCA\Social\Model\ActivityPub\Stream; use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\Client\Options\TimelineOptions; use OCA\Social\Model\Client\Options\ProbeOptions;
use OCA\Social\Service\AccountService; use OCA\Social\Service\AccountService;
use OCA\Social\Service\CacheActorService; use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\ConfigService; use OCA\Social\Service\ConfigService;
@ -130,7 +130,7 @@ class Timeline extends ExtendedBase {
$this->streamRequest->setViewer($actor); $this->streamRequest->setViewer($actor);
$options = new TimelineOptions(); $options = new ProbeOptions();
$options->setFormat(Stream::FORMAT_LOCAL); $options->setFormat(Stream::FORMAT_LOCAL);
$options->setLimit(intval($input->getOption('limit'))) $options->setLimit(intval($input->getOption('limit')))
->setMinId(intval($input->getOption('min_id'))) ->setMinId(intval($input->getOption('min_id')))
@ -140,7 +140,7 @@ class Timeline extends ExtendedBase {
if ($input->getOption('local')) { if ($input->getOption('local')) {
$options->setLocal(true); $options->setLocal(true);
} }
$options->setTimeline($input->getArgument('timeline')); $options->setProbe($input->getArgument('timeline'));
if ($input->getOption('account') !== '') { if ($input->getOption('account') !== '') {
$local = $this->cacheActorService->getFromLocalAccount($input->getOption('account')); $local = $this->cacheActorService->getFromLocalAccount($input->getOption('account'));

Wyświetl plik

@ -36,12 +36,13 @@ use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\AccountDoesNotExistException; use OCA\Social\Exceptions\AccountDoesNotExistException;
use OCA\Social\Exceptions\ClientNotFoundException; use OCA\Social\Exceptions\ClientNotFoundException;
use OCA\Social\Exceptions\InstanceDoesNotExistException; use OCA\Social\Exceptions\InstanceDoesNotExistException;
use OCA\Social\Exceptions\UnknownProbeException;
use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Document; use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Stream; use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\Client\MediaAttachment; use OCA\Social\Model\Client\MediaAttachment;
use OCA\Social\Model\Client\Options\TimelineOptions; use OCA\Social\Model\Client\Options\ProbeOptions;
use OCA\Social\Model\Client\SocialClient; use OCA\Social\Model\Client\SocialClient;
use OCA\Social\Model\Client\Status; use OCA\Social\Model\Client\Status;
use OCA\Social\Model\Post; use OCA\Social\Model\Post;
@ -412,9 +413,23 @@ class ApiController extends Controller {
try { try {
$this->initViewer(true); $this->initViewer(true);
$options = new TimelineOptions($this->request); if (!in_array(
strtolower($timeline),
[
ProbeOptions::HOME,
ProbeOptions::ACCOUNT,
ProbeOptions::PUBLIC,
ProbeOptions::DIRECT,
ProbeOptions::FAVOURITES,
ProbeOptions::NOTIFICATIONS
]
)) {
throw new UnknownProbeException('unknown timeline');
}
$options = new ProbeOptions($this->request);
$options->setFormat(ACore::FORMAT_LOCAL); $options->setFormat(ACore::FORMAT_LOCAL);
$options->setTimeline($timeline) $options->setProbe($timeline)
->setLocal($local) ->setLocal($local)
->setLimit($limit) ->setLimit($limit)
->setMaxId($max_id) ->setMaxId($max_id)
@ -519,9 +534,9 @@ class ApiController extends Controller {
$local = $this->cacheActorService->getFromLocalAccount($account); $local = $this->cacheActorService->getFromLocalAccount($account);
$options = new TimelineOptions($this->request); $options = new ProbeOptions($this->request);
$options->setFormat(ACore::FORMAT_LOCAL); $options->setFormat(ACore::FORMAT_LOCAL);
$options->setTimeline(TimelineOptions::TIMELINE_ACCOUNT) $options->setProbe(ProbeOptions::ACCOUNT)
->setAccountId($local->getId()) ->setAccountId($local->getId())
->setLimit($limit) ->setLimit($limit)
->setMaxId($max_id) ->setMaxId($max_id)
@ -537,6 +552,77 @@ class ApiController extends Controller {
} }
/**
* @NoCSRFRequired
* @PublicPage
*
* @param string $account
*
* @return DataResponse
*/
public function accountFollowing(
string $account,
int $limit = 20,
int $max_id = 0,
int $min_id = 0,
int $since = 0
): DataResponse {
try {
$this->initViewer(true);
$local = $this->cacheActorService->getFromLocalAccount($account);
$options = new ProbeOptions($this->request);
$options->setFormat(ACore::FORMAT_LOCAL);
$options->setProbe(ProbeOptions::FOLLOWING)
->setAccountId($local->getId())
->setLimit($limit)
->setMaxId($max_id)
->setMinId($min_id)
->setSince($since);
return new DataResponse($this->cacheActorService->probeActors($options), Http::STATUS_OK);
} catch (Exception $e) {
return $this->error($e->getMessage());
}
}
/**
* @NoCSRFRequired
* @PublicPage
*
* @param string $account
*
* @return DataResponse
*/
public function accountFollowers(
string $account,
int $limit = 20,
int $max_id = 0,
int $min_id = 0,
int $since = 0
): DataResponse {
try {
$this->initViewer(true);
$local = $this->cacheActorService->getFromLocalAccount($account);
$options = new ProbeOptions($this->request);
$options->setFormat(ACore::FORMAT_LOCAL);
$options->setProbe(ProbeOptions::FOLLOWERS)
->setAccountId($local->getId())
->setLimit($limit)
->setMaxId($max_id)
->setMinId($min_id)
->setSince($since);
return new DataResponse($this->cacheActorService->probeActors($options), Http::STATUS_OK);
} catch (Exception $e) {
return $this->error($e->getMessage());
}
}
/** /**
* @NoCSRFRequired * @NoCSRFRequired
* @PublicPage * @PublicPage
@ -557,9 +643,9 @@ class ApiController extends Controller {
try { try {
$this->initViewer(true); $this->initViewer(true);
$options = new TimelineOptions($this->request); $options = new ProbeOptions($this->request);
$options->setFormat(ACore::FORMAT_LOCAL); $options->setFormat(ACore::FORMAT_LOCAL);
$options->setTimeline(TimelineOptions::TIMELINE_FAVOURITES) $options->setProbe(ProbeOptions::FAVOURITES)
->setLimit($limit) ->setLimit($limit)
->setMaxId($max_id) ->setMaxId($max_id)
->setMinId($min_id) ->setMinId($min_id)
@ -592,9 +678,9 @@ class ApiController extends Controller {
try { try {
$this->initViewer(true); $this->initViewer(true);
$options = new TimelineOptions($this->request); $options = new ProbeOptions($this->request);
$options->setFormat(ACore::FORMAT_LOCAL); $options->setFormat(ACore::FORMAT_LOCAL);
$options->setTimeline(TimelineOptions::TIMELINE_NOTIFICATIONS) $options->setProbe(ProbeOptions::NOTIFICATIONS)
->setLimit($limit) ->setLimit($limit)
->setMaxId($max_id) ->setMaxId($max_id)
->setMinId($min_id) ->setMinId($min_id)
@ -630,9 +716,9 @@ class ApiController extends Controller {
try { try {
$this->initViewer(true); $this->initViewer(true);
$options = new TimelineOptions($this->request); $options = new ProbeOptions($this->request);
$options->setFormat(ACore::FORMAT_LOCAL); $options->setFormat(ACore::FORMAT_LOCAL);
$options->setTimeline('hashtag') $options->setProbe('hashtag')
->setLimit($limit) ->setLimit($limit)
->setMaxId($max_id) ->setMaxId($max_id)
->setMinId($min_id) ->setMinId($min_id)

Wyświetl plik

@ -34,6 +34,8 @@ use DateTime;
use Exception; use Exception;
use OCA\Social\Exceptions\CacheActorDoesNotExistException; use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCA\Social\Model\Client\Options\ProbeOptions;
use OCP\DB\Exception as DBException; use OCP\DB\Exception as DBException;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
@ -262,4 +264,85 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
return $inbox; return $inbox;
} }
/**
* @param ProbeOptions $options
*
* @return Person[]
*/
public function probeActors(ProbeOptions $options): array {
switch (strtolower($options->getProbe())) {
case ProbeOptions::FOLLOWING:
$result = $this->probeActorsFollowing($options);
break;
case ProbeOptions::FOLLOWERS:
$result = $this->probeActorsFollowers($options);
break;
default:
return [];
}
if ($options->isInverted()) {
// in case we inverted the order during the request, we revert the results
$result = array_reverse($result);
}
return $result;
}
/**
* @param ProbeOptions $options
*
* @return Person[]
*/
public function probeActorsFollowing(ProbeOptions $options): array {
$qb = $this->getCacheActorsSelectSql($options->getFormat());
$qb->paginate($options);
$qb->leftJoin(
$qb->getDefaultSelectAlias(),
CoreRequestBuilder::TABLE_FOLLOWS,
'ca_f',
// object_id of follow is equal to actor's id
$qb->expr()->eq('ca.id_prim', 'ca_f.object_id_prim')
);
// follow must be accepted
$qb->limitToType(Follow::TYPE, 'ca_f');
$qb->limitToAccepted(true, 'ca_f');
// actor_id of follow is equal to requested account
$qb->limitToActorIdPrim($qb->prim($options->getAccountId()), 'ca_f');
return $this->getCacheActorsFromRequest($qb);
}
/**
* @param ProbeOptions $options
*
* @return Person[]
*/
public function probeActorsFollowers(ProbeOptions $options): array {
$qb = $this->getCacheActorsSelectSql($options->getFormat());
$qb->paginate($options);
$qb->leftJoin(
$qb->getDefaultSelectAlias(),
CoreRequestBuilder::TABLE_FOLLOWS,
'ca_f',
// actor_id of follow is equal to actor's id
$qb->expr()->eq('ca.id_prim', 'ca_f.actor_id_prim')
);
// follow must be accepted
$qb->limitToType(Follow::TYPE, 'ca_f');
$qb->limitToAccepted(true, 'ca_f');
// object_id of follow is equal to requested account
$qb->limitToObjectIdPrim($qb->prim($options->getAccountId()), 'ca_f');
return $this->getCacheActorsFromRequest($qb);
}
} }

Wyświetl plik

@ -30,11 +30,12 @@ declare(strict_types=1);
namespace OCA\Social\Db; namespace OCA\Social\Db;
use OCA\Social\Tools\Exceptions\RowNotFoundException;
use OCA\Social\Tools\Traits\TArrayTools;
use OCA\Social\Exceptions\CacheActorDoesNotExistException; use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Tools\Exceptions\RowNotFoundException;
use OCA\Social\Tools\Traits\TArrayTools;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
class CacheActorsRequestBuilder extends CoreRequestBuilder { class CacheActorsRequestBuilder extends CoreRequestBuilder {
@ -72,14 +73,15 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
* *
* @return SocialQueryBuilder * @return SocialQueryBuilder
*/ */
protected function getCacheActorsSelectSql(): SocialQueryBuilder { protected function getCacheActorsSelectSql(int $format = Stream::FORMAT_ACTIVITYPUB): SocialQueryBuilder {
$qb = $this->getQueryBuilder(); $qb = $this->getQueryBuilder();
$qb->setFormat($format);
/** @noinspection PhpMethodParametersCountMismatchInspection */ /** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->select( $qb->select(
'ca.id', 'ca.account', 'ca.following', 'ca.followers', 'ca.inbox', 'ca.shared_inbox', 'ca.nid', 'ca.id', 'ca.account', 'ca.following', 'ca.followers', 'ca.inbox',
'ca.outbox', 'ca.featured', 'ca.url', 'ca.type', 'ca.preferred_username', 'ca.name', 'ca.summary', 'ca.shared_inbox', 'ca.outbox', 'ca.featured', 'ca.url', 'ca.type', 'ca.preferred_username',
'ca.public_key', 'ca.local', 'ca.details', 'ca.source', 'ca.creation' 'ca.name', 'ca.summary', 'ca.public_key', 'ca.local', 'ca.details', 'ca.source', 'ca.creation'
) )
->from(self::TABLE_CACHE_ACTORS, 'ca'); ->from(self::TABLE_CACHE_ACTORS, 'ca');
@ -87,7 +89,6 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
/** @deprecated */ /** @deprecated */
$this->defaultSelectAlias = 'ca'; $this->defaultSelectAlias = 'ca';
$qb->setDefaultSelectAlias('ca');
return $qb; return $qb;
} }

Wyświetl plik

@ -217,7 +217,7 @@ class FollowsRequest extends FollowsRequestBuilder {
*/ */
public function getFollowersByActorId(string $actorId): array { public function getFollowersByActorId(string $actorId): array {
$qb = $this->getFollowsSelectSql(); $qb = $this->getFollowsSelectSql();
$this->limitToOBjectId($qb, $actorId); $this->limitToObjectId($qb, $actorId);
$this->limitToAccepted($qb, true); $this->limitToAccepted($qb, true);
$this->leftJoinCacheActors($qb, 'actor_id'); $this->leftJoinCacheActors($qb, 'actor_id');
$this->leftJoinDetails($qb, 'id', 'ca'); $this->leftJoinDetails($qb, 'id', 'ca');

Wyświetl plik

@ -36,7 +36,7 @@ use DateInterval;
use DateTime; use DateTime;
use Exception; use Exception;
use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\Client\Options\TimelineOptions; use OCA\Social\Model\Client\Options\ProbeOptions;
use OCP\DB\QueryBuilder\ICompositeExpression; use OCP\DB\QueryBuilder\ICompositeExpression;
/** /**
@ -45,15 +45,8 @@ use OCP\DB\QueryBuilder\ICompositeExpression;
* @package OCA\Social\Db * @package OCA\Social\Db
*/ */
class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder { class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
/** public function limitToType(string $type, string $alias = ''): self {
* Limit the request to the Type $this->limitToDBField('type', $type, true, $alias);
*
* @param string $type
*
* @return SocialQueryBuilder
*/
public function limitToType(string $type): self {
$this->limitToDBField('type', $type, true);
return $this; return $this;
} }
@ -328,10 +321,10 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
/** /**
* @param TimelineOptions $options * @param ProbeOptions $options
* *
*/ */
public function paginate(TimelineOptions $options) { public function paginate(ProbeOptions $options) {
$expr = $this->expr(); $expr = $this->expr();
$pf = $this->getDefaultSelectAlias(); $pf = $this->getDefaultSelectAlias();

Wyświetl plik

@ -39,7 +39,7 @@ use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
use OCA\Social\Model\ActivityPub\Object\Document; use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Note; use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream; use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\Client\Options\TimelineOptions; use OCA\Social\Model\Client\Options\ProbeOptions;
use OCA\Social\Service\ConfigService; use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService; use OCA\Social\Service\MiscService;
use OCA\Social\Tools\Exceptions\DateTimeException; use OCA\Social\Tools\Exceptions\DateTimeException;
@ -376,32 +376,32 @@ class StreamRequest extends StreamRequestBuilder {
} }
/** /**
* @param TimelineOptions $options * @param ProbeOptions $options
* *
* @return Stream[] * @return Stream[]
*/ */
public function getTimeline(TimelineOptions $options): array { public function getTimeline(ProbeOptions $options): array {
switch (strtolower($options->getTimeline())) { switch (strtolower($options->getProbe())) {
case TimelineOptions::TIMELINE_ACCOUNT: case ProbeOptions::ACCOUNT:
$result = $this->getTimelineAccount($options); $result = $this->getTimelineAccount($options);
break; break;
case TimelineOptions::TIMELINE_HOME: case ProbeOptions::HOME:
$result = $this->getTimelineHome($options); $result = $this->getTimelineHome($options);
break; break;
case TimelineOptions::TIMELINE_DIRECT: case ProbeOptions::DIRECT:
$result = $this->getTimelineDirect($options); $result = $this->getTimelineDirect($options);
break; break;
case TimelineOptions::TIMELINE_FAVOURITES: case ProbeOptions::FAVOURITES:
$result = $this->getTimelineFavourites($options); $result = $this->getTimelineFavourites($options);
break; break;
case TimelineOptions::TIMELINE_HASHTAG: case ProbeOptions::HASHTAG:
$result = $this->getTimelineHashtag($options, $options->getArgument()); $result = $this->getTimelineHashtag($options, $options->getArgument());
break; break;
case TimelineOptions::TIMELINE_NOTIFICATIONS: case ProbeOptions::NOTIFICATIONS:
$options->setFormat(ACore::FORMAT_NOTIFICATION); $options->setFormat(ACore::FORMAT_NOTIFICATION);
$result = $this->getTimelineNotifications($options); $result = $this->getTimelineNotifications($options);
break; break;
case TimelineOptions::TIMELINE_PUBLIC: case ProbeOptions::PUBLIC:
$result = $this->getTimelinePublic($options); $result = $this->getTimelinePublic($options);
break; break;
default: default:
@ -409,7 +409,7 @@ class StreamRequest extends StreamRequestBuilder {
} }
if ($options->isInverted()) { if ($options->isInverted()) {
// in cae we inverted the order during the request, we revert the results // in case we inverted the order during the request, we revert the results
$result = array_reverse($result); $result = array_reverse($result);
} }
@ -421,11 +421,11 @@ class StreamRequest extends StreamRequestBuilder {
* * Own posts, * * Own posts,
* * Followed accounts * * Followed accounts
* *
* @param TimelineOptions $options * @param ProbeOptions $options
* *
* @return Stream[] * @return Stream[]
*/ */
private function getTimelineHome(TimelineOptions $options): array { private function getTimelineHome(ProbeOptions $options): array {
$qb = $this->getStreamSelectSql($options->getFormat()); $qb = $this->getStreamSelectSql($options->getFormat());
$qb->filterType(SocialAppNotification::TYPE); $qb->filterType(SocialAppNotification::TYPE);
@ -446,11 +446,11 @@ class StreamRequest extends StreamRequestBuilder {
* * Private message. * * Private message.
* - group messages. (not yet) * - group messages. (not yet)
* *
* @param TimelineOptions $options * @param ProbeOptions $options
* *
* @return Stream[] * @return Stream[]
*/ */
private function getTimelineDirect(TimelineOptions $options): array { private function getTimelineDirect(ProbeOptions $options): array {
$qb = $this->getStreamSelectSql(); $qb = $this->getStreamSelectSql();
$qb->filterType(SocialAppNotification::TYPE); $qb->filterType(SocialAppNotification::TYPE);
@ -471,11 +471,11 @@ class StreamRequest extends StreamRequestBuilder {
* - public message from actorId. * - public message from actorId.
* - followers-only if logged and follower. * - followers-only if logged and follower.
* *
* @param TimelineOptions $options * @param ProbeOptions $options
* *
* @return Stream[] * @return Stream[]
*/ */
private function getTimelineAccount(TimelineOptions $options): array { private function getTimelineAccount(ProbeOptions $options): array {
$qb = $this->getStreamSelectSql(); $qb = $this->getStreamSelectSql();
$qb->filterType(SocialAppNotification::TYPE); $qb->filterType(SocialAppNotification::TYPE);
@ -501,11 +501,11 @@ class StreamRequest extends StreamRequestBuilder {
/** /**
* @param TimelineOptions $options * @param ProbeOptions $options
* *
* @return Stream[] * @return Stream[]
*/ */
private function getTimelineFavourites(TimelineOptions $options): array { private function getTimelineFavourites(ProbeOptions $options): array {
$qb = $this->getStreamSelectSql($options->getFormat()); $qb = $this->getStreamSelectSql($options->getFormat());
$actor = $qb->getViewer(); $actor = $qb->getViewer();
$expr = $qb->expr(); $expr = $qb->expr();
@ -524,11 +524,11 @@ class StreamRequest extends StreamRequestBuilder {
/** /**
* @param TimelineOptions $options * @param ProbeOptions $options
* *
* @return Stream[] * @return Stream[]
*/ */
private function getTimelineHashtag(TimelineOptions $options, string $hashtag): array { private function getTimelineHashtag(ProbeOptions $options, string $hashtag): array {
$qb = $this->getStreamSelectSql($options->getFormat()); $qb = $this->getStreamSelectSql($options->getFormat());
return []; return [];
@ -538,11 +538,11 @@ class StreamRequest extends StreamRequestBuilder {
/** /**
* @param TimelineOptions $options * @param ProbeOptions $options
* *
* @return Stream[] * @return Stream[]
*/ */
private function getTimelineNotifications(TimelineOptions $options): array { private function getTimelineNotifications(ProbeOptions $options): array {
$qb = $this->getStreamSelectSql($options->getFormat()); $qb = $this->getStreamSelectSql($options->getFormat());
$actor = $qb->getViewer(); $actor = $qb->getViewer();
@ -682,11 +682,11 @@ class StreamRequest extends StreamRequestBuilder {
* Should return: * Should return:
* * All local public/federated posts * * All local public/federated posts
* *
* @param TimelineOptions $options * @param ProbeOptions $options
* *
* @return Stream[] * @return Stream[]
*/ */
private function getTimelinePublic(TimelineOptions $options): array { private function getTimelinePublic(ProbeOptions $options): array {
$qb = $this->getStreamSelectSql($options->getFormat()); $qb = $this->getStreamSelectSql($options->getFormat());
$qb->paginate($options); $qb->paginate($options);

Wyświetl plik

@ -31,5 +31,5 @@ namespace OCA\Social\Exceptions;
use Exception; use Exception;
class UnknownTimelineException extends Exception { class UnknownProbeException extends Exception {
} }

Wyświetl plik

@ -746,6 +746,15 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
} }
$table = $schema->createTable('social_cache_actor'); $table = $schema->createTable('social_cache_actor');
$table->addColumn(
'nid', Types::BIGINT,
[
'autoincrement' => true,
'notnull' => true,
'length' => 14,
'unsigned' => true,
]
);
$table->addColumn( $table->addColumn(
'id', Types::TEXT, 'id', Types::TEXT,
[ [
@ -888,7 +897,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
] ]
); );
$table->setPrimaryKey(['id_prim']); $table->setPrimaryKey(['nid']);
$table->addUniqueIndex(['id_prim']); $table->addUniqueIndex(['id_prim']);
} }

Wyświetl plik

@ -47,6 +47,14 @@ class Version1000Date20230217000001 extends SimpleMigrationStep {
} }
} }
if ($schema->hasTable('social_cache_actor')) {
$table = $schema->getTable('social_cache_actor');
if (!$table->hasColumn('nid')) {
$table->dropPrimaryKey();
}
}
return $schema; return $schema;
} }
} }

Wyświetl plik

@ -55,6 +55,26 @@ class Version1000Date20230217000002 extends SimpleMigrationStep {
} }
} }
// fix nid as primary on social_cache_actor
if ($schema->hasTable('social_cache_actor')) {
$table = $schema->getTable('social_cache_actor');
if (!$table->hasColumn('nid')) {
$table->addColumn(
'nid', Types::BIGINT,
[
'autoincrement' => true,
'notnull' => true,
'length' => 14,
'unsigned' => true,
]
);
$table->setPrimaryKey(['nid']);
}
}
if ($schema->hasTable('social_cache_doc')) { if ($schema->hasTable('social_cache_doc')) {
$table = $schema->getTable('social_cache_doc'); $table = $schema->getTable('social_cache_doc');

Wyświetl plik

@ -32,27 +32,29 @@ declare(strict_types=1);
namespace OCA\Social\Model\Client\Options; namespace OCA\Social\Model\Client\Options;
use JsonSerializable; use JsonSerializable;
use OCA\Social\Exceptions\UnknownTimelineException;
use OCA\Social\Tools\Traits\TArrayTools; use OCA\Social\Tools\Traits\TArrayTools;
use OCP\IRequest; use OCP\IRequest;
/** /**
* Class TimelineOptions * Class ProbeOptions
* *
* @package OCA\Social\Model\Client\Options * @package OCA\Social\Model\Client\Options
*/ */
class TimelineOptions extends CoreOptions implements JsonSerializable { class ProbeOptions extends CoreOptions implements JsonSerializable {
use TArrayTools; use TArrayTools;
public const TIMELINE_HOME = 'home'; public const HOME = 'home';
public const TIMELINE_PUBLIC = 'public'; public const PUBLIC = 'public';
public const TIMELINE_DIRECT = 'direct'; public const DIRECT = 'direct';
public const TIMELINE_ACCOUNT = 'account'; public const ACCOUNT = 'account';
public const TIMELINE_FAVOURITES = 'favourites'; public const FAVOURITES = 'favourites';
public const TIMELINE_HASHTAG = 'hashtag'; public const HASHTAG = 'hashtag';
public const TIMELINE_NOTIFICATIONS = 'notifications'; public const NOTIFICATIONS = 'notifications';
private string $timeline = ''; public const FOLLOWERS = 'followers';
public const FOLLOWING = 'following';
private string $probe = '';
private bool $local = false; private bool $local = false;
private bool $remote = false; private bool $remote = false;
private bool $onlyMedia = false; private bool $onlyMedia = false;
@ -66,17 +68,9 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
private array $excludeTypes = []; private array $excludeTypes = [];
private string $accountId = ''; private string $accountId = '';
public static array $availableTimelines = [
self::TIMELINE_HOME,
self::TIMELINE_ACCOUNT,
self::TIMELINE_PUBLIC,
self::TIMELINE_DIRECT,
self::TIMELINE_FAVOURITES,
self::TIMELINE_NOTIFICATIONS
];
/** /**
* TimelineOptions constructor. * ProbeOptions constructor.
* *
* @param IRequest|null $request * @param IRequest|null $request
*/ */
@ -90,25 +84,17 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @return string * @return string
*/ */
public function getTimeline(): string { public function getProbe(): string {
return $this->timeline; return $this->probe;
} }
/** /**
* @param string $timeline * @param string $probe
* *
* @return TimelineOptions * @return ProbeOptions
* @throws UnknownTimelineException
*/ */
public function setTimeline(string $timeline): self { public function setProbe(string $probe): self {
$timeline = strtolower($timeline); $this->probe = strtolower($probe);
if (!in_array($timeline, self::$availableTimelines)) {
throw new UnknownTimelineException(
'unknown timeline: ' . implode(', ', self::$availableTimelines)
);
}
$this->timeline = $timeline;
return $this; return $this;
} }
@ -124,7 +110,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param bool $local * @param bool $local
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setLocal(bool $local): self { public function setLocal(bool $local): self {
$this->local = $local; $this->local = $local;
@ -143,7 +129,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param bool $remote * @param bool $remote
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setRemote(bool $remote): self { public function setRemote(bool $remote): self {
$this->remote = $remote; $this->remote = $remote;
@ -162,7 +148,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param bool $onlyMedia * @param bool $onlyMedia
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setOnlyMedia(bool $onlyMedia): self { public function setOnlyMedia(bool $onlyMedia): self {
$this->onlyMedia = $onlyMedia; $this->onlyMedia = $onlyMedia;
@ -181,7 +167,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param int $minId * @param int $minId
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setMinId(int $minId): self { public function setMinId(int $minId): self {
$this->minId = $minId; $this->minId = $minId;
@ -200,7 +186,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param int $maxId * @param int $maxId
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setMaxId(int $maxId): self { public function setMaxId(int $maxId): self {
$this->maxId = $maxId; $this->maxId = $maxId;
@ -219,7 +205,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param int $since * @param int $since
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setSince(int $since): self { public function setSince(int $since): self {
$this->since = $since; $this->since = $since;
@ -238,7 +224,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param int $limit * @param int $limit
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setLimit(int $limit): self { public function setLimit(int $limit): self {
$this->limit = $limit; $this->limit = $limit;
@ -257,7 +243,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param bool $inverted * @param bool $inverted
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setInverted(bool $inverted): self { public function setInverted(bool $inverted): self {
$this->inverted = $inverted; $this->inverted = $inverted;
@ -269,7 +255,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param string $argument * @param string $argument
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setArgument(string $argument): self { public function setArgument(string $argument): self {
$this->argument = $argument; $this->argument = $argument;
@ -288,7 +274,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param array $types * @param array $types
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setTypes(array $types): self { public function setTypes(array $types): self {
$this->types = $types; $this->types = $types;
@ -307,7 +293,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param array $excludeTypes * @param array $excludeTypes
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setExcludeTypes(array $excludeTypes): self { public function setExcludeTypes(array $excludeTypes): self {
$this->excludeTypes = $excludeTypes; $this->excludeTypes = $excludeTypes;
@ -326,7 +312,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param string $accountId * @param string $accountId
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function setAccountId(string $accountId): self { public function setAccountId(string $accountId): self {
$this->accountId = $accountId; $this->accountId = $accountId;
@ -346,7 +332,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
/** /**
* @param array $arr * @param array $arr
* *
* @return TimelineOptions * @return ProbeOptions
*/ */
public function fromArray(array $arr): self { public function fromArray(array $arr): self {
$this->setLocal($this->getBool('local', $arr, $this->isLocal())); $this->setLocal($this->getBool('local', $arr, $this->isLocal()));
@ -368,7 +354,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
public function jsonSerialize(): array { public function jsonSerialize(): array {
return return
[ [
'timeline' => $this->getTimeline(), 'probe' => $this->getProbe(),
'accountId' => $this->getAccountId(), 'accountId' => $this->getAccountId(),
'local' => $this->isLocal(), 'local' => $this->isLocal(),
'remote' => $this->isRemote(), 'remote' => $this->isRemote(),

Wyświetl plik

@ -44,6 +44,7 @@ use OCA\Social\Exceptions\RetrieveAccountFormatException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnauthorizedFediverseException; use OCA\Social\Exceptions\UnauthorizedFediverseException;
use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\Client\Options\ProbeOptions;
use OCA\Social\Tools\Exceptions\MalformedArrayException; use OCA\Social\Tools\Exceptions\MalformedArrayException;
use OCA\Social\Tools\Exceptions\RequestContentException; use OCA\Social\Tools\Exceptions\RequestContentException;
use OCA\Social\Tools\Exceptions\RequestNetworkException; use OCA\Social\Tools\Exceptions\RequestNetworkException;
@ -327,4 +328,14 @@ class CacheActorService {
} catch (ItemUnknownException $e) { } catch (ItemUnknownException $e) {
} }
} }
/**
* @param ProbeOptions $options
*
* @return Person[]
*/
public function probeActors(ProbeOptions $options): array {
return $this->cacheActorsRequest->probeActors($options);
}
} }

Wyświetl plik

@ -43,7 +43,7 @@ use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Note; use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream; use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\Client\Options\TimelineOptions; use OCA\Social\Model\Client\Options\ProbeOptions;
use OCA\Social\Model\InstancePath; use OCA\Social\Model\InstancePath;
use OCA\Social\Tools\Exceptions\DateTimeException; use OCA\Social\Tools\Exceptions\DateTimeException;
use OCA\Social\Tools\Exceptions\MalformedArrayException; use OCA\Social\Tools\Exceptions\MalformedArrayException;
@ -405,11 +405,11 @@ class StreamService {
/** /**
* @param TimelineOptions $options * @param ProbeOptions $options
* *
* @return Note[] * @return Note[]
*/ */
public function getTimeline(TimelineOptions $options): array { public function getTimeline(ProbeOptions $options): array {
return $this->streamRequest->getTimeline($options); return $this->streamRequest->getTimeline($options);
} }