]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Twitter/DirectMessage.php
Merge pull request #13676 from MrPetovan/bug/13673-markers-json-output
[friendica.git] / src / Object / Api / Twitter / DirectMessage.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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\Twitter;
23
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Util\DateTimeFormat;
26
27 /**
28  * Class DirectMessage
29  */
30 class DirectMessage extends BaseDataTransferObject
31 {
32         /** @var int */
33         protected $id;
34         /** @var int */
35         protected $sender_id;
36         /** @var string */
37         protected $text;
38         /** @var int */
39         protected $recipient_id;
40         /** @var string (Datetime) */
41         protected $created_at;
42         /** @var string */
43         protected $sender_screen_name = null;
44         /** @var string */
45         protected $recipient_screen_name = null;
46         /** @var User */
47         protected $sender;
48         /** @var User */
49         protected $recipient;
50         /** @var string|null */
51         protected $title;
52         /** @var bool */
53         protected $friendica_seen;
54         /** @var string|null */
55         protected $friendica_parent_uri = null;
56
57         /**
58          * Creates a direct message record
59          *
60          * @param array  $mail
61          * @param User   $sender
62          * @param User   $recipient
63          * @param string $text
64          * @param string $title
65          */
66         public function __construct(array $mail, User $sender, User $recipient, string $text, string $title = null)
67         {
68                 $this->id                    = (int)$mail['id'];
69                 $this->created_at            = DateTimeFormat::utc($mail['created'] ?? 'now', DateTimeFormat::API);
70                 $this->title                 = $title;
71                 $this->text                  = $text;
72                 $this->sender                = $sender->toArray();
73                 $this->recipient             = $recipient->toArray();
74                 $this->sender_id             = (int)$this->sender['id'];
75                 $this->recipient_id          = (int)$this->recipient['id'];
76                 $this->sender_screen_name    = $this->sender['screen_name'];
77                 $this->recipient_screen_name = $this->recipient['screen_name'];
78                 $this->friendica_seen        = (bool)$mail['seen'] ?? false;
79                 $this->friendica_parent_uri  = $mail['parent-uri'] ?? '';
80         }
81
82         /**
83          * Returns the current entity as an array
84          *
85          * @return array
86          */
87         public function toArray(): array
88         {
89                 $status = parent::toArray();
90
91                 if (is_null($status['title'])) {
92                         unset($status['title']);
93                 }
94
95                 unset($status['sender']['uid']);
96                 unset($status['recipient']['uid']);
97
98                 return $status;
99         }
100 }