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\Mastodon;
25 use Friendica\BaseDataTransferObject;
26 use Friendica\Network\HTTPException;
27 use Friendica\Util\DateTimeFormat;
32 * @see https://docs.joinmastodon.org/entities/notification/
34 class Notification extends BaseDataTransferObject
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
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';
55 /** @var string One of the TYPE_* constant values */
57 /** @var string (Datetime) */
58 protected $created_at;
63 /** @var Status|null */
64 protected $status = null;
67 * Creates a notification record
69 * @throws HttpException\InternalServerErrorException|Exception
71 public function __construct(int $id, string $type, \DateTime $created_at, Account $account = null, Status $status = null, bool $dismissed = false)
73 $this->id = (string)$id;
75 $this->created_at = $created_at->format(DateTimeFormat::JSON);
76 $this->account = $account->toArray();
77 $this->dismissed = $dismissed;
79 if (!empty($status)) {
80 $this->status = $status->toArray();
85 * Returns the current entity as an array
89 public function toArray(): array
91 $notification = parent::toArray();
93 if (!$notification['status']) {
94 unset($notification['status']);