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