friendica/src/Object/Api/Mastodon/Relationship.php

109 lines
3.3 KiB
PHP
Raw Normal View History

<?php
2020-02-09 15:45:36 +01:00
/**
2021-03-29 08:40:20 +02:00
* @copyright Copyright (C) 2010-2021, the Friendica project
2020-02-09 15:45:36 +01:00
*
* @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;
use Friendica\BaseDataTransferObject;
use Friendica\Model\Contact;
use Friendica\Util\Network;
/**
* Class Relationship
*
2021-05-15 17:02:15 +02:00
* @see https://docs.joinmastodon.org/entities/relationship/
*/
class Relationship extends BaseDataTransferObject
{
/** @var int */
protected $id;
/** @var bool */
protected $following = false;
/** @var bool */
2021-05-14 23:51:32 +02:00
protected $requested = false;
/**
* Unsupported
* @var bool
*/
protected $endorsed = false;
/** @var bool */
2021-05-14 23:51:32 +02:00
protected $followed_by = false;
/** @var bool */
protected $muting = false;
/** @var bool */
protected $muting_notifications = false;
2021-05-14 23:51:32 +02:00
/**
* Unsupported
* @var bool
*/
protected $showing_reblogs = true;
/** @var bool */
2021-05-14 23:51:32 +02:00
protected $notifying = false;
/** @var bool */
protected $blocking = false;
/** @var bool */
protected $domain_blocking = false;
/**
* Unsupported
* @var bool
*/
2021-05-14 23:51:32 +02:00
protected $blocked_by = false;
/**
* Unsupported
2021-05-14 23:51:32 +02:00
* @var string
*/
2021-05-14 23:51:32 +02:00
protected $note = '';
/**
2021-05-15 17:02:15 +02:00
* @param int $contactId Contact row Id with uid != 0
* @param array $contactRecord Full Contact table record with uid != 0
2021-05-14 23:51:32 +02:00
* @param bool $blocked "true" if user is blocked
* @param bool $muted "true" if user is muted
*/
2021-05-15 17:02:15 +02:00
public function __construct(int $contactId, array $contactRecord = [], bool $blocked = false, bool $muted = false)
{
2021-05-15 17:02:15 +02:00
$this->id = $contactId;
$this->following = false;
$this->requested = false;
2021-05-14 23:51:32 +02:00
$this->endorsed = false;
2021-05-15 17:02:15 +02:00
$this->followed_by = false;
$this->muting = $muted;
$this->muting_notifications = false;
2021-05-14 23:51:32 +02:00
$this->showing_reblogs = true;
2021-05-15 17:02:15 +02:00
$this->notifying = false;
$this->blocking = $blocked;
$this->domain_blocking = Network::isUrlBlocked($contactRecord['url'] ?? '');
2021-05-14 23:51:32 +02:00
$this->blocked_by = false;
$this->note = '';
2021-05-15 17:02:15 +02:00
if ($contactRecord['uid'] != 0) {
$this->following = in_array($contactRecord['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]);
$this->requested = (bool)($contactRecord['pending'] ?? false);
$this->followed_by = in_array($contactRecord['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]);
$this->muting = (bool)($contactRecord['readonly'] ?? false) || $muted;
$this->notifying = (bool)$contactRecord['notify_new_posts'] ?? false;
$this->blocking = (bool)($contactRecord['blocked'] ?? false) || $blocked;
$this->note = $contactRecord['info'];
}
return $this;
}
}