]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Api/Twitter/Status.php
Use the owner, not the author
[friendica.git] / src / Object / Api / Twitter / Status.php
index 2bfdb055d4e2980698b5c92d94964ad9e6665914..f9ce6a209d65ad003c97f1aa6c462ff39ee479bb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -23,7 +23,6 @@ namespace Friendica\Object\Api\Twitter;
 
 use Friendica\BaseDataTransferObject;
 use Friendica\Content\ContactSelector;
-use Friendica\Content\Text\BBCode;
 use Friendica\Model\Item;
 use Friendica\Util\DateTimeFormat;
 
@@ -34,22 +33,32 @@ use Friendica\Util\DateTimeFormat;
  */
 class Status extends BaseDataTransferObject
 {
-       /** @var int */
-       protected $id;
        /** @var string */
-       protected $id_str;
+       protected $text;
+       /** @var bool */
+       protected $truncated;
        /** @var string (Datetime) */
        protected $created_at;
        /** @var int|null */
        protected $in_reply_to_status_id = null;
        /** @var string|null */
        protected $in_reply_to_status_id_str = null;
+       /** @var string */
+       protected $source;
+       /** @var int */
+       protected $id;
+       /** @var string */
+       protected $id_str;
        /** @var int|null */
        protected $in_reply_to_user_id = null;
        /** @var string|null */
        protected $in_reply_to_user_id_str = null;
        /** @var string|null */
        protected $in_reply_to_screen_name = null;
+       /** @var array|null */
+       protected $geo;
+       /** @var bool */
+       protected $favorited = false;
        /** @var User */
        protected $user;
        /** @var User */
@@ -57,34 +66,27 @@ class Status extends BaseDataTransferObject
        /** @var User */
        protected $friendica_owner;
        /** @var bool */
-       protected $favorited = false;
-       /** @var Status|null */
-       protected $retweeted_status = null;
-       /** @var Status|null */
-       protected $quoted_status = null;
-       /** @var string */
-       protected $text;
+       protected $friendica_private;
        /** @var string */
        protected $statusnet_html;
+       /** @var int */
+       protected $statusnet_conversation_id;
        /** @var string */
-       protected $friendica_html;
+       protected $external_url;
+       /** @var array */
+       protected $friendica_activities;
        /** @var string */
        protected $friendica_title;
-       /** @var bool */
-       protected $truncated;
-       /** @var int */
-       protected $friendica_comments;
        /** @var string */
-       protected $source;
-       /** @var string */
-       protected $external_url;
+       protected $friendica_html;
        /** @var int */
-       protected $statusnet_conversation_id;
-       /** @var bool */
-       protected $friendica_private;
-       protected $geo;
+       protected $friendica_comments;
+       /** @var Status|null */
+       protected $retweeted_status = null;
+       /** @var Status|null */
+       protected $quoted_status = null;
        /** @var array */
-       protected $friendica_activities;
+       protected $attachments;
        /** @var array */
        protected $entities;
        /** @var array */
@@ -96,15 +98,15 @@ class Status extends BaseDataTransferObject
         * @param array   $item
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function __construct(string $text, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, int $friendica_comments)
+       public function __construct(string $text, string $statusnetHtml, string $friendicaHtml, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, array $attachments, int $friendica_comments, bool $liked)
        {
-               $this->id                        = (int)$item['id'];
-               $this->id_str                    = (string)$item['id'];
-               $this->statusnet_conversation_id = (int)$item['parent'];
+               $this->id                        = (int)$item['uri-id'];
+               $this->id_str                    = (string)$item['uri-id'];
+               $this->statusnet_conversation_id = (int)$item['parent-uri-id'];
 
                $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::API);
 
-               if ($item['gravity'] == GRAVITY_COMMENT) {
+               if ($item['gravity'] == Item::GRAVITY_COMMENT) {
                        $this->in_reply_to_status_id     = (int)$item['thr-parent-id'];
                        $this->in_reply_to_status_id_str = (string)$item['thr-parent-id'];
                        $this->in_reply_to_user_id       = (int)$item['parent-author-id'];
@@ -114,9 +116,9 @@ class Status extends BaseDataTransferObject
 
                $this->text                 = $text;
                $this->friendica_title      = $item['title'];
-               $this->statusnet_html       = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API);
-               $this->friendica_html       = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL);
-               $this->user                 = $author->toArray();
+               $this->statusnet_html       = $statusnetHtml;
+               $this->friendica_html       = $friendicaHtml;
+               $this->user                 = $owner->toArray();
                $this->friendica_author     = $author->toArray();
                $this->friendica_owner      = $owner->toArray();
                $this->truncated            = false;
@@ -124,18 +126,21 @@ class Status extends BaseDataTransferObject
                $this->retweeted_status     = $retweeted;
                $this->quoted_status        = $quoted;
                $this->external_url         = $item['plink'];
-               $this->favorited            = (bool)$item['starred'];
+               $this->favorited            = $liked;
                $this->friendica_comments   = $friendica_comments;
-               $this->source               = $item['app'] ?: 'web';
+               $this->source               = $item['app'];
                $this->geo                  = $geo;
                $this->friendica_activities = $friendica_activities;
+               $this->attachments          = $attachments;
                $this->entities             = $entities;
                $this->extended_entities    = $entities;
 
-               if ($this->source == 'web') {
-                       $this->source = ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']);
-               } elseif (ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']) != $this->source) {
-                       $this->source = trim($this->source. ' (' . ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']) . ')');
+               $origin = ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']);
+
+               if (empty($this->source)) {
+                       $this->source = $origin;
+               } elseif ($origin != $this->source) {
+                       $this->source = trim($this->source. ' (' . $origin . ')');
                }
        }
 
@@ -156,6 +161,23 @@ class Status extends BaseDataTransferObject
                        unset($status['quoted_status']);
                }
 
+               if (empty($status['geo'])) {
+                       $status['geo'] = null;
+               }
+
+               if (empty($status['entities'])) {
+                       $status['entities'] = null;
+               }
+
+               if (empty($status['extended_entities'])) {
+                       $status['extended_entities'] = null;
+               }
+
+               if (empty($status['attachments'])) {
+                       $status['attachments'] = null;
+               }
+
+
                return $status;
        }
 }