kopia lustrzana https://github.com/nextcloud/social
info about links between viewer/account
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/82/head
rodzic
ead09b1085
commit
39ce6745e1
|
@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
|
|||
use Exception;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
|
||||
use OCA\Social\Model\ActivityPub\Person;
|
||||
use OCA\Social\Service\ActivityPub\PersonService;
|
||||
use OCA\Social\Service\ActorService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
|
@ -107,22 +108,31 @@ class SocialPubController extends Controller {
|
|||
$actor = $this->personService->getFromLocalAccount($username);
|
||||
$actor->setCompleteDetails(true);
|
||||
|
||||
$logged = false;
|
||||
$ownAccount = false;
|
||||
if ($this->userId !== null) {
|
||||
$logged = true;
|
||||
$local = $this->actorService->getActorFromUserId($this->userId, true);
|
||||
$this->actorService->acquaintLinksBetweenPersons($actor, $local);
|
||||
if ($local->getId() === $actor->getId()) {
|
||||
$ownAccount = true;
|
||||
} else {
|
||||
$this->fillActorWithLinks($actor, $local);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'serverData' => [
|
||||
'public' => true,
|
||||
],
|
||||
'actor' => $actor
|
||||
'actor' => $actor,
|
||||
'logged' => $logged,
|
||||
'ownAccount' => $ownAccount
|
||||
];
|
||||
|
||||
|
||||
$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();
|
||||
|
@ -179,6 +189,15 @@ class SocialPubController extends Controller {
|
|||
return $this->success([$username, $postId]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Person $actor
|
||||
* @param Person $local
|
||||
*/
|
||||
private function fillActorWithLinks(Person $actor, Person $local) {
|
||||
$links = $this->actorService->getLinksBetweenPersons($local, $actor);
|
||||
$actor->addDetailArray('link', $links);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
|
|||
'ca.id', 'ca.account', 'ca.following', 'ca.followers', 'ca.inbox',
|
||||
'ca.shared_inbox', 'ca.outbox', 'ca.featured', 'ca.url', 'ca.type',
|
||||
'ca.preferred_username', 'ca.name', 'ca.summary',
|
||||
'ca.public_key', 'ca.local', 'ca.source', 'ca.creation'
|
||||
'ca.public_key', 'ca.local', 'ca.details', 'ca.source', 'ca.creation'
|
||||
)
|
||||
->from(self::TABLE_CACHE_ACTORS, 'ca');
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ use OCA\Social\Db\FollowsRequest;
|
|||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Exceptions\AccountAlreadyExistsException;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\FollowDoesNotExistException;
|
||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
use OCA\Social\Model\ActivityPub\Person;
|
||||
use OCA\Social\Service\ActivityPub\PersonService;
|
||||
|
@ -203,15 +204,29 @@ class ActorService {
|
|||
/**
|
||||
* @param Person $local
|
||||
* @param Person $actor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function acquaintLinksBetweenPersons(Person $actor, Person $local) {
|
||||
$actor->addDetailArray(
|
||||
'links',
|
||||
[
|
||||
'follower' => true,
|
||||
'following' => true
|
||||
]
|
||||
);
|
||||
public function getLinksBetweenPersons(Person $local, Person $actor): array {
|
||||
|
||||
$links = [
|
||||
'follower' => false,
|
||||
'following' => false
|
||||
];
|
||||
|
||||
try {
|
||||
$this->followsRequest->getByPersons($local->getId(), $actor->getId());
|
||||
$links['following'] = true;
|
||||
} catch (FollowDoesNotExistException $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
$this->followsRequest->getByPersons($actor->getId(), $local->getId());
|
||||
$links['follower'] = true;
|
||||
} catch (FollowDoesNotExistException $e) {
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue