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\Mastodon;
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Content\Text\BBCode;
26 use Friendica\Object\Api\Mastodon\Status\Counts;
27 use Friendica\Object\Api\Mastodon\Status\UserAttributes;
28 use Friendica\Util\DateTimeFormat;
33 * @see https://docs.joinmastodon.org/entities/status
35 class Status extends BaseDataTransferObject
39 /** @var string (Datetime) */
40 protected $created_at;
41 /** @var string|null */
42 protected $in_reply_to_id = null;
43 /** @var string|null */
44 protected $in_reply_to_account_id = null;
46 protected $sensitive = false;
48 protected $spoiler_text = "";
49 /** @var string (Enum of public, unlisted, private, direct)*/
50 protected $visibility;
51 /** @var string|null */
52 protected $language = null;
55 /** @var string|null (URL)*/
56 protected $url = null;
58 protected $replies_count = 0;
60 protected $reblogs_count = 0;
62 protected $favourites_count = 0;
64 protected $favourited = false;
66 protected $reblogged = false;
68 protected $muted = false;
70 protected $bookmarked = false;
72 protected $pinned = false;
75 /** @var Status|null */
76 protected $reblog = null;
77 /** @var Application */
78 protected $application = null;
81 /** @var Attachment */
82 protected $media_attachments = [];
84 protected $mentions = [];
88 protected $emojis = [];
90 protected $card = null;
92 protected $poll = null;
95 * Creates a status record from an item record.
98 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
100 public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card, array $attachments, array $reblog)
102 $this->id = (string)$item['uri-id'];
103 $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::ATOM);
105 if ($item['gravity'] == GRAVITY_COMMENT) {
106 $this->in_reply_to_id = (string)$item['thr-parent-id'];
107 $this->in_reply_to_account_id = (string)$item['parent-author-id'];
110 $this->sensitive = $sensitive;
111 $this->spoiler_text = $item['title'];
113 $visibility = ['public', 'private', 'unlisted'];
114 $this->visibility = $visibility[$item['private']];
116 $languages = json_decode($item['language'], true);
117 $this->language = is_array($languages) ? array_key_first($languages) : null;
119 $this->uri = $item['uri'];
120 $this->url = $item['plink'] ?? null;
121 $this->replies_count = $counts->replies;
122 $this->reblogs_count = $counts->reblogs;
123 $this->favourites_count = $counts->favourites;
124 $this->favourited = $userAttributes->favourited;
125 $this->reblogged = $userAttributes->reblogged;
126 $this->muted = $userAttributes->muted;
127 $this->bookmarked = $userAttributes->bookmarked;
128 $this->pinned = $userAttributes->pinned;
129 $this->content = BBCode::convert($item['raw-body'] ?? $item['body'], false, BBCode::API);
130 $this->reblog = $reblog;
131 $this->application = $application->toArray();
132 $this->account = $account->toArray();
133 $this->media_attachments = $attachments;
134 $this->mentions = $mentions;
137 $this->card = $card->toArray() ?: null;
142 * Returns the current entity as an array
146 public function toArray(): array
148 $status = parent::toArray();
150 if (!$status['pinned']) {
151 unset($status['pinned']);
154 if (empty($status['application']['name'])) {
155 unset($status['application']);
158 if (empty($status['reblog'])) {
159 $status['reblog'] = null;