3 * @copyright Copyright (C) 2010-2022, 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;
54 protected $in_reply_to_user_id = null;
55 /** @var string|null */
56 protected $in_reply_to_user_id_str = null;
57 /** @var string|null */
58 protected $in_reply_to_screen_name = null;
59 /** @var array|null */
62 protected $favorited = false;
66 protected $friendica_author;
68 protected $friendica_owner;
70 protected $friendica_private;
72 protected $statusnet_html;
74 protected $statusnet_conversation_id;
76 protected $external_url;
78 protected $friendica_activities;
80 protected $friendica_title;
82 protected $friendica_html;
84 protected $friendica_comments;
85 /** @var Status|null */
86 protected $retweeted_status = null;
87 /** @var Status|null */
88 protected $quoted_status = null;
90 protected $attachments;
94 protected $extended_entities;
97 * Creates a status record from an item record.
100 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
102 public function __construct(string $text, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, array $attachments, int $friendica_comments, bool $liked)
104 $this->id = (int)$item['id'];
105 $this->id_str = (string)$item['id'];
106 $this->statusnet_conversation_id = (int)$item['parent'];
108 $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::API);
110 if ($item['gravity'] == GRAVITY_COMMENT) {
111 $this->in_reply_to_status_id = (int)$item['thr-parent-id'];
112 $this->in_reply_to_status_id_str = (string)$item['thr-parent-id'];
113 $this->in_reply_to_user_id = (int)$item['parent-author-id'];
114 $this->in_reply_to_user_id_str = (string)$item['parent-author-id'];
115 $this->in_reply_to_screen_name = $item['parent-author-nick'];
119 $this->friendica_title = $item['title'];
120 $this->statusnet_html = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API);
121 $this->friendica_html = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL);
122 $this->user = $author->toArray();
123 $this->friendica_author = $author->toArray();
124 $this->friendica_owner = $owner->toArray();
125 $this->truncated = false;
126 $this->friendica_private = $item['private'] == Item::PRIVATE;
127 $this->retweeted_status = $retweeted;
128 $this->quoted_status = $quoted;
129 $this->external_url = $item['plink'];
130 $this->favorited = $liked;
131 $this->friendica_comments = $friendica_comments;
132 $this->source = $item['app'];
134 $this->friendica_activities = $friendica_activities;
135 $this->attachments = $attachments;
136 $this->entities = $entities;
137 $this->extended_entities = $entities;
139 $origin = ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']);
141 if (empty($this->source)) {
142 $this->source = $origin;
143 } elseif ($origin != $this->source) {
144 $this->source = trim($this->source. ' (' . $origin . ')');
149 * Returns the current entity as an array
153 public function toArray(): array
155 $status = parent::toArray();
157 if (empty($status['retweeted_status'])) {
158 unset($status['retweeted_status']);
161 if (empty($status['quoted_status'])) {
162 unset($status['quoted_status']);
165 if (empty($status['geo'])) {
166 $status['geo'] = null;
169 if (empty($status['entities'])) {
170 $status['entities'] = null;
173 if (empty($status['extended_entities'])) {
174 $status['extended_entities'] = null;
177 if (empty($status['attachments'])) {
178 $status['attachments'] = null;