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\Model\Item;
27 use Friendica\Util\DateTimeFormat;
32 * @see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/tweet
34 class Status extends BaseDataTransferObject
40 /** @var string (Datetime) */
41 protected $created_at;
43 protected $in_reply_to_status_id = null;
44 /** @var string|null */
45 protected $in_reply_to_status_id_str = null;
53 protected $in_reply_to_user_id = null;
54 /** @var string|null */
55 protected $in_reply_to_user_id_str = null;
56 /** @var string|null */
57 protected $in_reply_to_screen_name = null;
58 /** @var array|null */
61 protected $favorited = false;
65 protected $friendica_author;
67 protected $friendica_owner;
69 protected $friendica_private;
71 protected $statusnet_html;
73 protected $statusnet_conversation_id;
75 protected $external_url;
77 protected $friendica_activities;
79 protected $friendica_title;
81 protected $friendica_html;
83 protected $friendica_comments;
84 /** @var Status|null */
85 protected $retweeted_status = null;
86 /** @var Status|null */
87 protected $quoted_status = null;
89 protected $attachments;
93 protected $extended_entities;
96 * Creates a status record from an item record.
99 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
101 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)
103 $this->id = (int)$item['id'];
104 $this->id_str = (string)$item['id'];
105 $this->statusnet_conversation_id = (int)$item['parent'];
107 $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::API);
109 if ($item['gravity'] == GRAVITY_COMMENT) {
110 $this->in_reply_to_status_id = (int)$item['thr-parent-id'];
111 $this->in_reply_to_status_id_str = (string)$item['thr-parent-id'];
112 $this->in_reply_to_user_id = (int)$item['parent-author-id'];
113 $this->in_reply_to_user_id_str = (string)$item['parent-author-id'];
114 $this->in_reply_to_screen_name = $item['parent-author-nick'];
118 $this->friendica_title = $item['title'];
119 $this->statusnet_html = $statusnetHtml;
120 $this->friendica_html = $friendicaHtml;
121 $this->user = $author->toArray();
122 $this->friendica_author = $author->toArray();
123 $this->friendica_owner = $owner->toArray();
124 $this->truncated = false;
125 $this->friendica_private = $item['private'] == Item::PRIVATE;
126 $this->retweeted_status = $retweeted;
127 $this->quoted_status = $quoted;
128 $this->external_url = $item['plink'];
129 $this->favorited = $liked;
130 $this->friendica_comments = $friendica_comments;
131 $this->source = $item['app'];
133 $this->friendica_activities = $friendica_activities;
134 $this->attachments = $attachments;
135 $this->entities = $entities;
136 $this->extended_entities = $entities;
138 $origin = ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']);
140 if (empty($this->source)) {
141 $this->source = $origin;
142 } elseif ($origin != $this->source) {
143 $this->source = trim($this->source. ' (' . $origin . ')');
148 * Returns the current entity as an array
152 public function toArray(): array
154 $status = parent::toArray();
156 if (empty($status['retweeted_status'])) {
157 unset($status['retweeted_status']);
160 if (empty($status['quoted_status'])) {
161 unset($status['quoted_status']);
164 if (empty($status['geo'])) {
165 $status['geo'] = null;
168 if (empty($status['entities'])) {
169 $status['entities'] = null;
172 if (empty($status['extended_entities'])) {
173 $status['extended_entities'] = null;
176 if (empty($status['attachments'])) {
177 $status['attachments'] = null;