2021-05-09 11:50:05 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Object\Api\Mastodon;
|
|
|
|
|
2021-06-09 00:09:32 +02:00
|
|
|
use Exception;
|
2021-05-09 11:50:05 +00:00
|
|
|
use Friendica\BaseDataTransferObject;
|
2021-06-09 00:09:32 +02:00
|
|
|
use Friendica\Network\HTTPException;
|
2021-05-09 11:50:05 +00:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Notification
|
|
|
|
*
|
|
|
|
* @see https://docs.joinmastodon.org/entities/notification/
|
|
|
|
*/
|
|
|
|
class Notification extends BaseDataTransferObject
|
|
|
|
{
|
2021-09-17 23:15:23 -04:00
|
|
|
/* From the Mastodon documentation:
|
|
|
|
* - follow = Someone followed you
|
|
|
|
* - follow_request = Someone requested to follow you
|
|
|
|
* - mention = Someone mentioned you in their status
|
|
|
|
* - reblog = Someone boosted one of your statuses
|
|
|
|
* - favourite = Someone favourited one of your statuses
|
|
|
|
* - poll = A poll you have voted in or created has ended
|
|
|
|
* - status = Someone you enabled notifications for has posted a status
|
|
|
|
*/
|
|
|
|
public const TYPE_FOLLOW = 'follow';
|
|
|
|
public const TYPE_INTRODUCTION = 'follow_request';
|
|
|
|
public const TYPE_MENTION = 'mention';
|
|
|
|
public const TYPE_RESHARE = 'reblog';
|
|
|
|
public const TYPE_LIKE = 'favourite';
|
|
|
|
public const TYPE_POLL = 'poll';
|
|
|
|
public const TYPE_POST = 'status';
|
|
|
|
|
2021-05-09 11:50:05 +00:00
|
|
|
/** @var string */
|
|
|
|
protected $id;
|
2021-09-17 23:15:23 -04:00
|
|
|
/** @var string One of the TYPE_* constant values */
|
2021-05-09 11:50:05 +00:00
|
|
|
protected $type;
|
|
|
|
/** @var string (Datetime) */
|
|
|
|
protected $created_at;
|
|
|
|
/** @var Account */
|
|
|
|
protected $account;
|
|
|
|
/** @var Status|null */
|
|
|
|
protected $status = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a notification record
|
|
|
|
*
|
2021-06-09 00:09:32 +02:00
|
|
|
* @throws HttpException\InternalServerErrorException|Exception
|
2021-05-09 11:50:05 +00:00
|
|
|
*/
|
|
|
|
public function __construct(int $id, string $type, string $created_at, Account $account = null, Status $status = null)
|
|
|
|
{
|
|
|
|
$this->id = (string)$id;
|
|
|
|
$this->type = $type;
|
2021-06-02 03:32:42 +00:00
|
|
|
$this->created_at = DateTimeFormat::utc($created_at, DateTimeFormat::JSON);
|
2021-05-09 11:50:05 +00:00
|
|
|
$this->account = $account->toArray();
|
|
|
|
|
|
|
|
if (!empty($status)) {
|
|
|
|
$this->status = $status->toArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current entity as an array
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
$notification = parent::toArray();
|
|
|
|
|
|
|
|
if (!$notification['status']) {
|
|
|
|
unset($notification['status']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $notification;
|
|
|
|
}
|
|
|
|
}
|