3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Object\Api\Twitter;
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Content\ContactSelector;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Model\Item;
28 use Friendica\Util\DateTimeFormat;
33 * @see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/tweet
35 class Status extends BaseDataTransferObject
41 /** @var string (Datetime) */
42 protected $created_at;
44 protected $in_reply_to_status_id = null;
45 /** @var string|null */
46 protected $in_reply_to_status_id_str = null;
48 protected $in_reply_to_user_id = null;
49 /** @var string|null */
50 protected $in_reply_to_user_id_str = null;
51 /** @var string|null */
52 protected $in_reply_to_screen_name = null;
56 protected $friendica_author;
58 protected $friendica_owner;
60 protected $favorited = false;
61 /** @var Status|null */
62 protected $retweeted_status = null;
63 /** @var Status|null */
64 protected $quoted_status = null;
68 protected $statusnet_html;
70 protected $friendica_html;
72 protected $friendica_title;
76 protected $friendica_comments;
80 protected $external_url;
82 protected $statusnet_conversation_id;
84 protected $friendica_private;
87 protected $friendica_activities;
91 protected $extended_entities;
94 * Creates a status record from an item record.
97 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
99 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)
101 $this->id = (int)$item['id'];
102 $this->id_str = (string)$item['id'];
103 $this->statusnet_conversation_id = (int)$item['parent'];
105 $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::API);
107 if ($item['gravity'] == GRAVITY_COMMENT) {
108 $this->in_reply_to_status_id = (int)$item['thr-parent-id'];
109 $this->in_reply_to_status_id_str = (string)$item['thr-parent-id'];
110 $this->in_reply_to_user_id = (int)$item['parent-author-id'];
111 $this->in_reply_to_user_id_str = (string)$item['parent-author-id'];
112 $this->in_reply_to_screen_name = $item['parent-author-nick'];
116 $this->friendica_title = $item['title'];
117 $this->statusnet_html = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API);
118 $this->friendica_html = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL);
119 $this->user = $author->toArray();
120 $this->friendica_author = $author->toArray();
121 $this->friendica_owner = $owner->toArray();
122 $this->truncated = false;
123 $this->friendica_private = $item['private'] == Item::PRIVATE;
124 $this->retweeted_status = $retweeted;
125 $this->quoted_status = $quoted;
126 $this->external_url = $item['plink'];
127 $this->favorited = (bool)$item['starred'];
128 $this->friendica_comments = $friendica_comments;
129 $this->source = $item['app'] ?: 'web';
131 $this->friendica_activities = $friendica_activities;
132 $this->entities = $entities;
133 $this->extended_entities = $entities;
135 if ($this->source == 'web') {
136 $this->source = ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']);
137 } elseif (ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']) != $this->source) {
138 $this->source = trim($this->source. ' (' . ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']) . ')');
143 * Returns the current entity as an array
147 public function toArray(): array
149 $status = parent::toArray();
151 if (empty($status['retweeted_status'])) {
152 unset($status['retweeted_status']);
155 if (empty($status['quoted_status'])) {
156 unset($status['quoted_status']);