kopia lustrzana https://github.com/nextcloud/social
Merge pull request #100 from nextcloud-gmbh/fixing-details
set viewer and assign detailspull/99/head
commit
d08ec50d28
|
@ -75,7 +75,7 @@ return [
|
|||
['name' => 'Local#actionFollow', 'url' => '/api/v1/current/follow', 'verb' => 'PUT'],
|
||||
['name' => 'Local#actionUnfollow', 'url' => '/api/v1/current/follow', 'verb' => 'DELETE'],
|
||||
|
||||
['name' => 'Local#currentInfo', 'url' => '/api/v1/current/info', 'verb' => 'PUT'],
|
||||
['name' => 'Local#currentInfo', 'url' => '/api/v1/current/info', 'verb' => 'GET'],
|
||||
['name' => 'Local#currentFollowers', 'url' => '/api/v1/current/followers', 'verb' => 'GET'],
|
||||
['name' => 'Local#currentFollowing', 'url' => '/api/v1/current/following', 'verb' => 'GET'],
|
||||
|
||||
|
|
|
@ -407,7 +407,15 @@ class LocalController extends Controller {
|
|||
* @return DataResponse
|
||||
*/
|
||||
public function accountInfo(string $username): DataResponse {
|
||||
|
||||
try {
|
||||
$viewer = $this->actorService->getActorFromUserId($this->userId, true);
|
||||
$this->personService->setViewerId($viewer->getId());
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$actor = $this->actorService->getActor($username);
|
||||
$actor = $this->personService->getFromLocalAccount($actor->getPreferredUsername());
|
||||
|
||||
|
@ -473,6 +481,12 @@ class LocalController extends Controller {
|
|||
* @return DataResponse
|
||||
*/
|
||||
public function globalAccountInfo(string $account): DataResponse {
|
||||
try {
|
||||
$viewer = $this->actorService->getActorFromUserId($this->userId, true);
|
||||
$this->personService->setViewerId($viewer->getId());
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
$actor = $this->personService->getFromAccount($account);
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ namespace OCA\Social\Db;
|
|||
use DateTime;
|
||||
use Exception;
|
||||
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Model\ActivityPub\Person;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
|
@ -134,20 +133,14 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
*
|
||||
* @param string $account
|
||||
*
|
||||
* @param string $viewerId
|
||||
*
|
||||
* @return Person
|
||||
* @throws CacheActorDoesNotExistException
|
||||
*/
|
||||
public function getFromAccount(string $account, string $viewerId = ''): Person {
|
||||
public function getFromAccount(string $account): Person {
|
||||
$qb = $this->getCacheActorsSelectSql();
|
||||
$this->limitToAccount($qb, $account);
|
||||
$this->leftJoinCacheDocuments($qb, 'icon_id');
|
||||
|
||||
if ($viewerId !== '') {
|
||||
$this->leftJoinFollowAsViewer($qb, 'id', $viewerId, true, 'as_follower');
|
||||
$this->leftJoinFollowAsViewer($qb, 'id', $viewerId, false, 'as_followed');
|
||||
}
|
||||
$this->leftJoinDetails($qb);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
|
@ -157,21 +150,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
throw new CacheActorDoesNotExistException();
|
||||
}
|
||||
|
||||
$account = $this->parseCacheActorsSelectSql($data);
|
||||
|
||||
try {
|
||||
$this->parseFollowLeftJoin($data, 'as_follower');
|
||||
$account->addDetailBool('following', true);
|
||||
} catch (InvalidResourceException $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
$this->parseFollowLeftJoin($data, 'as_followed');
|
||||
$account->addDetailBool('followed', true);
|
||||
} catch (InvalidResourceException $e) {
|
||||
}
|
||||
|
||||
return $account;
|
||||
return $this->parseCacheActorsSelectSql($data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -188,6 +167,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
$this->limitToPreferredUsername($qb, $account);
|
||||
$this->limitToLocal($qb, true);
|
||||
$this->leftJoinCacheDocuments($qb, 'icon_id');
|
||||
$this->leftJoinDetails($qb);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
|
@ -203,44 +183,19 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
|
||||
/**
|
||||
* @param string $search
|
||||
* @param string $viewerId
|
||||
*
|
||||
* @return Person[]
|
||||
*/
|
||||
public function searchAccounts(string $search, string $viewerId = ''): array {
|
||||
public function searchAccounts(string $search): array {
|
||||
$qb = $this->getCacheActorsSelectSql();
|
||||
$this->searchInAccount($qb, $search);
|
||||
$this->leftJoinCacheDocuments($qb, 'icon_id');
|
||||
|
||||
if ($viewerId !== '') {
|
||||
$this->leftJoinFollowAsViewer($qb, 'id', $viewerId, true, 'as_follower');
|
||||
$this->leftJoinFollowAsViewer($qb, 'id', $viewerId, false, 'as_followed');
|
||||
}
|
||||
$this->leftJoinDetails($qb);
|
||||
|
||||
$accounts = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$account = $this->parseCacheActorsSelectSql($data);
|
||||
|
||||
if ($viewerId !== '') {
|
||||
try {
|
||||
$this->parseFollowLeftJoin($data, 'as_follower');
|
||||
$account->addDetailBool('following', true);
|
||||
} catch (InvalidResourceException $e) {
|
||||
$account->addDetailBool('following', false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->parseFollowLeftJoin($data, 'as_followed');
|
||||
$account->addDetailBool('followed', true);
|
||||
} catch (InvalidResourceException $e) {
|
||||
$account->addDetailBool('followed', false);
|
||||
}
|
||||
|
||||
$account->setCompleteDetails(true);
|
||||
}
|
||||
|
||||
$accounts[] = $account;
|
||||
$accounts[] = $this->parseCacheActorsSelectSql($data);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
|
|
|
@ -119,8 +119,41 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
|
|||
} catch (InvalidResourceException $e) {
|
||||
}
|
||||
|
||||
$this->assignDetails($actor, $data);
|
||||
|
||||
return $actor;
|
||||
}
|
||||
|
||||
|
||||
protected function leftJoinDetails(IQueryBuilder $qb) {
|
||||
$viewerId = $this->getViewerId();
|
||||
if ($viewerId !== '') {
|
||||
$this->leftJoinFollowAsViewer($qb, 'id', $viewerId, true, 'as_follower');
|
||||
$this->leftJoinFollowAsViewer($qb, 'id', $viewerId, false, 'as_followed');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function assignDetails(Person $actor, array $data) {
|
||||
if ($this->getViewerId() !== '') {
|
||||
|
||||
try {
|
||||
$this->parseFollowLeftJoin($data, 'as_follower');
|
||||
$actor->addDetailBool('following', true);
|
||||
} catch (InvalidResourceException $e) {
|
||||
$actor->addDetailBool('following', false);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->parseFollowLeftJoin($data, 'as_followed');
|
||||
$actor->addDetailBool('followed', true);
|
||||
} catch (InvalidResourceException $e) {
|
||||
$actor->addDetailBool('followed', false);
|
||||
}
|
||||
|
||||
$actor->setCompleteDetails(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,9 @@ class CoreRequestBuilder {
|
|||
/** @var string */
|
||||
protected $defaultSelectAlias;
|
||||
|
||||
/** @var string */
|
||||
private $viewerId = '';
|
||||
|
||||
|
||||
/**
|
||||
* CoreRequestBuilder constructor.
|
||||
|
@ -94,6 +97,21 @@ class CoreRequestBuilder {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getViewerId(): string {
|
||||
return $this->viewerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $viewerId
|
||||
*/
|
||||
public function setViewerId(string $viewerId) {
|
||||
$this->viewerId = $viewerId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limit the request to the Id
|
||||
*
|
||||
|
|
|
@ -106,6 +106,7 @@ class PersonService implements ICoreService {
|
|||
*/
|
||||
public function setViewerId(string $viewerId) {
|
||||
$this->viewerId = $viewerId;
|
||||
$this->cacheActorsRequest->setViewerId($viewerId);
|
||||
}
|
||||
|
||||
public function getViewerId(): string {
|
||||
|
@ -185,7 +186,7 @@ class PersonService implements ICoreService {
|
|||
public function getFromAccount(string $account, bool $retrieve = true): Person {
|
||||
|
||||
try {
|
||||
$actor = $this->cacheActorsRequest->getFromAccount($account, $this->getViewerId());
|
||||
$actor = $this->cacheActorsRequest->getFromAccount($account);
|
||||
} catch (CacheActorDoesNotExistException $e) {
|
||||
if (!$retrieve) {
|
||||
throw new CacheActorDoesNotExistException();
|
||||
|
@ -245,7 +246,7 @@ class PersonService implements ICoreService {
|
|||
* @return Person[]
|
||||
*/
|
||||
public function searchCachedAccounts(string $search): array {
|
||||
return $this->cacheActorsRequest->searchAccounts($search, $this->getViewerId());
|
||||
return $this->cacheActorsRequest->searchAccounts($search);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -240,9 +240,9 @@ class ActorService {
|
|||
try {
|
||||
$actor = $this->getActor($username);;
|
||||
$count = [
|
||||
'followers', $this->followsRequest->countFollowers($actor->getId()),
|
||||
'following', $this->followsRequest->countFollowing($actor->getId()),
|
||||
'post', $this->notesRequest->countNotesFromActorId($actor->getId())
|
||||
'followers' => $this->followsRequest->countFollowers($actor->getId()),
|
||||
'following' => $this->followsRequest->countFollowing($actor->getId()),
|
||||
'post' => $this->notesRequest->countNotesFromActorId($actor->getId())
|
||||
];
|
||||
$actor->addDetailArray('count', $count);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue