diff options
Diffstat (limited to 'lib/Model')
-rw-r--r-- | lib/Model/ActivityPub/Actor/Person.php | 150 | ||||
-rw-r--r-- | lib/Model/Client/ClientApp.php | 8 | ||||
-rw-r--r-- | lib/Model/Instance.php | 441 |
3 files changed, 566 insertions, 33 deletions
diff --git a/lib/Model/ActivityPub/Actor/Person.php b/lib/Model/ActivityPub/Actor/Person.php index 163325d5..d169c60b 100644 --- a/lib/Model/ActivityPub/Actor/Person.php +++ b/lib/Model/ActivityPub/Actor/Person.php @@ -109,6 +109,9 @@ class Person extends ACore implements IQueryRow, JsonSerializable { /** @var string */ private $featured = ''; + /** @var string */ + private $header = ''; + /** @var bool */ private $locked = false; @@ -118,6 +121,15 @@ class Person extends ACore implements IQueryRow, JsonSerializable { /** @var bool */ private $discoverable = false; + /** @var string */ + private $privacy = 'public'; + + /** @var bool */ + private $sensitive = false; + + /** @var string */ + private $language = 'en'; + /** @var int */ private $avatarVersion = -1; @@ -185,9 +197,15 @@ class Person extends ACore implements IQueryRow, JsonSerializable { return $this->displayName; } - - public function setDisplayName(string $displayName): string { + /** + * @param string $displayName + * + * @return $this + */ + public function setDisplayName(string $displayName): self { $this->displayName = $displayName; + + return $this; } @@ -213,6 +231,42 @@ class Person extends ACore implements IQueryRow, JsonSerializable { /** * @return string */ + public function getAvatar(): string { + if ($this->hasIcon()) { + return $this->getIcon() + ->getId(); + } + + return ''; + } + + + /** + * @return string + */ + public function getHeader(): string { + if ($this->header === '') { + return $this->getAvatar(); + } + + return $this->header; + } + + /** + * @param string $header + * + * @return $this + */ + public function setHeader(string $header): self { + $this->header = $header; + + return $this; + } + + + /** + * @return string + */ public function getPublicKey(): string { return $this->publicKey; } @@ -476,6 +530,63 @@ class Person extends ACore implements IQueryRow, JsonSerializable { /** + * @return string + */ + public function getPrivacy(): string { + return $this->privacy; + } + + /** + * @param string $privacy + * + * @return Person + */ + public function setPrivacy(string $privacy): self { + $this->privacy = $privacy; + + return $this; + } + + + /** + * @return bool + */ + public function isSensitive(): bool { + return $this->sensitive; + } + + /** + * @param bool $sensitive + * + * @return Person + */ + public function setSensitive(bool $sensitive): self { + $this->sensitive = $sensitive; + + return $this; + } + + + /** + * @return string + */ + public function getLanguage(): string { + return $this->language; + } + + /** + * @param string $language + * + * @return $this + */ + public function setLanguage(string $language): self { + $this->language = $language; + + return $this; + } + + + /** * @return int */ public function getAvatarVersion(): int { @@ -612,31 +723,42 @@ class Person extends ACore implements IQueryRow, JsonSerializable { * @return array */ public function exportAsLocal(): array { + $details = $this->getDetailsAll(); $result = [ + "id" => $this->getId(), "username" => $this->getPreferredUsername(), - "acct" => $this->getAccount(), + "acct" => $this->getPreferredUsername(), "display_name" => $this->getDisplayName(), "locked" => $this->isLocked(), "bot" => $this->isBot(), "discoverable" => $this->isDiscoverable(), "group" => false, - "created_at" => "2017-05-02T09=>56=>41.951Z", + "created_at" => date('Y-m-d\TH:i:s', $this->getCreation()) . '.000Z', "note" => $this->getDescription(), "url" => $this->getId(), - "avatar" => "https://files.mastodon.social/accounts/avatars/000/126/222/original/50785214e44d10cc.jpeg", - "avatar_static" => "https://files.mastodon.social/accounts/avatars/000/126/222/original/50785214e44d10cc.jpeg", - "header" => "https://files.mastodon.social/accounts/headers/000/126/222/original/6d7b41fdd92cfd6f.jpeg", - "header_static" => "https://files.mastodon.social/accounts/headers/000/126/222/original/6d7b41fdd92cfd6f.jpeg", - "followers_count" => 9451, - "following_count" => 132, - "statuses_count" => 3020, - "last_status_at" => "2020-08-24", - "emojis" => '' + "avatar" => $this->getAvatar(), + // "avatar_static" => "https://files.mastodon.social/accounts/avatars/000/126/222/original/50785214e44d10cc.jpeg", + "avatar_static" => $this->getAvatar(), + "header" => $this->getHeader(), + "header_static" => $this->getHeader(), + "followers_count" => $this->getInt('count.followers', $details), + "following_count" => $this->getInt('count.following', $details), + "statuses_count" => $this->getInt('count.post', $details), + "last_status_at" => $this->get('last_post_creation', $details), + "source" => [ + "privacy" => $this->getPrivacy(), + "sensitive" => $this->isSensitive(), + "language" => $this->getLanguage(), + "note" => $this->getDescription(), + "fields" => [], + "follow_requests_count" => 0 + ], + "emojis" => [], + "fields" => [] ]; return array_merge(parent::exportAsLocal(), $result); } - } diff --git a/lib/Model/Client/ClientApp.php b/lib/Model/Client/ClientApp.php index 3fd5988f..b2ac14c6 100644 --- a/lib/Model/Client/ClientApp.php +++ b/lib/Model/Client/ClientApp.php @@ -246,12 +246,18 @@ class ClientApp implements IQueryRow, JsonSerializable { 'id' => $this->getId(), 'name' => $this->getName(), 'website' => $this->getWebsite(), - 'redirect_uri' => $this->getRedirectUris(), 'scopes' => implode(' ', $this->getScopes()), 'client_id' => $this->getClientId(), 'client_secret' => $this->getClientSecret() ]; + $uris = $this->getRedirectUris(); + if (sizeof($uris) > 1) { + $arr['redirect_uris'] = $uris; + } else { + $arr['redirect_uri'] = $uris[0]; + } + return array_filter($arr); } diff --git a/lib/Model/Instance.php b/lib/Model/Instance.php index a1ab08d6..65550556 100644 --- a/lib/Model/Instance.php +++ b/lib/Model/Instance.php @@ -30,59 +30,464 @@ declare(strict_types=1); namespace OCA\Social\Model; +use daita\MySmallPhpTools\IQueryRow; use daita\MySmallPhpTools\Traits\TArrayTools; use JsonSerializable; +use OCA\Social\Model\ActivityPub\Actor\Person; + + +/** + * Class Instance + * + * @package OCA\Social\Model + */ +class Instance implements IQueryRow, JsonSerializable { -class Instance implements JsonSerializable { use TArrayTools; + /** @var bool */ + private $local = false; + + /** @var string */ + private $uri = ''; + /** @var string */ - private $address; + private $title = ''; + + /** @var string */ + private $version = ''; + + /** @var string */ + private $shortDescription = ''; + + /** @var string */ + private $description = ''; + + /** @var string */ + private $email = ''; + + /** @var array */ + private $urls = []; - /** @var InstancePath[] */ - private $instancePaths = []; + /** @var array */ + private $stats = []; - public function __construct(string $address = '') { - $this->address = $address; + /** @var array */ + private $usage = []; + + /** @var string */ + private $image = ''; + + /** @var array */ + private $languages = []; + + /** @var bool */ + private $registrations = false; + + /** @var bool */ + private $approvalRequired = false; + + /** @var bool */ + private $invitesEnabled = false; + + /** @var Person */ + private $contactAccount; + + /** @var string */ + private $accountPrim; + + + /** + * Instance constructor. + */ + public function __construct() { + } + + + /** + * @return bool + */ + public function isLocal(): bool { + return $this->local; + } + + /** + * @param bool $local + * + * @return Instance + */ + public function setLocal(bool $local): self { + $this->local = $local; + + return $this; } /** * @return string */ - public function getAddress(): string { - return $this->address; + public function getUri(): string { + return $this->uri; + } + + /** + * @param string $uri + * + * @return Instance + */ + public function setUri(string $uri): self { + $this->uri = $uri; + + return $this; } /** - * @param InstancePath $path + * @return string + */ + public function getTitle(): string { + return $this->title; + } + + /** + * @param string $title * * @return Instance */ - public function addPath(InstancePath $path): Instance { - $this->instancePaths[] = $path; + public function setTitle(string $title): self { + $this->title = $title; return $this; } + /** - * @return InstancePath[] + * @return string */ - public function getInstancePaths(): array { - return $this->instancePaths; + public function getVersion(): string { + return $this->version; } + /** + * @param string $version + * + * @return Instance + */ + public function setVersion(string $version): self { + $this->version = $version; + + return $this; + } + + /** + * @return string + */ + public function getShortDescription(): string { + return $this->shortDescription; + } + + /** + * @param string $shortDescription + * + * @return Instance + */ + public function setShortDescription(string $shortDescription): self { + $this->shortDescription = $shortDescription; + + return $this; + } + + + /** + * @return string + */ + public function getDescription(): string { + return $this->description; + } + + /** + * @param string $description + * + * @return Instance + */ + public function setDescription(string $description): self { + $this->description = $description; + + return $this; + } + + + /** + * @return string + */ + public function getEmail(): string { + return $this->email; + } + + /** + * @param string $email + * + * @return Instance + */ + public function setEmail(string $email): self { + $this->email = $email; + + return $this; + } + + + /** + * @return array + */ + public function getUrls(): array { + return $this->urls; + } + + /** + * @param array $urls + * + * @return Instance + */ + public function setUrls(array $urls): self { + $this->urls = $urls; + + return $this; + } + + + /** + * @return array + */ + public function getStats(): array { + return $this->stats; + } + + /** + * @param array $stats + * + * @return Instance + */ + public function setStats(array $stats): self { + $this->stats = $stats; + + return $this; + } + + + /** + * @return array + */ + public function getUsage(): array { + return $this->usage; + } + + /** + * @param array $usage + * + * @return Instance + */ + public function setUsage(array $usage): self { + $this->usage = $usage; + + return $this; + } + + + /** + * @return string + */ + public function getImage(): string { + return $this->image; + } + + /** + * @param string $image + * + * @return Instance + */ + public function setImage(string $image): self { + $this->image = $image; + + return $this; + } + + + /** + * @return array + */ + public function getLanguages(): array { + return $this->languages; + } + + /** + * @param array $languages + * + * @return Instance + */ + public function setLanguages(array $languages): self { + $this->languages = $languages; + + return $this; + } + + + /** + * @return bool + */ + public function isRegistrations(): bool { + return $this->registrations; + } + + /** + * @param bool $registrations + * + * @return Instance + */ + public function setRegistrations(bool $registrations): self { + $this->registrations = $registrations; + + return $this; + } + + + /** + * @return bool + */ + public function isApprovalRequired(): bool { + return $this->approvalRequired; + } + + /** + * @param bool $approvalRequired + * + * @return Instance + */ + public function setApprovalRequired(bool $approvalRequired): self { + $this->approvalRequired = $approvalRequired; + + return $this; + } + + + /** + * @return bool + */ + public function isInvitesEnabled(): bool { + return $this->invitesEnabled; + } + + /** + * @param bool $invitesEnabled + * + * @return Instance + */ + public function setInvitesEnabled(bool $invitesEnabled): self { + $this->invitesEnabled = $invitesEnabled; + + return $this; + } + + + /** + * @return bool + */ + public function hasContactAccount(): bool { + return ($this->contactAccount !== null); + } + + /** + * @return Person + */ + public function getContactAccount(): Person { + return $this->contactAccount; + } + + /** + * @param Person $account + * + * @return Instance + */ + public function setContactAccount(Person $account): self { + $this->contactAccount = $account; + + return $this; + } + + /** + * @return string + */ + public function getAccountPrim(): string { + return $this->accountPrim; + } + + /** + * @param string $prim + * + * @return Instance + */ + public function setAccountPrim(string $prim): self { + $this->accountPrim = $prim; + + return $this; + } + + + /** + * @param array $data + * + * @return $this + */ + public function importFromDatabase(array $data): self { + $this->setLocal($this->getBool('local', $data)); + $this->setUri($this->get('uri', $data)); + $this->setTitle($this->get('title', $data)); + $this->setVersion($this->get('version', $data)); + $this->setShortDescription($this->get('short_description', $data)); + $this->setDescription($this->get('description', $data)); + $this->setEmail($this->get('email', $data)); + $this->setUrls($this->getArray('urls', $data)); + $this->setStats($this->getArray('stats', $data)); + $this->setUsage($this->getArray('usage', $data)); + $this->setImage($this->get('image', $data)); + $this->setLanguages($this->getArray('languages', $data)); + $this->setAccountPrim($this->get('account_prim', $data)); + +// $contact = new Person(); +// $this->setContactAccount($contact); + + return $this; + } + + + /** + * @return array + */ public function jsonSerialize(): array { - return [ - 'address' => $this->address, - 'instancePaths' => $this->getInstancePaths() + $arr = [ + 'uri' => $this->getUri(), + 'title' => $this->getTitle(), + 'version' => $this->getVersion(), + 'short_description' => $this->getShortDescription(), + 'description' => $this->getDescription(), + 'email' => $this->getEmail(), + 'urls' => $this->getUrls(), + 'stats' => $this->getStats(), + 'thumbnail' => $this->getImage(), + 'languages' => $this->getLanguages(), + 'registrations' => $this->isRegistrations(), + 'approval_required' => $this->isApprovalRequired(), + 'invites_enabled' => $this->isInvitesEnabled() ]; - } + if ($this->hasContactAccount()) { + $arr['contact_account'] = $this->getContactAccount(); + } + + return $arr; + } } |