]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Mastodon/ScheduledStatus.php
e4f702a23414b6e9c3b3016178dbf8ab4fd7cf66
[friendica.git] / src / Object / Api / Mastodon / ScheduledStatus.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
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\BaseDataTransferObject;
25 use Friendica\Content\Text\BBCode;
26 use Friendica\Util\DateTimeFormat;
27
28 /**
29  * Class ScheduledStatus
30  *
31  * @see https://docs.joinmastodon.org/entities/scheduledstatus
32  */
33 class ScheduledStatus extends BaseDataTransferObject
34 {
35         /** @var string */
36         protected $id;
37         /** @var string (Datetime) */
38         protected $scheduled_at;
39         /** @var array */
40         protected $params = [
41                 'text'           => '',
42                 'media_ids'      => null,
43                 'sensitive'      => null,
44                 'spoiler_text'   => null,
45                 'visibility'     => '',
46                 'scheduled_at'   => null,
47                 'poll'           => null,
48                 'idempotency'    => null,
49                 'in_reply_to_id' => null,
50                 'application_id' => ''
51         ];
52         /** @var Attachment */
53         protected $media_attachments = [];
54
55         /**
56          * Creates a status record from a delayed-post record.
57          *
58          * @param array $delayed_post Record with the delayed post
59          * @param array $parameters   Parameters for the workerqueue entry for the delayed post
60          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
61          */
62         public function __construct(array $delayed_post, array $parameters, array $media_ids = null, int $in_reply_to_id = null)
63         {
64                 $visibility = ['public', 'private', 'unlisted'];
65
66                 $this->id           = (string)$delayed_post['id'];
67                 $this->scheduled_at = DateTimeFormat::utc($delayed_post['delayed'], DateTimeFormat::JSON);
68
69                 $this->params = [
70                         'text'           => BBCode::convert(BBCode::setMentionsToNicknames($parameters['item']['body'] ?? ''), false, BBCode::API),
71                         'media_ids'      => $media_ids,
72                         'sensitive'      => null,
73                         'spoiler_text'   => $parameters['item']['title'] ?? '',
74                         'visibility'     => $visibility[$parameters['item']['private']],
75                         'scheduled_at'   => $this->scheduled_at,
76                         'poll'           => null,
77                         'idempotency'    => null,
78                         'in_reply_to_id' => $in_reply_to_id,
79                         'application_id' => ''
80                 ];
81
82                 $this->media_attachments = [];
83         }
84 }