summaryrefslogtreecommitdiffstats
path: root/lib/Model/ActivityPub/Actor/Person.php
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-12-13 08:40:27 -0100
committerMaxence Lange <maxence@artificial-owl.com>2018-12-13 08:40:27 -0100
commit7f2eede76bf40ba2c60deb10b9356ca9e8864889 (patch)
tree5d7733febe7ad9613e037b14a1a0076c756dacb8 /lib/Model/ActivityPub/Actor/Person.php
parenta72039c21225de466d7761cc3fa9b1205626cf3e (diff)
moving stuff around
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Model/ActivityPub/Actor/Person.php')
-rw-r--r--lib/Model/ActivityPub/Actor/Person.php530
1 files changed, 530 insertions, 0 deletions
diff --git a/lib/Model/ActivityPub/Actor/Person.php b/lib/Model/ActivityPub/Actor/Person.php
new file mode 100644
index 00000000..adb0ce2f
--- /dev/null
+++ b/lib/Model/ActivityPub/Actor/Person.php
@@ -0,0 +1,530 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Social\Model\ActivityPub\Actor;
+
+
+use JsonSerializable;
+use OCA\Social\Exceptions\InvalidResourceEntryException;
+use OCA\Social\Exceptions\UrlCloudException;
+use OCA\Social\Model\ActivityPub\ACore;
+use OCA\Social\Model\ActivityPub\Object\Image;
+
+
+/**
+ * Class Actor
+ *
+ * @package OCA\Social\Model\ActivityPub
+ */
+class Person extends ACore implements JsonSerializable {
+
+
+ const TYPE = 'Person';
+
+
+ /** @var string */
+ private $userId = '';
+
+ /** @var string */
+ private $name = '';
+
+ /** @var string */
+ private $preferredUsername = '';
+
+ /** @var string */
+ private $publicKey = '';
+
+ /** @var string */
+ private $privateKey = '';
+
+ /** @var int */
+ private $creation = 0;
+
+ /** @var string */
+ private $account = '';
+
+ /** @var string */
+ private $following = '';
+
+ /** @var string */
+ private $followers = '';
+
+ /** @var string */
+ private $inbox = '';
+
+ /** @var string */
+ private $outbox = '';
+
+ /** @var string */
+ private $sharedInbox = '';
+
+ /** @var string */
+ private $featured = '';
+
+ /** @var array */
+ private $details = [];
+
+ /** @var int */
+ private $avatarVersion = -1;
+
+
+ /**
+ * Person constructor.
+ *
+ * @param ACore $parent
+ */
+ public function __construct($parent = null) {
+ parent::__construct($parent);
+
+ $this->setType(self::TYPE);
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getUserId(): string {
+ return $this->userId;
+ }
+
+ /**
+ * @param string $userId
+ *
+ * @return Person
+ */
+ public function setUserId(string $userId): Person {
+ $this->userId = $userId;
+
+ return $this;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getPreferredUsername(): string {
+ return $this->preferredUsername;
+ }
+
+ /**
+ * @param string $preferredUsername
+ *
+ * @return Person
+ */
+ public function setPreferredUsername(string $preferredUsername): Person {
+ $this->preferredUsername = $preferredUsername;
+
+ return $this;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getPublicKey(): string {
+ return $this->publicKey;
+ }
+
+ /**
+ * @param string $publicKey
+ *
+ * @return Person
+ */
+ public function setPublicKey(string $publicKey): Person {
+ $this->publicKey = $publicKey;
+
+ return $this;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getPrivateKey(): string {
+ return $this->privateKey;
+ }
+
+ /**
+ * @param string $privateKey
+ *
+ * @return Person
+ */
+ public function setPrivateKey(string $privateKey): Person {
+ $this->privateKey = $privateKey;
+
+ return $this;
+ }
+
+
+ /**
+ * @return int
+ */
+ public function getCreation(): int {
+ return $this->creation;
+ }
+
+ /**
+ * @param int $creation
+ *
+ * @return Person
+ */
+ public function setCreation(int $creation): Person {
+ $this->creation = $creation;
+
+ return $this;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getFollowing(): string {
+ return $this->following;
+ }
+
+ /**
+ * @param string $following
+ *
+ * @return Person
+ */
+ public function setFollowing(string $following): Person {
+ $this->following = $following;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getFollowers(): string {
+ return $this->followers;
+ }
+
+ /**
+ * @param string $followers
+ *
+ * @return Person
+ */
+ public function setFollowers(string $followers): Person {
+ $this->followers = $followers;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAccount(): string {
+ return $this->account;
+ }
+
+ /**
+ * @param string $account
+ *
+ * @return Person
+ */
+ public function setAccount(string $account): Person {
+ if ($account !== '' && substr($account, 0, 1) === '@') {
+ $account = substr($account, 1);
+ }
+
+ $this->account = $account;
+
+ return $this;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getInbox(): string {
+ return $this->inbox;
+ }
+
+ /**
+ * @param string $inbox
+ *
+ * @return Person
+ */
+ public function setInbox(string $inbox): Person {
+ $this->inbox = $inbox;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOutbox(): string {
+ return $this->outbox;
+ }
+
+ /**
+ * @param string $outbox
+ *
+ * @return Person
+ */
+ public function setOutbox(string $outbox): Person {
+ $this->outbox = $outbox;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getSharedInbox(): string {
+ return $this->sharedInbox;
+ }
+
+ /**
+ * @param string $sharedInbox
+ *
+ * @return Person
+ */
+ public function setSharedInbox(string $sharedInbox): Person {
+ $this->sharedInbox = $sharedInbox;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getName(): string {
+ return $this->name;
+ }
+
+ /**
+ * @param string $name
+ *
+ * @return Person
+ */
+ public function setName(string $name): Person {
+ $this->name = $name;
+
+ return $this;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getFeatured(): string {
+ return $this->featured;
+ }
+
+ /**
+ * @param string $featured
+ *
+ * @return Person
+ */
+ public function setFeatured(string $featured): Person {
+ $this->featured = $featured;
+
+ return $this;
+ }
+
+
+ /**
+ * @return array
+ */
+ public function getDetails(): array {
+ return $this->details;
+ }
+
+ /**
+ * @param string $detail
+ * @param string $value
+ *
+ * @return Person
+ */
+ public function addDetail(string $detail, string $value): Person {
+ $this->details[$detail] = $value;
+
+ return $this;
+ }
+
+ /**
+ * @param string $detail
+ * @param int $value
+ *
+ * @return Person
+ */
+ public function addDetailInt(string $detail, int $value): Person {
+ $this->details[$detail] = $value;
+
+ return $this;
+ }
+
+ /**
+ * @param string $detail
+ * @param array $value
+ *
+ * @return Person
+ */
+ public function addDetailArray(string $detail, array $value): Person {
+ $this->details[$detail] = $value;
+
+ return $this;
+ }
+
+ /**
+ * @param string $detail
+ * @param bool $value
+ *
+ * @return Person
+ */
+ public function addDetailBool(string $detail, bool $value): Person {
+ $this->details[$detail] = $value;
+
+ return $this;
+ }
+
+ /**
+ * @param array $details
+ *
+ * @return Person
+ */
+ public function setDetails(array $details): Person {
+ $this->details = $details;
+
+ return $this;
+ }
+
+
+ /**
+ * @return int
+ */
+ public function getAvatarVersion(): int {
+ return $this->avatarVersion;
+ }
+
+ /**
+ * @param int $avatarVersion
+ *
+ * @return Person
+ */
+ public function setAvatarVersion(int $avatarVersion): Person {
+ $this->avatarVersion = $avatarVersion;
+
+ return $this;
+ }
+
+
+ /**
+ * @param array $data
+ *
+ * @throws UrlCloudException
+ * @throws InvalidResourceEntryException
+ */
+ public function import(array $data) {
+ parent::import($data);
+ $this->setPreferredUsername(
+ $this->validate(ACore::AS_USERNAME, 'preferredUsername', $data, '')
+ )
+ ->setPublicKey($this->get('publicKey.publicKeyPem', $data))
+ ->setSharedInbox($this->validate(ACore::AS_URL, 'endpoints.sharedInbox', $data))
+ ->setName($this->validate(ACore::AS_USERNAME, 'name', $data, ''))
+ ->setAccount($this->validate(ACore::AS_ACCOUNT, 'account', $data, ''))
+ ->setInbox($this->validate(ACore::AS_URL, 'inbox', $data, ''))
+ ->setOutbox($this->validate(ACore::AS_URL, 'outbox', $data, ''))
+ ->setFollowers($this->validate(ACore::AS_URL, 'followers', $data, ''))
+ ->setFollowing($this->validate(ACore::AS_URL, 'following', $data, ''))
+ ->setFeatured($this->validate(ACore::AS_URL, 'featured', $data, ''));
+
+ $icon = new Image($this);
+ $icon->setUrlCloud($this->getUrlCloud());
+ $icon->import($this->getArray('icon', $data, []));
+
+ if ($icon->getType() === Image::TYPE) {
+ $this->setIcon($icon);
+ }
+
+ }
+
+
+ /**
+ * @param array $data
+ */
+ public function importFromDatabase(array $data) {
+ parent::importFromDatabase($data);
+ $this->setPreferredUsername($this->get('preferred_username', $data, ''))
+ ->setName($this->get('name', $data, ''))
+ ->setAccount($this->get('account', $data, ''))
+ ->setPublicKey($this->get('public_key', $data, ''))
+ ->setPrivateKey($this->get('private_key', $data, ''))
+ ->setInbox($this->get('inbox', $data, ''))
+ ->setOutbox($this->get('outbox', $data, ''))
+ ->setFollowers($this->get('followers', $data, ''))
+ ->setFollowing($this->get('following', $data, ''))
+ ->setSharedInbox($this->get('shared_inbox', $data, ''))
+ ->setFeatured($this->get('featured', $data, ''))
+ ->setDetails($this->getArray('details', $data, []))
+ ->setCreation($this->getInt('creation', $data, 0));
+ }
+
+
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array {
+ $result = array_merge(
+ parent::jsonSerialize(),
+ [
+ 'aliases' => [
+ $this->getUrlSocial() . '@' . $this->getPreferredUsername(),
+ $this->getUrlSocial() . 'users/' . $this->getPreferredUsername()
+ ],
+ 'preferredUsername' => $this->getPreferredUsername(),
+ 'name' => $this->getName(),
+ 'inbox' => $this->getInbox(),
+ 'outbox' => $this->getOutbox(),
+ 'account' => $this->getAccount(),
+ 'following' => $this->getFollowing(),
+ 'followers' => $this->getFollowers(),
+ 'endpoints' =>
+ ['sharedInbox' => $this->getSharedInbox()],
+ 'publicKey' => [
+ 'id' => $this->getId() . '#main-key',
+ 'owner' => $this->getId(),
+ 'publicKeyPem' => $this->getPublicKey()
+ ]
+ ]
+ );
+
+ if ($this->isCompleteDetails()) {
+ $result['details'] = $this->getDetails();
+ }
+
+ return $result;
+ }
+
+}