kopia lustrzana https://github.com/nextcloud/social
Followers/Following
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/86/head
rodzic
3eafb16c4e
commit
f9f2b07d7e
|
@ -261,7 +261,7 @@ class ActivityPubController extends Controller {
|
|||
|
||||
try {
|
||||
$actor = $this->actorService->getActor($username);
|
||||
$followers = $this->followService->getFollowers($actor);
|
||||
$followers = $this->followService->getFollowersCollection($actor);
|
||||
|
||||
// $followers->setTopLevel(true);
|
||||
|
||||
|
|
|
@ -374,6 +374,82 @@ class LocalController extends Controller {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function currentFollowers(): DataResponse {
|
||||
try {
|
||||
$actor = $this->actorService->getActorFromUserId($this->userId);
|
||||
$followers = $this->followService->getFollowers($actor);
|
||||
|
||||
return $this->success($followers);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function currentFollowing(): DataResponse {
|
||||
try {
|
||||
$actor = $this->actorService->getActorFromUserId($this->userId);
|
||||
$followers = $this->followService->getFollowing($actor);
|
||||
|
||||
return $this->success($followers);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function accountFollowers(string $username): DataResponse {
|
||||
try {
|
||||
$actor = $this->actorService->getActor($username);
|
||||
$followers = $this->followService->getFollowers($actor);
|
||||
|
||||
return $this->success($followers);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function accountFollowing(string $username): DataResponse {
|
||||
try {
|
||||
$actor = $this->actorService->getActor($username);
|
||||
$followers = $this->followService->getFollowing($actor);
|
||||
|
||||
return $this->success($followers);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* // TODO: Delete the NoCSRF check
|
||||
|
@ -425,6 +501,7 @@ class LocalController extends Controller {
|
|||
* @NoSubAdminRequired
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function actorAvatar(string $id): Response {
|
||||
|
|
|
@ -32,8 +32,10 @@ namespace OCA\Social\Db;
|
|||
|
||||
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use DateTime;
|
||||
use OCA\Social\Exceptions\FollowDoesNotExistException;
|
||||
use OCA\Social\Model\ActivityPub\Follow;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -58,7 +60,11 @@ class FollowsRequest extends FollowsRequestBuilder {
|
|||
->setValue('actor_id', $qb->createNamedParameter($follow->getActorId()))
|
||||
->setValue('type', $qb->createNamedParameter($follow->getType()))
|
||||
->setValue('object_id', $qb->createNamedParameter($follow->getObjectId()))
|
||||
->setValue('follow_id', $qb->createNamedParameter($follow->getFollowId()));
|
||||
->setValue('follow_id', $qb->createNamedParameter($follow->getFollowId()))
|
||||
->setValue(
|
||||
'creation',
|
||||
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
|
||||
);
|
||||
|
||||
$qb->execute();
|
||||
}
|
||||
|
@ -158,6 +164,50 @@ class FollowsRequest extends FollowsRequestBuilder {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $actorId
|
||||
*
|
||||
* @return Follow[]
|
||||
*/
|
||||
public function getFollowersByActorId(string $actorId): array {
|
||||
$qb = $this->getFollowsSelectSql();
|
||||
$this->limitToOBjectId($qb, $actorId);
|
||||
$this->leftJoinCacheActors($qb, 'actor_id');
|
||||
$qb->orderBy('creation', 'desc');
|
||||
|
||||
$follows = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$follows[] = $this->parseFollowsSelectSql($data);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $follows;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $actorId
|
||||
*
|
||||
* @return Follow[]
|
||||
*/
|
||||
public function getFollowingByActorId(string $actorId): array {
|
||||
$qb = $this->getFollowsSelectSql();
|
||||
$this->limitToActorId($qb, $actorId);
|
||||
$this->leftJoinCacheActors($qb, 'actor_id');
|
||||
$qb->orderBy('creation', 'desc');
|
||||
|
||||
$follows = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$follows[] = $this->parseFollowsSelectSql($data);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $follows;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Follow $follow
|
||||
*/
|
||||
|
|
|
@ -149,12 +149,22 @@ class FollowService implements ICoreService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Person $actor
|
||||
*
|
||||
* @return Person[]
|
||||
*/
|
||||
public function getFollowers(Person $actor): array {
|
||||
return $this->followsRequest->getFollowersByActorId($actor->getId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Person $actor
|
||||
*
|
||||
* @return OrderedCollection
|
||||
*/
|
||||
public function getFollowers(Person $actor): OrderedCollection {
|
||||
public function getFollowersCollection(Person $actor): OrderedCollection {
|
||||
$collection = new OrderedCollection();
|
||||
$collection->setId($actor->getFollowers());
|
||||
$collection->setTotalItems(20);
|
||||
|
@ -164,6 +174,31 @@ class FollowService implements ICoreService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Person $actor
|
||||
*
|
||||
* @return Person[]
|
||||
*/
|
||||
public function getFollowing(Person $actor): array {
|
||||
return $this->followsRequest->getFollowingByActorId($actor->getId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Person $actor
|
||||
*
|
||||
* @return OrderedCollection
|
||||
*/
|
||||
public function getFollowingCollection(Person $actor): OrderedCollection {
|
||||
$collection = new OrderedCollection();
|
||||
// $collection->setId($actor->getFollowers());
|
||||
// $collection->setTotalItems(20);
|
||||
// $collection->setFirst('...');
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Follow $follow
|
||||
*/
|
||||
|
|
Ładowanie…
Reference in New Issue