]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Mastodon/Status.php
Merge remote-tracking branch 'friendica/stable' into develop
[friendica.git] / src / Object / Api / Mastodon / Status.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Object\Api\Mastodon;
23
24 use Friendica\BaseEntity;
25 use Friendica\Content\Text\BBCode;
26 use Friendica\Object\Api\Mastodon\Status\Counts;
27 use Friendica\Util\DateTimeFormat;
28
29 /**
30  * Class Status
31  *
32  * @see https://docs.joinmastodon.org/entities/status
33  */
34 class Status extends BaseEntity
35 {
36         /** @var string */
37         protected $id;
38         /** @var string (Datetime) */
39         protected $created_at;
40         /** @var string|null */
41         protected $in_reply_to_id = null;
42         /** @var string|null */
43         protected $in_reply_to_account_id = null;
44         /** @var bool */
45         protected $sensitive = false;
46         /** @var string */
47         protected $spoiler_text = "";
48         /** @var string (Enum of public, unlisted, private, direct)*/
49         protected $visibility;
50         /** @var string|null */
51         protected $language = null;
52         /** @var string */
53         protected $uri;
54         /** @var string|null (URL)*/
55         protected $url = null;
56         /** @var int */
57         protected $replies_count = 0;
58         /** @var int */
59         protected $reblogs_count = 0;
60         /** @var int */
61         protected $favourites_count = 0;
62         /** @var bool */
63         protected $favourited = false;
64         /** @var bool */
65         protected $reblogged = false;
66         /** @var bool */
67         protected $muted = false;
68         /** @var bool */
69         protected $bookmarked = false;
70         /** @var bool */
71         protected $pinned = false;
72         /** @var string */
73         protected $content;
74         /** @var Status|null */
75         protected $reblog = null;
76         /** @var Application */
77         protected $application = null;
78         /** @var Account */
79         protected $account;
80         /** @var Attachment */
81         protected $media_attachments = [];
82         /** @var Mention */
83         protected $mentions = [];
84         /** @var Tag */
85         protected $tags = [];
86         /** @var Emoji[] */
87         protected $emojis = [];
88         /** @var Card|null */
89         protected $card = null;
90         /** @var Poll|null */
91         protected $poll = null;
92
93         /**
94          * Creates a status record from an item record.
95          *
96          * @param array   $item
97          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
98          */
99         public function __construct(array $item, Account $account, Counts $counts)
100         {
101                 $this->id         = (string)$item['uri-id'];
102                 $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::ATOM);
103
104                 if ($item['gravity'] == GRAVITY_COMMENT) {
105                         $this->in_reply_to_id         = (string)$item['thr-parent-id'];
106                         $this->in_reply_to_account_id = (string)$item['parent-author-id'];
107                 }
108
109                 $this->sensitive = false;
110                 $this->spoiler_text = $item['title'];
111
112                 $visibility = ['public', 'private', 'unlisted'];
113                 $this->visibility = $visibility[$item['private']];
114
115                 $this->language = null;
116                 $this->uri = $item['uri'];
117                 $this->url = $item['plink'] ?? null;
118                 $this->replies_count = $counts->replies;
119                 $this->reblogs_count = $counts->reblogs;
120                 $this->favourites_count = $counts->favourites;
121                 $this->favourited = false;
122                 $this->reblogged = false;
123                 $this->muted = false;
124                 $this->bookmarked = false;
125                 $this->pinned = false;
126                 $this->content = BBCode::convert($item['body'], false);
127                 $this->reblog = null;
128                 $this->application = null;
129                 $this->account = $account->toArray();
130                 $this->media_attachments = [];
131                 $this->mentions = [];
132                 $this->tags = [];
133                 $this->emojis = [];
134                 $this->card = null;
135                 $this->poll = null;
136         }
137 }