Merge pull request #7095 from annando/ap-connect

Switching from legacy DFRN connect to ActivityPub
This commit is contained in:
Hypolite Petovan 2019-05-05 09:37:43 -04:00 committed by GitHub
commit e17db489ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 169 additions and 111 deletions

View file

@ -24,7 +24,6 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\APContact;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\User;
@ -138,21 +137,16 @@ function dfrn_confirm_post(App $a, $handsfree = null)
$dfrn_confirm = $contact['confirm'];
$aes_allow = $contact['aes_allow'];
$network = ((strlen($contact['issued-id'])) ? Protocol::DFRN : Protocol::OSTATUS);
if ($contact['network']) {
$network = $contact['network'];
}
// an empty DFRN-ID tells us that it had been a request via AP from a Friendica contact
if (($network === Protocol::DFRN) && empty($dfrn_id) && !empty($contact['hub-verify'])) {
$apcontact = APContact::getByURL($contact['url']);
if (!empty($apcontact)) {
$network = Protocol::ACTIVITYPUB;
}
if (!empty($contact['protocol'])) {
$protocol = $contact['protocol'];
} elseif (($contact['network'] === Protocol::DFRN) && empty($dfrn_id)) {
$protocol = Contact::getProtocol($contact['url'], $contact['network']);
} else {
$protocol = $contact['network'];
}
if ($network === Protocol::DFRN) {
if ($protocol === Protocol::DFRN) {
/*
* Generate a key pair for all further communications with this person.
* We have a keypair for every contact, and a site key for unknown people.
@ -166,11 +160,8 @@ function dfrn_confirm_post(App $a, $handsfree = null)
$public_key = $res['pubkey'];
// Save the private key. Send them the public key.
q("UPDATE `contact` SET `prvkey` = '%s' WHERE `id` = %d AND `uid` = %d",
DBA::escape($private_key),
intval($contact_id),
intval($uid)
);
$fields = ['prvkey' => $private_key, 'protocol' => Protocol::DFRN];
DBA::update('contact', $fields, ['id' => $contact_id]);
$params = [];
@ -302,6 +293,8 @@ function dfrn_confirm_post(App $a, $handsfree = null)
if ($status != 0) {
return;
}
} else {
DBA::update('contact', ['protocol' => $protocol], ['id' => $contact_id]);
}
/*
@ -315,7 +308,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
Logger::log('dfrn_confirm: confirm - imported photos');
if ($network === Protocol::DFRN) {
if ($protocol === Protocol::DFRN) {
$new_relation = Contact::FOLLOWER;
if (($relation == Contact::SHARING) || ($duplex)) {
@ -344,7 +337,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
intval($contact_id)
);
} else {
if ($network == Protocol::ACTIVITYPUB) {
if ($protocol == Protocol::ACTIVITYPUB) {
ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid);
// Setting "pending" to true on a bidirectional contact request could create a problem when it isn't accepted on the other side
// Then we have got a situation where - although one direction is accepted - the contact still appears as pending.
@ -356,10 +349,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
$pending = false;
}
// $network !== Protocol::DFRN
$network = defaults($contact, 'network', Protocol::OSTATUS);
$arr = Probe::uri($contact['url'], $network);
$arr = Probe::uri($contact['url'], $protocol);
$notify = defaults($contact, 'notify' , $arr['notify']);
$poll = defaults($contact, 'poll' , $arr['poll']);
@ -369,7 +359,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
$new_relation = $contact['rel'];
$writable = $contact['writable'];
if (in_array($network, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
if (in_array($protocol, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
if ($duplex) {
$new_relation = Contact::FRIEND;
} else {
@ -386,7 +376,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
$fields = ['name-date' => DateTimeFormat::utcNow(),
'uri-date' => DateTimeFormat::utcNow(), 'addr' => $addr,
'notify' => $notify, 'poll' => $poll, 'blocked' => false,
'pending' => $pending, 'network' => $network,
'pending' => $pending, 'protocol' => $protocol,
'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation];
DBA::update('contact', $fields, ['id' => $contact_id]);
}
@ -397,7 +387,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
// reload contact info
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
if ((isset($new_relation) && $new_relation == Contact::FRIEND)) {
if (isset($new_relation) && ($new_relation == Contact::FRIEND)) {
if (DBA::isResult($contact) && ($contact['network'] === Protocol::DIASPORA)) {
$ret = Diaspora::sendShare($user, $contact);
Logger::log('share returns: ' . $ret);
@ -406,7 +396,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact['id']);
if ($network == Protocol::ACTIVITYPUB && $duplex) {
if (($protocol == Protocol::ACTIVITYPUB) && $duplex) {
ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
}

View file

@ -91,32 +91,34 @@ function follow_content(App $a)
$ret = Probe::uri($url);
if (($ret['network'] == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
$protocol = Contact::getProtocol($ret['url'], $ret['network']);
if (($protocol == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
$submit = '';
//$a->internalRedirect($_SESSION['return_path']);
// NOTREACHED
}
if (($ret['network'] == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
if (($protocol == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
notice(L10n::t("OStatus support is disabled. Contact can't be added."));
$submit = '';
//$a->internalRedirect($_SESSION['return_path']);
// NOTREACHED
}
if ($ret['network'] == Protocol::PHANTOM) {
if ($protocol == Protocol::PHANTOM) {
notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
$submit = '';
//$a->internalRedirect($_SESSION['return_path']);
// NOTREACHED
}
if ($ret['network'] == Protocol::MAIL) {
if ($protocol == Protocol::MAIL) {
$ret['url'] = $ret['addr'];
}
if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($r)) {
if (($protocol === Protocol::DFRN) && !DBA::isResult($r)) {
$request = $ret['request'];
$tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
} else {
@ -147,7 +149,7 @@ function follow_content(App $a)
$gcontact_id = $r[0]['id'];
}
if ($ret['network'] === Protocol::DIASPORA) {
if ($protocol === Protocol::DIASPORA) {
$r[0]['location'] = '';
$r[0]['about'] = '';
}