account statuses

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/1583/head
Maxence Lange 2023-01-16 15:19:26 -01:00
rodzic f56e326f80
commit 0974fff12c
6 zmienionych plików z 105 dodań i 29 usunięć

Wyświetl plik

@ -83,6 +83,7 @@ return [
['name' => 'Api#notifications', 'url' => '/api/v1/notifications', 'verb' => 'GET'],
['name' => 'Api#tag', 'url' => '/api/v1/timelines/tag/{hashtag}', 'verb' => 'GET'],
['name' => 'Api#statusNew', 'url' => '/api/v1/statuses', 'verb' => 'POST'],
['name' => 'Api#accountStatuses', 'url' => '/api/v1/accounts/{account}/statuses', 'verb' => 'GET'],
// Api for local front-end
// TODO: front-end should be using the new ApiController

Wyświetl plik

@ -36,6 +36,7 @@ use OCA\Social\Db\StreamRequest;
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\ConfigService;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
@ -53,6 +54,7 @@ class Timeline extends ExtendedBase {
private IUserManager $userManager;
private StreamRequest $streamRequest;
private AccountService $accountService;
private CacheActorService $cacheActorService;
private ConfigService $configService;
private ?int $count = null;
@ -70,6 +72,7 @@ class Timeline extends ExtendedBase {
IUserManager $userManager,
StreamRequest $streamRequest,
AccountService $accountService,
CacheActorService $cacheActorService,
ConfigService $configService
) {
parent::__construct();
@ -77,6 +80,7 @@ class Timeline extends ExtendedBase {
$this->userManager = $userManager;
$this->streamRequest = $streamRequest;
$this->accountService = $accountService;
$this->cacheActorService = $cacheActorService;
$this->configService = $configService;
}
@ -94,6 +98,7 @@ class Timeline extends ExtendedBase {
->addOption('max_id', '', InputOption::VALUE_REQUIRED, 'max_id', 0)
->addOption('since', '', InputOption::VALUE_REQUIRED, 'since', 0)
->addOption('limit', '', InputOption::VALUE_REQUIRED, 'limit', 5)
->addOption('account', '', InputOption::VALUE_REQUIRED, 'account', '')
->addOption('crop', '', InputOption::VALUE_REQUIRED, 'crop', 0)
->setDescription('Get stream by timeline and viewer');
}
@ -136,6 +141,12 @@ class Timeline extends ExtendedBase {
$options->setLocal(true);
}
$options->setTimeline($input->getArgument('timeline'));
if ($input->getOption('account') !== '') {
$local = $this->cacheActorService->getFromLocalAccount($input->getOption('account'));
$options->setAccountId($local->getId());
}
$this->outputStreams($this->streamRequest->getTimeline($options));
return 0;

Wyświetl plik

@ -280,6 +280,47 @@ class ApiController extends Controller {
}
/**
* @NoCSRFRequired
* @PublicPage
*
* @param string $account
* @param int $limit
* @param int $max_id
* @param int $min_id
*
* @return DataResponse
*/
public function accountStatuses(
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 TimelineOptions($this->request);
$options->setFormat(ACore::FORMAT_LOCAL);
$options->setTimeline(TimelineOptions::TIMELINE_ACCOUNT)
->setAccountId($local->getId())
->setLimit($limit)
->setMaxId($max_id)
->setMinId($min_id)
->setSince($since);
$posts = $this->streamService->getTimeline($options);
return new DataResponse($posts, Http::STATUS_OK);
} catch (Exception $e) {
return $this->error($e->getMessage());
}
}
/**
* @NoCSRFRequired
* @PublicPage

Wyświetl plik

@ -362,6 +362,9 @@ class StreamRequest extends StreamRequestBuilder {
*/
public function getTimeline(TimelineOptions $options): array {
switch (strtolower($options->getTimeline())) {
case TimelineOptions::TIMELINE_ACCOUNT:
$result = $this->getTimelineAccount($options);
break;
case TimelineOptions::TIMELINE_HOME:
$result = $this->getTimelineHome($options);
break;
@ -443,6 +446,43 @@ class StreamRequest extends StreamRequestBuilder {
}
/**
* Should returns:
* - public message from actorId.
* - followers-only if logged and follower.
*
* @param TimelineOptions $options
*
* @return Stream[]
*/
private function getTimelineAccount(TimelineOptions $options): array {
$qb = $this->getStreamSelectSql();
$qb->filterType(SocialAppNotification::TYPE);
$qb->paginate($options);
$actorId = $options->getAccountId();
if ($actorId === '') {
return [];
}
$qb->limitToAttributedTo($actorId, true);
$qb->selectDestFollowing('sd', '');
$qb->innerJoinStreamDest('recipient', 'id_prim', 'sd', 's');
$accountIsViewer = ($qb->hasViewer() && $qb->getViewer()->getId() === $actorId);
$qb->limitToDest($accountIsViewer ? '' : ACore::CONTEXT_PUBLIC, 'recipient', '', 'sd');
$qb->linkToCacheActors('ca', 's.attributed_to_prim');
$qb->leftJoinStreamAction();
return $this->getStreamsFromRequest($qb);
}
/**
* @param TimelineOptions $options
*
@ -577,7 +617,7 @@ class StreamRequest extends StreamRequestBuilder {
* @return Stream[]
* @throws DateTimeException
*/
public function getTimelineAccount(string $actorId, int $since = 0, int $limit = 5): array {
public function getTimelineAccount_dep(string $actorId, int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
$qb->limitPaginate($since, $limit);

Wyświetl plik

@ -47,6 +47,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
public const TIMELINE_HOME = 'home';
public const TIMELINE_PUBLIC = 'public';
public const TIMELINE_DIRECT = 'direct';
public const TIMELINE_ACCOUNT = 'account';
public const TIMELINE_FAVOURITES = 'favourites';
public const TIMELINE_HASHTAG = 'hashtag';
public const TIMELINE_NOTIFICATIONS = 'notifications';
@ -67,6 +68,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
public static array $availableTimelines = [
self::TIMELINE_HOME,
self::TIMELINE_ACCOUNT,
self::TIMELINE_PUBLIC,
self::TIMELINE_DIRECT,
self::TIMELINE_FAVOURITES,
@ -349,7 +351,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
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->setOnlyMedia($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->setSince($this->getInt('since', $arr, $this->getSince()));
@ -367,6 +369,7 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
return
[
'timeline' => $this->getTimeline(),
'accountId' => $this->getAccountId(),
'local' => $this->isLocal(),
'remote' => $this->isRemote(),
'only_media' => $this->isOnlyMedia(),

Wyświetl plik

@ -55,49 +55,31 @@ use OCA\Social\Tools\Exceptions\RequestResultSizeException;
use OCA\Social\Tools\Exceptions\RequestServerException;
class StreamService {
private StreamRequest $streamRequest;
private ActivityService $activityService;
private AccountService $accountService;
private SignatureService $signatureService;
private StreamQueueService $streamQueueService;
private CacheActorService $cacheActorService;
private ConfigService $configService;
private MiscService $miscService;
/**
* NoteService constructor.
*
* @param StreamRequest $streamRequest
* @param ActivityService $activityService
* @param AccountService $accountService
* @param SignatureService $signatureService
* @param StreamQueueService $streamQueueService
* @param CacheActorService $cacheActorService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
StreamRequest $streamRequest, ActivityService $activityService,
AccountService $accountService, SignatureService $signatureService,
StreamQueueService $streamQueueService, CacheActorService $cacheActorService,
ConfigService $configService, MiscService $miscService
StreamRequest $streamRequest,
ActivityService $activityService,
CacheActorService $cacheActorService,
ConfigService $configService
) {
$this->streamRequest = $streamRequest;
$this->activityService = $activityService;
$this->accountService = $accountService;
$this->signatureService = $signatureService;
$this->streamQueueService = $streamQueueService;
$this->cacheActorService = $cacheActorService;
$this->configService = $configService;
$this->miscService = $miscService;
}
@ -268,9 +250,7 @@ class StreamService {
$note->addTag(
[
'type' => 'Hashtag',
'href' => $this->configService->getSocialUrl() . 'tag/' . strtolower(
$hashtag
),
'href' => $this->configService->getSocialUrl() . 'tag/' . strtolower($hashtag),
'name' => '#' . $hashtag
]
);
@ -445,7 +425,7 @@ class StreamService {
* @deprecated
*/
public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array {
return $this->streamRequest->getTimelineAccount($actorId, $since, $limit);
return $this->streamRequest->getTimelineAccount_dep($actorId, $since, $limit);
}