- $relation = $contact['rel'];
- $new_relation = $contact['rel'];
- $writable = $contact['writable'];
-
- if (!empty($contact['protocol'])) {
- $protocol = $contact['protocol'];
- } else {
- $protocol = $contact['network'];
- }
-
- if ($protocol == Protocol::ACTIVITYPUB) {
- ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid);
- }
-
- if (in_array($protocol, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
- if ($duplex) {
- $new_relation = Contact::FRIEND;
- } else {
- $new_relation = Contact::FOLLOWER;
- }
-
- if ($new_relation != Contact::FOLLOWER) {
- $writable = 1;
- }
- }
-
- $fields = ['name-date' => DateTimeFormat::utcNow(),
- 'uri-date' => DateTimeFormat::utcNow(),
- 'blocked' => false, 'pending' => false, 'protocol' => $protocol,
- 'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation];
- DBA::update('contact', $fields, ['id' => $cid]);
-
- if ($new_relation == Contact::FRIEND) {
- if ($protocol == Protocol::DIASPORA) {
- $user = User::getById($uid);
- $contact = Contact::getById($cid);
- $ret = Diaspora::sendShare($user, $contact);
- Logger::info('share returns', ['return' => $ret]);
- } elseif ($protocol == Protocol::ACTIVITYPUB) {
- ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
- }
- }