X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=fa6966a0eff8c66144cc4eaffc7d00cc022429b9;hb=dc49ad090eca1bf4e511091418166da6fe68009b;hp=d53126f6ff2aed90db3f1eda8c393f79f205a79b;hpb=b028de3aa3e14a398bfdec86f741428864a7bb11;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index d53126f6ff..fa6966a0ef 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -16,7 +16,9 @@ use Friendica\Database\DBA; use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Object\Image; +use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; +use Friendica\Protocol\DFRN; use Friendica\Protocol\OStatus; use Friendica\Protocol\PortableContact; use Friendica\Protocol\Salmon; @@ -528,13 +530,16 @@ class Contact extends BaseObject /** * @brief Sends an unfriend message. Does not remove the contact * - * @param array $user User unfriending - * @param array $contact Contact unfriended + * @param array $user User unfriending + * @param array $contact Contact unfriended + * @param boolean $dissolve Remove the contact on the remote side * @return void */ - public static function terminateFriendship(array $user, array $contact) + public static function terminateFriendship(array $user, array $contact, $dissolve = false) { - if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DFRN])) { + if (($contact['network'] == Protocol::DFRN) && $dissolve) { + DFRN::deliver($user, $contact, 'placeholder', true); + } elseif (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DFRN])) { // create an unfollow slap $item = []; $item['verb'] = NAMESPACE_OSTATUS . "/unfollow"; @@ -551,6 +556,12 @@ class Contact extends BaseObject } } elseif ($contact['network'] == Protocol::DIASPORA) { Diaspora::sendUnshare($user, $contact); + } elseif ($contact['network'] == Protocol::ACTIVITYPUB) { + ActivityPub\Transmitter::sendContactUndo($contact['url'], $user['uid']); + + if ($dissolve) { + ActivityPub\Transmitter::sendContactReject($contact['url'], $contact['hub-verify'], $user['uid']); + } } } @@ -771,7 +782,7 @@ class Contact extends BaseObject } if ((empty($profile["addr"]) || empty($profile["name"])) && (defaults($profile, "gid", 0) != 0) - && in_array($profile["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]) + && in_array($profile["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]) ) { Worker::add(PRIORITY_LOW, "UpdateGContact", $profile["gid"]); } @@ -1050,7 +1061,6 @@ class Contact extends BaseObject if (!x($contact, 'avatar')) { $update_contact = true; } - if (!$update_contact || $no_update) { return $contact_id; } @@ -1084,7 +1094,7 @@ class Contact extends BaseObject } // Last try in gcontact for unsupported networks - if (!in_array($data["network"], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::PUMPIO, Protocol::MAIL, Protocol::FEED])) { + if (!in_array($data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::PUMPIO, Protocol::MAIL, Protocol::FEED])) { if ($uid != 0) { return 0; } @@ -1312,33 +1322,27 @@ class Contact extends BaseObject require_once 'include/conversation.php'; - // There are no posts with "uid = 0" with connector networks - // This speeds up the query a lot - $r = q("SELECT `network`, `id` AS `author-id`, `contact-type` FROM `contact` - WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0", - DBA::escape(normalise_link($contact_url)) - ); + $cid = Self::getIdForURL($contact_url); - if (!DBA::isResult($r)) { + $contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]); + if (!DBA::isResult($contact)) { return ''; } - if (in_array($r[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) { + if (in_array($contact["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) { $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))"; } else { $sql = "`item`.`uid` = ?"; } - $author_id = intval($r[0]["author-id"]); - - $contact = ($r[0]["contact-type"] == self::ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id'); + $contact_field = ($contact["contact-type"] == self::ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id'); if ($thread_mode) { - $condition = ["`$contact` = ? AND `gravity` = ? AND " . $sql, - $author_id, GRAVITY_PARENT, local_user()]; + $condition = ["`$contact_field` = ? AND `gravity` = ? AND " . $sql, + $cid, GRAVITY_PARENT, local_user()]; } else { - $condition = ["`$contact` = ? AND `gravity` IN (?, ?) AND " . $sql, - $author_id, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()]; + $condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql, + $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()]; } $params = ['order' => ['created' => true], @@ -1491,10 +1495,11 @@ class Contact extends BaseObject } /** - * @param integer $id contact id + * @param integer $id contact id + * @param string $network Optional network we are probing for * @return boolean */ - public static function updateFromProbe($id) + public static function updateFromProbe($id, $network = '') { /* Warning: Never ever fetch the public key via Probe::uri and write it into the contacts. @@ -1507,10 +1512,10 @@ class Contact extends BaseObject return false; } - $ret = Probe::uri($contact["url"]); + $ret = Probe::uri($contact["url"], $network); // If Probe::uri fails the network code will be different - if ($ret["network"] != $contact["network"]) { + if (($ret["network"] != $contact["network"]) && ($ret["network"] != $network)) { return false; } @@ -1533,14 +1538,15 @@ class Contact extends BaseObject DBA::update( 'contact', [ - 'url' => $ret['url'], - 'nurl' => normalise_link($ret['url']), - 'addr' => $ret['addr'], - 'alias' => $ret['alias'], - 'batch' => $ret['batch'], - 'notify' => $ret['notify'], - 'poll' => $ret['poll'], - 'poco' => $ret['poco'] + 'url' => $ret['url'], + 'nurl' => normalise_link($ret['url']), + 'network' => $ret['network'], + 'addr' => $ret['addr'], + 'alias' => $ret['alias'], + 'batch' => $ret['batch'], + 'notify' => $ret['notify'], + 'poll' => $ret['poll'], + 'poco' => $ret['poco'] ], ['id' => $id] ); @@ -1682,7 +1688,7 @@ class Contact extends BaseObject $hidden = (($ret['network'] === Protocol::MAIL) ? 1 : 0); - if (in_array($ret['network'], [Protocol::MAIL, Protocol::DIASPORA])) { + if (in_array($ret['network'], [Protocol::MAIL, Protocol::DIASPORA, Protocol::ACTIVITYPUB])) { $writeable = 1; } @@ -1762,6 +1768,9 @@ class Contact extends BaseObject } elseif ($contact['network'] == Protocol::DIASPORA) { $ret = Diaspora::sendShare($a->user, $contact); logger('share returns: ' . $ret); + } elseif ($contact['network'] == Protocol::ACTIVITYPUB) { + $ret = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid); + logger('Follow returns: ' . $ret); } } @@ -1810,7 +1819,7 @@ class Contact extends BaseObject return $contact; } - public static function addRelationship($importer, $contact, $datarray, $item, $sharing = false) { + public static function addRelationship($importer, $contact, $datarray, $item = '', $sharing = false) { // Should always be set if (empty($datarray['author-id'])) { return; @@ -1823,7 +1832,7 @@ class Contact extends BaseObject return; } - $url = $pub_contact['url']; + $url = defaults($datarray, 'author-link', $pub_contact['url']); $name = $pub_contact['name']; $photo = $pub_contact['photo']; $nick = $pub_contact['nick']; @@ -1835,13 +1844,17 @@ class Contact extends BaseObject DBA::update('contact', ['rel' => self::FRIEND, 'writable' => true], ['id' => $contact['id'], 'uid' => $importer['uid']]); } + + if ($contact['network'] == Protocol::ACTIVITYPUB) { + ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']); + } + // send email notification to owner? } else { if (DBA::exists('contact', ['nurl' => normalise_link($url), 'uid' => $importer['uid'], 'pending' => true])) { logger('ignoring duplicated connection request from pending contact ' . $url); return; } - // create contact record q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`, `blocked`, `readonly`, `pending`, `writable`) @@ -1904,6 +1917,12 @@ class Contact extends BaseObject } elseif (DBA::isResult($user) && in_array($user['page-flags'], [self::PAGE_SOAPBOX, self::PAGE_FREELOVE, self::PAGE_COMMUNITY])) { $condition = ['uid' => $importer['uid'], 'url' => $url, 'pending' => true]; DBA::update('contact', ['pending' => false], $condition); + + $contact = DBA::selectFirst('contact', ['url', 'network', 'hub-verify'], ['id' => $contact_record['id']]); + + if ($contact['network'] == Protocol::ACTIVITYPUB) { + ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']); + } } } }