X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FObject%2FApi%2FMastodon%2FRelationship.php;h=42d0e73119bc315f6efccc7f99adec658ec50127;hb=32bb0976046ef9fa2296d0aeb39a01b0b916dc1e;hp=146ad212b402bea380ea42708cc4e3af03d7f72f;hpb=0de8e4db080b5739d77d6394eb5c2904e5d1b66f;p=friendica.git diff --git a/src/Object/Api/Mastodon/Relationship.php b/src/Object/Api/Mastodon/Relationship.php index 146ad212b4..42d0e73119 100644 --- a/src/Object/Api/Mastodon/Relationship.php +++ b/src/Object/Api/Mastodon/Relationship.php @@ -1,59 +1,107 @@ . + * + */ namespace Friendica\Object\Api\Mastodon; -use Friendica\BaseEntity; +use Friendica\BaseDataTransferObject; use Friendica\Model\Contact; use Friendica\Util\Network; /** * Class Relationship * - * @see https://docs.joinmastodon.org/api/entities/#relationship + * @see https://docs.joinmastodon.org/entities/relationship/ */ -class Relationship extends BaseEntity +class Relationship extends BaseDataTransferObject { /** @var int */ protected $id; /** @var bool */ protected $following = false; /** @var bool */ - protected $followed_by = false; + protected $requested = false; + /** + * Unsupported + * @var bool + */ + protected $endorsed = false; /** @var bool */ - protected $blocking = false; + protected $followed_by = false; /** @var bool */ protected $muting = false; /** @var bool */ protected $muting_notifications = false; + /** + * Unsupported + * @var bool + */ + protected $showing_reblogs = true; /** @var bool */ - protected $requested = false; + protected $notifying = false; + /** @var bool */ + protected $blocking = false; /** @var bool */ protected $domain_blocking = false; /** * Unsupported * @var bool */ - protected $showing_reblogs = true; + protected $blocked_by = false; /** * Unsupported - * @var bool + * @var string */ - protected $endorsed = false; + protected $note = ''; /** - * @param int $userContactId Contact row Id with uid != 0 - * @param array $userContact Full Contact table record with uid != 0 + * @param int $contactId Contact row Id with uid != 0 + * @param array $contactRecord Full Contact table record with uid != 0 + * @param bool $blocked "true" if user is blocked + * @param bool $muted "true" if user is muted */ - public function __construct(int $userContactId, array $userContact = []) + public function __construct(int $contactId, array $contactRecord = [], bool $blocked = false, bool $muted = false) { - $this->id = $userContactId; - $this->following = in_array($userContact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]); - $this->followed_by = in_array($userContact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]); - $this->blocking = (bool)$userContact['blocked'] ?? false; - $this->muting = (bool)$userContact['readonly'] ?? false; - $this->muting_notifications = (bool)$userContact['readonly'] ?? false; - $this->requested = (bool)$userContact['pending'] ?? false; - $this->domain_blocking = Network::isUrlBlocked($userContact['url'] ?? ''); + $this->id = (string)$contactId; + $this->following = false; + $this->requested = false; + $this->endorsed = false; + $this->followed_by = false; + $this->muting = $muted; + $this->muting_notifications = false; + $this->showing_reblogs = true; + $this->notifying = false; + $this->blocking = $blocked; + $this->domain_blocking = Network::isUrlBlocked($contactRecord['url'] ?? ''); + $this->blocked_by = false; + $this->note = ''; + + if ($contactRecord['uid'] != 0) { + $this->following = !$contactRecord['pending'] && in_array($contactRecord['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]); + $this->requested = (bool)($contactRecord['pending'] ?? false); + $this->followed_by = !$contactRecord['pending'] && 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; }