kopia lustrzana https://github.com/nextcloud/social
basic implementation of collections
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/1720/head
rodzic
961f8c021e
commit
8a7e941726
|
@ -278,7 +278,17 @@ class ActivityPubController extends Controller {
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function outbox(string $username): Response {
|
public function outbox(string $username): Response {
|
||||||
return $this->success([$username]);
|
// if (!$this->checkSourceActivityStreams()) {
|
||||||
|
// return $this->socialPubController->outbox($username);
|
||||||
|
// }
|
||||||
|
|
||||||
|
try {
|
||||||
|
$actor = $this->cacheActorService->getFromLocalAccount($username);
|
||||||
|
|
||||||
|
return $this->directSuccess($this->streamService->getOutboxCollection($actor));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $this->fail($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -301,11 +311,8 @@ class ActivityPubController extends Controller {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$actor = $this->cacheActorService->getFromLocalAccount($username);
|
$actor = $this->cacheActorService->getFromLocalAccount($username);
|
||||||
$followers = $this->followService->getFollowersCollection($actor);
|
|
||||||
|
|
||||||
// $followers->setTopLevel(true);
|
return $this->directSuccess($this->followService->getFollowersCollection($actor));
|
||||||
|
|
||||||
return $this->directSuccess($followers);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->fail($e);
|
return $this->fail($e);
|
||||||
}
|
}
|
||||||
|
@ -329,7 +336,13 @@ class ActivityPubController extends Controller {
|
||||||
return $this->socialPubController->following($username);
|
return $this->socialPubController->following($username);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->success([$username]);
|
try {
|
||||||
|
$actor = $this->cacheActorService->getFromLocalAccount($username);
|
||||||
|
|
||||||
|
return $this->directSuccess($this->followService->getFollowingCollection($actor));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $this->fail($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,8 @@ class FollowsRequest extends FollowsRequestBuilder {
|
||||||
$this->leftJoinDetails($qb, 'id', 'ca');
|
$this->leftJoinDetails($qb, 'id', 'ca');
|
||||||
$qb->orderBy('f.creation', 'desc');
|
$qb->orderBy('f.creation', 'desc');
|
||||||
|
|
||||||
|
// TODO: pagination
|
||||||
|
|
||||||
return $this->getFollowsFromRequest($qb);
|
return $this->getFollowsFromRequest($qb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nextcloud - Social Support
|
* Nextcloud - Social Support
|
||||||
*
|
*
|
||||||
|
@ -28,103 +27,69 @@ declare(strict_types=1);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace OCA\Social\Model\ActivityPub;
|
namespace OCA\Social\Model\ActivityPub;
|
||||||
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
|
||||||
/**
|
|
||||||
* Class OrderedCollection
|
|
||||||
*
|
|
||||||
* @package OCA\Social\Model\ActivityPub
|
|
||||||
*/
|
|
||||||
class OrderedCollection extends ACore implements JsonSerializable {
|
class OrderedCollection extends ACore implements JsonSerializable {
|
||||||
public const TYPE = 'OrderedCollection';
|
public const TYPE = 'OrderedCollection';
|
||||||
|
|
||||||
|
|
||||||
private int $totalItems = 0;
|
private int $totalItems = 0;
|
||||||
|
|
||||||
private string $first = '';
|
private string $first = '';
|
||||||
|
private string $last = '';
|
||||||
|
|
||||||
/**
|
|
||||||
* Activity constructor.
|
|
||||||
*
|
|
||||||
* @param ACore $parent
|
|
||||||
*/
|
|
||||||
public function __construct($parent = null) {
|
public function __construct($parent = null) {
|
||||||
parent::__construct($parent);
|
parent::__construct($parent);
|
||||||
|
|
||||||
$this->setType(self::TYPE);
|
$this->setType(self::TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getTotalItems(): int {
|
public function getTotalItems(): int {
|
||||||
return $this->totalItems;
|
return $this->totalItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setTotalItems(int $totalItems): self {
|
||||||
* @param int $totalItems
|
|
||||||
*
|
|
||||||
* @return OrderedCollection
|
|
||||||
*/
|
|
||||||
public function setTotalItems(int $totalItems): OrderedCollection {
|
|
||||||
$this->totalItems = $totalItems;
|
$this->totalItems = $totalItems;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getFirst(): string {
|
public function getFirst(): string {
|
||||||
return $this->first;
|
return $this->first;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setFirst(string $first): self {
|
||||||
* @param string $first
|
|
||||||
*
|
|
||||||
* @return OrderedCollection
|
|
||||||
*/
|
|
||||||
public function setFirst(string $first): OrderedCollection {
|
|
||||||
$this->first = $first;
|
$this->first = $first;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLast(): string {
|
||||||
|
return $this->last;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//"id": "https://pub.pontapreta.net/users/admin/following",
|
|
||||||
//"type": "OrderedCollection",
|
|
||||||
//"totalItems": 1,
|
|
||||||
//"first": "https://pub.pontapreta.net/users/admin/following?page=1"
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
*/
|
|
||||||
public function import(array $data) {
|
|
||||||
parent::import($data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setLast(string $last): self {
|
||||||
|
$this->last = $last;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function import(array $data): self {
|
||||||
|
parent::import($data);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function jsonSerialize(): array {
|
public function jsonSerialize(): array {
|
||||||
return array_merge(
|
return array_filter(
|
||||||
parent::jsonSerialize(),
|
array_merge(
|
||||||
[
|
parent::jsonSerialize(),
|
||||||
'totalItems' => $this->getTotalItems(),
|
[
|
||||||
'first' => $this->getFirst()
|
'totalItems' => $this->getTotalItems(),
|
||||||
]
|
'first' => $this->getFirst(),
|
||||||
|
'last' => $this->getLast()
|
||||||
|
]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,18 +56,19 @@ use OCA\Social\Tools\Exceptions\RequestResultNotJsonException;
|
||||||
use OCA\Social\Tools\Exceptions\RequestResultSizeException;
|
use OCA\Social\Tools\Exceptions\RequestResultSizeException;
|
||||||
use OCA\Social\Tools\Exceptions\RequestServerException;
|
use OCA\Social\Tools\Exceptions\RequestServerException;
|
||||||
use OCA\Social\Tools\Traits\TArrayTools;
|
use OCA\Social\Tools\Traits\TArrayTools;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class FollowService {
|
class FollowService {
|
||||||
use TArrayTools;
|
use TArrayTools;
|
||||||
|
|
||||||
|
|
||||||
|
private IURLGenerator $urlGenerator;
|
||||||
private FollowsRequest $followsRequest;
|
private FollowsRequest $followsRequest;
|
||||||
private ActivityService $activityService;
|
private ActivityService $activityService;
|
||||||
private CacheActorService $cacheActorService;
|
private CacheActorService $cacheActorService;
|
||||||
private ConfigService $configService;
|
private ConfigService $configService;
|
||||||
private LoggerInterface $logger;
|
private LoggerInterface $logger;
|
||||||
|
|
||||||
private ?Person $viewer = null;
|
private ?Person $viewer = null;
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,12 +82,14 @@ class FollowService {
|
||||||
* @param LoggerInterface $logger
|
* @param LoggerInterface $logger
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
IURLGenerator $urlGenerator,
|
||||||
FollowsRequest $followsRequest,
|
FollowsRequest $followsRequest,
|
||||||
ActivityService $activityService,
|
ActivityService $activityService,
|
||||||
CacheActorService $cacheActorService,
|
CacheActorService $cacheActorService,
|
||||||
ConfigService $configService,
|
ConfigService $configService,
|
||||||
LoggerInterface $logger
|
LoggerInterface $logger
|
||||||
) {
|
) {
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->followsRequest = $followsRequest;
|
$this->followsRequest = $followsRequest;
|
||||||
$this->activityService = $activityService;
|
$this->activityService = $activityService;
|
||||||
$this->cacheActorService = $cacheActorService;
|
$this->cacheActorService = $cacheActorService;
|
||||||
|
@ -250,8 +253,14 @@ class FollowService {
|
||||||
public function getFollowersCollection(Person $actor): OrderedCollection {
|
public function getFollowersCollection(Person $actor): OrderedCollection {
|
||||||
$collection = new OrderedCollection();
|
$collection = new OrderedCollection();
|
||||||
$collection->setId($actor->getFollowers());
|
$collection->setId($actor->getFollowers());
|
||||||
$collection->setTotalItems(20);
|
$collection->setTotalItems($this->getInt('followers', $actor->getDetails('count')));
|
||||||
$collection->setFirst('...');
|
|
||||||
|
$first = $this->urlGenerator->linkToRouteAbsolute(
|
||||||
|
'social.ActivityPub.followers',
|
||||||
|
['username' => $actor->getPreferredUsername()]
|
||||||
|
)
|
||||||
|
. '?page=1';
|
||||||
|
$collection->setFirst($first);
|
||||||
|
|
||||||
return $collection;
|
return $collection;
|
||||||
}
|
}
|
||||||
|
@ -276,9 +285,15 @@ class FollowService {
|
||||||
*/
|
*/
|
||||||
public function getFollowingCollection(Person $actor): OrderedCollection {
|
public function getFollowingCollection(Person $actor): OrderedCollection {
|
||||||
$collection = new OrderedCollection();
|
$collection = new OrderedCollection();
|
||||||
// $collection->setId($actor->getFollowers());
|
$collection->setId($actor->getFollowing());
|
||||||
// $collection->setTotalItems(20);
|
$collection->setTotalItems($this->getInt('following', $actor->getDetails('count')));
|
||||||
// $collection->setFirst('...');
|
|
||||||
|
$first = $this->urlGenerator->linkToRouteAbsolute(
|
||||||
|
'social.ActivityPub.following',
|
||||||
|
['username' => $actor->getPreferredUsername()]
|
||||||
|
)
|
||||||
|
. '?page=1';
|
||||||
|
$collection->setFirst($first);
|
||||||
|
|
||||||
return $collection;
|
return $collection;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ use OCA\Social\Exceptions\UnauthorizedFediverseException;
|
||||||
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\Note;
|
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||||
|
use OCA\Social\Model\ActivityPub\OrderedCollection;
|
||||||
use OCA\Social\Model\ActivityPub\Stream;
|
use OCA\Social\Model\ActivityPub\Stream;
|
||||||
use OCA\Social\Model\Client\Options\ProbeOptions;
|
use OCA\Social\Model\Client\Options\ProbeOptions;
|
||||||
use OCA\Social\Model\InstancePath;
|
use OCA\Social\Model\InstancePath;
|
||||||
|
@ -52,8 +53,13 @@ use OCA\Social\Tools\Exceptions\RequestNetworkException;
|
||||||
use OCA\Social\Tools\Exceptions\RequestResultNotJsonException;
|
use OCA\Social\Tools\Exceptions\RequestResultNotJsonException;
|
||||||
use OCA\Social\Tools\Exceptions\RequestResultSizeException;
|
use OCA\Social\Tools\Exceptions\RequestResultSizeException;
|
||||||
use OCA\Social\Tools\Exceptions\RequestServerException;
|
use OCA\Social\Tools\Exceptions\RequestServerException;
|
||||||
|
use OCA\Social\Tools\Traits\TArrayTools;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
class StreamService {
|
class StreamService {
|
||||||
|
use TArrayTools;
|
||||||
|
|
||||||
|
private IUrlGenerator $urlGenerator;
|
||||||
private StreamRequest $streamRequest;
|
private StreamRequest $streamRequest;
|
||||||
private ActivityService $activityService;
|
private ActivityService $activityService;
|
||||||
private CacheActorService $cacheActorService;
|
private CacheActorService $cacheActorService;
|
||||||
|
@ -61,20 +67,14 @@ class StreamService {
|
||||||
|
|
||||||
private const ANCESTOR_LIMIT = 5;
|
private const ANCESTOR_LIMIT = 5;
|
||||||
|
|
||||||
/**
|
|
||||||
* NoteService constructor.
|
|
||||||
*
|
|
||||||
* @param StreamRequest $streamRequest
|
|
||||||
* @param ActivityService $activityService
|
|
||||||
* @param CacheActorService $cacheActorService
|
|
||||||
* @param ConfigService $configService
|
|
||||||
*/
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
IUrlGenerator $urlGenerator,
|
||||||
StreamRequest $streamRequest,
|
StreamRequest $streamRequest,
|
||||||
ActivityService $activityService,
|
ActivityService $activityService,
|
||||||
CacheActorService $cacheActorService,
|
CacheActorService $cacheActorService,
|
||||||
ConfigService $configService
|
ConfigService $configService
|
||||||
) {
|
) {
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->streamRequest = $streamRequest;
|
$this->streamRequest = $streamRequest;
|
||||||
$this->activityService = $activityService;
|
$this->activityService = $activityService;
|
||||||
$this->cacheActorService = $cacheActorService;
|
$this->cacheActorService = $cacheActorService;
|
||||||
|
@ -282,8 +282,6 @@ class StreamService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Note $note
|
* @param Note $note
|
||||||
* @param string $replyTo
|
* @param string $replyTo
|
||||||
|
@ -403,7 +401,11 @@ class StreamService {
|
||||||
* @throws StreamNotFoundException
|
* @throws StreamNotFoundException
|
||||||
* @throws DateTimeException
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
public function getRepliesByParentId(string $id, int $since = 0, int $limit = 5, bool $asViewer = false
|
public function getRepliesByParentId(
|
||||||
|
string $id,
|
||||||
|
int $since = 0,
|
||||||
|
int $limit = 5,
|
||||||
|
bool $asViewer = false
|
||||||
): array {
|
): array {
|
||||||
return $this->streamRequest->getRepliesByParentId($id, $since, $limit, $asViewer);
|
return $this->streamRequest->getRepliesByParentId($id, $since, $limit, $asViewer);
|
||||||
}
|
}
|
||||||
|
@ -563,4 +565,26 @@ class StreamService {
|
||||||
|
|
||||||
return $this->cacheActorService->getFromId($note->getAttributedTo());
|
return $this->cacheActorService->getFromId($note->getAttributedTo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Person $actor
|
||||||
|
*
|
||||||
|
* @return OrderedCollection
|
||||||
|
*/
|
||||||
|
public function getOutboxCollection(Person $actor): OrderedCollection {
|
||||||
|
$collection = new OrderedCollection();
|
||||||
|
$collection->setId($actor->getOutbox());
|
||||||
|
$collection->setTotalItems($this->getInt('post', $actor->getDetails('count')));
|
||||||
|
|
||||||
|
$link = $this->urlGenerator->linkToRouteAbsolute(
|
||||||
|
'social.ActivityPub.outbox',
|
||||||
|
['username' => $actor->getPreferredUsername()]
|
||||||
|
);
|
||||||
|
|
||||||
|
$collection->setFirst($link . '?page=1');
|
||||||
|
$collection->setLast($link . '?page=1&min_id=0');
|
||||||
|
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue