generate details on account info

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/82/head
Maxence Lange 2018-11-29 16:41:55 -01:00
rodzic aaafa82b4b
commit c005273e1f
5 zmienionych plików z 123 dodań i 15 usunięć

Wyświetl plik

@ -128,7 +128,7 @@ class ActivityPubController extends Controller {
*/
public function actor(string $username): Response {
if (!$this->checkSourceActivityStreams()) {
return $this->navigationController->public($username);
return $this->socialPubController->actor($username);
}
try {

Wyświetl plik

@ -31,13 +31,18 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Service\ActivityService;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Service\ActivityPub\PersonService;
use OCA\Social\Service\ActorService;
use OCA\Social\Service\MiscService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IL10N;
use OCP\IRequest;
class SocialPubController extends Controller {
@ -45,12 +50,18 @@ class SocialPubController extends Controller {
use TNCDataResponse;
/** @var ActivityService */
private $activityService;
/** @var string */
private $userId;
/** @var IL10N */
private $l10n;
/** @var ActorService */
private $actorService;
/** @var PersonService */
private $personService;
/** @var MiscService */
private $miscService;
@ -58,19 +69,23 @@ class SocialPubController extends Controller {
/**
* SocialPubController constructor.
*
* @param ActivityService $activityService
* @param ActorService $actorService
* @param $userId
* @param IRequest $request
* @param IL10N $l10n
* @param ActorService $actorService
* @param PersonService $personService
* @param MiscService $miscService
*/
public function __construct(
ActivityService $activityService, ActorService $actorService, IRequest $request,
MiscService $miscService
$userId, IRequest $request, IL10N $l10n, ActorService $actorService,
PersonService $personService, MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
$this->activityService = $activityService;
$this->userId = $userId;
$this->l10n = $l10n;
$this->actorService = $actorService;
$this->personService = $personService;
$this->miscService = $miscService;
}
@ -81,14 +96,39 @@ class SocialPubController extends Controller {
*
* @NoCSRFRequired
* @PublicPage
* e*
*
* @param string $username
*
* @return TemplateResponse
* @return Response
*/
public function actor(string $username): TemplateResponse {
return new TemplateResponse(Application::APP_NAME, 'actor', [], 'blank');
public function actor(string $username): Response {
try {
$actor = $this->personService->getFromLocalAccount($username);
if ($this->userId !== null) {
$local = $this->actorService->getActorFromUserId($this->userId, true);
$this->actorService->acquaintLinksBetweenPersons($actor, $local);
$actor->setCompleteDetails(true);
}
$data = [
'serverData' => [
'public' => true,
],
'actor' => $actor
];
$page = new PublicTemplateResponse(Application::APP_NAME, 'main', $data);
$page->setHeaderTitle($this->l10n->t('Social') . ' ' . $username);
$this->miscService->log(json_encode($actor));
return $page;
} catch (CacheActorDoesNotExistException $e) {
return new NotFoundResponse();
} catch (Exception $e) {
$this->fail($e);
}
}

Wyświetl plik

@ -153,6 +153,32 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
}
/**
* get Cached version of a local Actor, based on the preferred username
*
* @param string $account
*
* @return Person
* @throws CacheActorDoesNotExistException
*/
public function getFromLocalAccount(string $account): Person {
$qb = $this->getCacheActorsSelectSql();
$this->limitToPreferredUsername($qb, $account);
$this->limitToLocal($qb, true);
$this->leftJoinCacheDocuments($qb, 'icon_id');
$cursor = $qb->execute();
$data = $cursor->fetch();
$cursor->closeCursor();
if ($data === false) {
throw new CacheActorDoesNotExistException();
}
return $this->parseCacheActorsSelectSql($data);
}
/**
* @param string $search
*

Wyświetl plik

@ -189,6 +189,17 @@ class PersonService implements ICoreService {
}
/**
* @param string $account
*
* @return Person
* @throws CacheActorDoesNotExistException
*/
public function getFromLocalAccount(string $account): Person {
return $this->cacheActorsRequest->getFromLocalAccount($account);
}
/**
* @param array $object
*

Wyświetl plik

@ -36,6 +36,7 @@ use OC\User\NoUserException;
use OCA\Social\Db\ActorsRequest;
use OCA\Social\Exceptions\AccountAlreadyExistsException;
use OCA\Social\Exceptions\ActorDoesNotExistException;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Model\ActivityPub\Person;
use OCA\Social\Service\ActivityPub\PersonService;
@ -114,15 +115,26 @@ class ActorService {
/**
* @param string $userId
* @param bool $create
*
* @return Person
* @throws AccountAlreadyExistsException
* @throws ActorDoesNotExistException
* @throws NoUserException
* @throws SocialAppConfigException
*/
public function getActorFromUserId(string $userId): Person {
public function getActorFromUserId(string $userId, bool $create = false): Person {
$this->miscService->confirmUserId($userId);
$actor = $this->actorsRequest->getFromUserId($userId);
try {
$actor = $this->actorsRequest->getFromUserId($userId);
} catch (ActorDoesNotExistException $e) {
if ($create) {
$this->createActor($userId, $userId);
$actor = $this->actorsRequest->getFromUserId($userId);
} else {
throw new ActorDoesNotExistException();
}
}
return $actor;
}
@ -177,6 +189,21 @@ class ActorService {
}
/**
* @param Person $local
* @param Person $actor
*/
public function acquaintLinksBetweenPersons(Person $actor, Person $local) {
$actor->addDetailArray(
'links',
[
'follower' => true,
'following' => true
]
);
}
/**
* @param string $username
* @param bool $refresh
@ -186,6 +213,10 @@ class ActorService {
public function cacheLocalActorByUsername(string $username, bool $refresh = false) {
try {
$actor = $this->getActor($username);
$actor->addDetailInt('followers', 10);
$actor->addDetailInt('following', 10);
$actor->addDetailInt('post', 100);
$this->personService->cacheLocalActor($actor, $refresh);
} catch (ActorDoesNotExistException $e) {
}