3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Object\Api\Twitter;
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Util\DateTimeFormat;
30 class DirectMessage extends BaseDataTransferObject
39 protected $recipient_id;
40 /** @var string (Datetime) */
41 protected $created_at;
43 protected $sender_screen_name = null;
45 protected $recipient_screen_name = null;
50 /** @var string|null */
53 protected $friendica_seen;
54 /** @var string|null */
55 protected $friendica_parent_uri = null;
58 * Creates a direct message record
62 * @param User $recipient
64 * @param string $title
66 public function __construct(array $mail, User $sender, User $recipient, string $text, string $title = null)
68 $this->id = (int)$mail['id'];
69 $this->created_at = DateTimeFormat::utc($mail['created'] ?? 'now', DateTimeFormat::API);
70 $this->title = $title;
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'] ?? '';
83 * Returns the current entity as an array
87 public function toArray(): array
89 $status = parent::toArray();
91 if (is_null($status['title'])) {
92 unset($status['title']);
95 unset($status['sender']['uid']);
96 unset($status['recipient']['uid']);