]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Api/Mastodon/Account.php
Merge pull request #10359 from annando/milliseconds
[friendica.git] / src / Object / Api / Mastodon / Account.php
index 7e726da97c78d1ef205ffc3fa9a0f12025c75bf7..f9c77675fa73680714af79ccea7b47e0ba28a861 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -22,7 +22,7 @@
 namespace Friendica\Object\Api\Mastodon;
 
 use Friendica\App\BaseURL;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
 use Friendica\Collection\Api\Mastodon\Fields;
 use Friendica\Content\Text\BBCode;
 use Friendica\Database\DBA;
@@ -34,7 +34,7 @@ use Friendica\Util\DateTimeFormat;
  *
  * @see https://docs.joinmastodon.org/entities/account
  */
-class Account extends BaseEntity
+class Account extends BaseDataTransferObject
 {
        /** @var string */
        protected $id;
@@ -99,11 +99,17 @@ class Account extends BaseEntity
                                $publicContact['nick'] :
                                $publicContact['addr'];
                $this->display_name    = $publicContact['name'];
-               $this->locked          = !empty($apcontact['manually-approve']);
+               $this->locked          = (bool)$publicContact['manually-approve'] ?? !empty($apcontact['manually-approve']);
                $this->bot             = ($publicContact['contact-type'] == Contact::TYPE_NEWS);
                $this->discoverable    = !$publicContact['unsearchable'];
                $this->group           = ($publicContact['contact-type'] == Contact::TYPE_COMMUNITY);
-               $this->created_at      = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::ATOM);
+
+               $publicContactCreated = $publicContact['created'] ?: DBA::NULL_DATETIME;
+               $userContactCreated = $userContact['created'] ?? DBA::NULL_DATETIME;
+
+               $created = $userContactCreated < $publicContactCreated && ($userContactCreated != DBA::NULL_DATETIME) ? $userContactCreated : $publicContactCreated;
+               $this->created_at      = DateTimeFormat::utc($created, DateTimeFormat::JSON);
+
                $this->note            = BBCode::convert($publicContact['about'], false);
                $this->url             = $publicContact['url'];
                $this->avatar          = $userContact['avatar'] ?? $publicContact['avatar'];
@@ -123,8 +129,23 @@ class Account extends BaseEntity
 
                // No custom emojis per account in Friendica
                $this->emojis          = [];
-               // No metadata fields in Friendica
                $this->fields          = $fields->getArrayCopy();
 
        }
+
+       /**
+        * Returns the current entity as an array
+        *
+        * @return array
+        */
+       public function toArray(): array
+       {
+               $account = parent::toArray();
+
+               if (empty($account['moved'])) {
+                       unset($account['moved']);
+               }
+
+               return $account;
+       }
 }