]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Mastodon/Relationship.php
42d0e73119bc315f6efccc7f99adec658ec50127
[friendica.git] / src / Object / Api / Mastodon / Relationship.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Object\Api\Mastodon;
23
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Model\Contact;
26 use Friendica\Util\Network;
27
28 /**
29  * Class Relationship
30  *
31  * @see https://docs.joinmastodon.org/entities/relationship/
32  */
33 class Relationship extends BaseDataTransferObject
34 {
35         /** @var int */
36         protected $id;
37         /** @var bool */
38         protected $following = false;
39         /** @var bool */
40         protected $requested = false;
41         /**
42          * Unsupported
43          * @var bool
44          */
45         protected $endorsed = false;
46         /** @var bool */
47         protected $followed_by = false;
48         /** @var bool */
49         protected $muting = false;
50         /** @var bool */
51         protected $muting_notifications = false;
52         /**
53          * Unsupported
54          * @var bool
55          */
56         protected $showing_reblogs = true;
57         /** @var bool */
58         protected $notifying = false;
59         /** @var bool */
60         protected $blocking = false;
61         /** @var bool */
62         protected $domain_blocking = false;
63         /**
64          * Unsupported
65          * @var bool
66          */
67         protected $blocked_by = false;
68         /**
69          * Unsupported
70          * @var string
71          */
72         protected $note = '';
73
74         /**
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
79          */
80         public function __construct(int $contactId, array $contactRecord = [], bool $blocked = false, bool $muted = false)
81         {
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;
94                 $this->note                 = '';
95
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'];
104                 }
105
106                 return $this;
107         }
108 }