]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Mastodon/Notification.php
Correct format/style errors
[friendica.git] / src / Object / Api / Mastodon / Notification.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\Mastodon;
23
24 use Exception;
25 use Friendica\BaseDataTransferObject;
26 use Friendica\Network\HTTPException;
27 use Friendica\Util\DateTimeFormat;
28
29 /**
30  * Class Notification
31  *
32  * @see https://docs.joinmastodon.org/entities/notification/
33  */
34 class Notification extends BaseDataTransferObject
35 {
36         /* From the Mastodon documentation:
37          * - follow         = Someone followed you
38          * - follow_request = Someone requested to follow you
39          * - mention        = Someone mentioned you in their status
40          * - reblog         = Someone boosted one of your statuses
41          * - favourite      = Someone favourited one of your statuses
42          * - poll           = A poll you have voted in or created has ended
43          * - status         = Someone you enabled notifications for has posted a status
44          */
45         public const TYPE_FOLLOW       = 'follow';
46         public const TYPE_INTRODUCTION = 'follow_request';
47         public const TYPE_MENTION      = 'mention';
48         public const TYPE_RESHARE      = 'reblog';
49         public const TYPE_LIKE         = 'favourite';
50         public const TYPE_POLL         = 'poll';
51         public const TYPE_POST         = 'status';
52
53         /** @var string */
54         protected $id;
55         /** @var string One of the TYPE_* constant values */
56         protected $type;
57         /** @var string (Datetime) */
58         protected $created_at;
59         /** @var bool */
60         protected $dismissed;
61         /** @var Account */
62         protected $account;
63         /** @var Status|null */
64         protected $status = null;
65
66         /**
67          * Creates a notification record
68          *
69          * @throws HttpException\InternalServerErrorException|Exception
70          */
71         public function __construct(int $id, string $type, \DateTime $created_at, Account $account = null, Status $status = null, bool $dismissed = false)
72         {
73                 $this->id         = (string)$id;
74                 $this->type       = $type;
75                 $this->created_at = $created_at->format(DateTimeFormat::JSON);
76                 $this->account    = $account->toArray();
77                 $this->dismissed  = $dismissed;
78
79                 if (!empty($status)) {
80                         $this->status = $status->toArray();
81                 }
82         }
83
84         /**
85          * Returns the current entity as an array
86          *
87          * @return array
88          */
89         public function toArray(): array
90         {
91                 $notification = parent::toArray();
92
93                 if (!$notification['status']) {
94                         unset($notification['status']);
95                 }
96
97                 return $notification;
98         }
99 }