]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Api/Mastodon/Status.php
Merge branch 'develop' into mastodon-timeline-temporal-paging
[friendica.git] / src / Object / Api / Mastodon / Status.php
index 12fef7ac8f0676a7e3fb37b6bde1458e61a751b4..cefae5d2129cbdb8574c977fcc63c128800d0053 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -23,7 +23,9 @@ namespace Friendica\Object\Api\Mastodon;
 
 use Friendica\BaseDataTransferObject;
 use Friendica\Content\Text\BBCode;
+use Friendica\Model\Item;
 use Friendica\Object\Api\Mastodon\Status\Counts;
+use Friendica\Object\Api\Mastodon\Status\FriendicaExtension;
 use Friendica\Object\Api\Mastodon\Status\UserAttributes;
 use Friendica\Util\DateTimeFormat;
 
@@ -40,6 +42,8 @@ class Status extends BaseDataTransferObject
        protected $created_at;
        /** @var string|null */
        protected $in_reply_to_id = null;
+       /** @var Status|null - Fedilab extension, see issue https://github.com/friendica/friendica/issues/12672 */
+       protected $in_reply_to_status = null;
        /** @var string|null */
        protected $in_reply_to_account_id = null;
        /** @var bool */
@@ -74,6 +78,8 @@ class Status extends BaseDataTransferObject
        protected $content;
        /** @var Status|null */
        protected $reblog = null;
+       /** @var Status|null - Akkoma extension, see issue https://github.com/friendica/friendica/issues/12603 */
+       protected $quote = null;
        /** @var Application */
        protected $application = null;
        /** @var Account */
@@ -90,6 +96,8 @@ class Status extends BaseDataTransferObject
        protected $card = null;
        /** @var Poll|null */
        protected $poll = null;
+       /** @var FriendicaExtension */
+       protected $friendica;
 
        /**
         * Creates a status record from an item record.
@@ -97,23 +105,24 @@ class Status extends BaseDataTransferObject
         * @param array   $item
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card, array $attachments, array $reblog)
+       public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card, array $attachments, array $in_reply, array $reblog, FriendicaExtension $friendica, array $quote = null, array $poll = null)
        {
                $this->id         = (string)$item['uri-id'];
                $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::JSON);
 
-               if ($item['gravity'] == GRAVITY_COMMENT) {
+               if ($item['gravity'] == Item::GRAVITY_COMMENT) {
                        $this->in_reply_to_id         = (string)$item['thr-parent-id'];
+                       $this->in_reply_to_status     = $in_reply;
                        $this->in_reply_to_account_id = (string)$item['parent-author-id'];
                }
 
                $this->sensitive    = $sensitive;
-               $this->spoiler_text = $item['title'] ?: $item['content-warning'];
+               $this->spoiler_text = $item['title'] ?: $item['content-warning'] ?: '';
 
                $visibility = ['public', 'private', 'unlisted'];
                $this->visibility = $visibility[$item['private']];
 
-               $languages = json_decode($item['language'], true);
+               $languages = json_decode($item['language'] ?? '', true);
                if (is_array($languages)) {
                        reset($languages);
                        $this->language = key($languages);
@@ -131,8 +140,9 @@ class Status extends BaseDataTransferObject
                $this->muted = $userAttributes->muted;
                $this->bookmarked = $userAttributes->bookmarked;
                $this->pinned = $userAttributes->pinned;
-               $this->content = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API);
+               $this->content = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::MASTODON_API);
                $this->reblog = $reblog;
+               $this->quote = $quote;
                $this->application = $application->toArray();
                $this->account = $account->toArray();
                $this->media_attachments = $attachments;
@@ -140,7 +150,23 @@ class Status extends BaseDataTransferObject
                $this->tags = $tags;
                $this->emojis = [];
                $this->card = $card->toArray() ?: null;
-               $this->poll = null;
+               $this->poll = $poll;
+               $this->friendica = $friendica;
+       }
+
+       /**
+        * Returns the current created_at DateTime as an integer timestamp
+        * @return int
+        * @throws \Exception
+        */
+       public function createdAtTimestamp(): int
+       {
+               $result = strtotime($this->created_at);
+               if (!$result) {
+                       throw new \Exception('Unknown date-time format');
+               }
+
+               return $result;
        }
 
        /**
@@ -164,6 +190,14 @@ class Status extends BaseDataTransferObject
                        $status['reblog'] = null;
                }
 
+               if (empty($status['quote'])) {
+                       $status['quote'] = null;
+               }
+
+               if (empty($status['in_reply_to_status'])) {
+                       $status['in_reply_to_status'] = null;
+               }
+
                return $status;
        }
 }