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