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;
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Model\Contact;
26 use Friendica\Util\Network;
31 * @see https://docs.joinmastodon.org/entities/relationship/
33 class Relationship extends BaseDataTransferObject
38 protected $following = false;
40 protected $requested = false;
45 protected $endorsed = false;
47 protected $followed_by = false;
49 protected $muting = false;
51 protected $muting_notifications = false;
56 protected $showing_reblogs = true;
58 protected $notifying = false;
60 protected $blocking = false;
62 protected $domain_blocking = false;
67 protected $blocked_by = false;
75 * @param int $contactId Contact row Id with uid != 0
76 * @param array $contactRecord Full Contact table record with uid != 0
77 * @param bool $blocked "true" if user is blocked
78 * @param bool $muted "true" if user is muted
80 public function __construct(int $contactId, array $contactRecord = [], bool $blocked = false, bool $muted = false)
82 $this->id = (string)$contactId;
83 $this->following = false;
84 $this->requested = false;
85 $this->endorsed = false;
86 $this->followed_by = false;
87 $this->muting = $muted;
88 $this->muting_notifications = false;
89 $this->showing_reblogs = true;
90 $this->notifying = false;
91 $this->blocking = $blocked;
92 $this->domain_blocking = Network::isUrlBlocked($contactRecord['url'] ?? '');
93 $this->blocked_by = false;
96 if ($contactRecord['uid'] != 0) {
97 $this->following = !$contactRecord['pending'] && in_array($contactRecord['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]);
98 $this->requested = (bool)($contactRecord['pending'] ?? false);
99 $this->followed_by = !$contactRecord['pending'] && in_array($contactRecord['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]);
100 $this->muting = (bool)($contactRecord['readonly'] ?? false) || $muted;
101 $this->notifying = (bool)$contactRecord['notify_new_posts'] ?? false;
102 $this->blocking = (bool)($contactRecord['blocked'] ?? false) || $blocked;
103 $this->note = $contactRecord['info'];