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\Content\Text\HTML;
28 use Friendica\Model\Item;
29 use Friendica\Util\DateTimeFormat;
34 * @see https://docs.joinmastodon.org/entities/status
36 class Status extends BaseDataTransferObject
42 /** @var string (Datetime) */
43 protected $created_at;
45 protected $in_reply_to_status_id = null;
46 /** @var string|null */
47 protected $in_reply_to_status_id_str = null;
49 protected $in_reply_to_user_id = null;
50 /** @var string|null */
51 protected $in_reply_to_user_id_str = null;
52 /** @var string|null */
53 protected $in_reply_to_screen_name = null;
57 protected $friendica_author;
59 protected $friendica_owner;
61 protected $favorited = false;
62 /** @var Status|null */
63 protected $retweeted_status = null;
64 /** @var Status|null */
65 protected $quoted_status = null;
69 protected $statusnet_html;
71 protected $friendica_html;
73 protected $friendica_title;
77 protected $friendica_comments;
81 protected $external_url;
83 protected $statusnet_conversation_id;
85 protected $friendica_private;
86 /** @var Attachment */
87 protected $attachments = [];
89 protected $friendica_activities;
93 * Creates a status record from an item record.
96 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
98 public function __construct(array $item, User $author, User $owner, array $retweeted, array $quoted, array $attachments, array $geo, array $friendica_activities, array $entities, int $friendica_comments)
100 $this->id = (int)$item['id'];
101 $this->id_str = (string)$item['id'];
102 $this->statusnet_conversation_id = (int)$item['parent'];
104 $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::API);
106 if ($item['gravity'] == GRAVITY_COMMENT) {
107 $this->in_reply_to_status_id = (int)$item['thr-parent-id'];
108 $this->in_reply_to_status_id_str = (string)$item['thr-parent-id'];
109 $this->in_reply_to_user_id = (int)$item['parent-author-id'];
110 $this->in_reply_to_user_id_str = (string)$item['parent-author-id'];
111 $this->in_reply_to_screen_name = $item['parent-author-nick'];
114 $this->text = trim(HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::API), 0));
115 $this->friendica_title = $item['title'];
116 $this->statusnet_html = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API);
117 $this->friendica_html = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL);
118 $this->user = $author->toArray();
119 $this->friendica_author = $author->toArray();
120 $this->friendica_owner = $owner->toArray();
121 $this->truncated = false;
122 $this->friendica_private = $item['private'] == Item::PRIVATE;
123 $this->retweeted_status = $retweeted;
124 $this->quoted_status = $quoted;
125 $this->external_url = $item['plink'];
126 $this->favorited = (bool)$item['starred'];
127 $this->friendica_comments = $friendica_comments;
128 $this->source = $item['app'] ?: 'web';
129 $this->attachments = $attachments;
131 $this->friendica_activities = $friendica_activities;
132 $this->entities = $entities;
134 if ($this->source == 'web') {
135 $this->source = ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']);
136 } elseif (ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']) != $this->source) {
137 $this->source = trim($this->source. ' (' . ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']) . ')');
142 * Returns the current entity as an array
146 public function toArray(): array
148 $status = parent::toArray();
150 if (empty($status['retweeted_status'])) {
151 unset($status['retweeted_status']);
154 if (empty($status['quoted_status'])) {
155 unset($status['quoted_status']);