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

@ -34,7 +34,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1310); define('DB_UPDATE_VERSION', 1311);
} }
return [ return [
@ -74,6 +74,7 @@ return [
"alias" => ["type" => "varchar(255)", "comment" => ""], "alias" => ["type" => "varchar(255)", "comment" => ""],
"pubkey" => ["type" => "text", "comment" => ""], "pubkey" => ["type" => "text", "comment" => ""],
"baseurl" => ["type" => "varchar(255)", "comment" => "baseurl of the ap contact"], "baseurl" => ["type" => "varchar(255)", "comment" => "baseurl of the ap contact"],
"generator" => ["type" => "varchar(255)", "comment" => "Name of the contact's system"],
"updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""] "updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""]
], ],
"indexes" => [ "indexes" => [
@ -185,7 +186,8 @@ return [
"remote_self" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "remote_self" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"rel" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "The kind of the relation between the user and the contact"], "rel" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "The kind of the relation between the user and the contact"],
"duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network protocol of the contact"], "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network of the contact"],
"protocol" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Protocol of the contact"],
"name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"], "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"],
"nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"], "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"],
"location" => ["type" => "varchar(255)", "default" => "", "comment" => ""], "location" => ["type" => "varchar(255)", "default" => "", "comment" => ""],

View File

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2019.06-dev (Dalmatian Bellflower) -- Friendica 2019.06-dev (Dalmatian Bellflower)
-- DB_UPDATE_VERSION 1310 -- DB_UPDATE_VERSION 1311
-- ------------------------------------------ -- ------------------------------------------
@ -40,6 +40,7 @@ CREATE TABLE IF NOT EXISTS `apcontact` (
`alias` varchar(255) COMMENT '', `alias` varchar(255) COMMENT '',
`pubkey` text COMMENT '', `pubkey` text COMMENT '',
`baseurl` varchar(255) COMMENT 'baseurl of the ap contact', `baseurl` varchar(255) COMMENT 'baseurl of the ap contact',
`generator` varchar(255) COMMENT 'Name of the contact\'s system',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
PRIMARY KEY(`url`), PRIMARY KEY(`url`),
INDEX `addr` (`addr`(32)), INDEX `addr` (`addr`(32)),
@ -143,7 +144,8 @@ CREATE TABLE IF NOT EXISTS `contact` (
`remote_self` boolean NOT NULL DEFAULT '0' COMMENT '', `remote_self` boolean NOT NULL DEFAULT '0' COMMENT '',
`rel` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'The kind of the relation between the user and the contact', `rel` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'The kind of the relation between the user and the contact',
`duplex` boolean NOT NULL DEFAULT '0' COMMENT '', `duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
`network` char(4) NOT NULL DEFAULT '' COMMENT 'Network protocol of the contact', `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network of the contact',
`protocol` char(4) NOT NULL DEFAULT '' COMMENT 'Protocol of the contact',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by', `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by',
`nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact', `nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact',
`location` varchar(255) DEFAULT '' COMMENT '', `location` varchar(255) DEFAULT '' COMMENT '',

View File

@ -24,7 +24,6 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\APContact;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\User; use Friendica\Model\User;
@ -138,21 +137,16 @@ function dfrn_confirm_post(App $a, $handsfree = null)
$dfrn_confirm = $contact['confirm']; $dfrn_confirm = $contact['confirm'];
$aes_allow = $contact['aes_allow']; $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 // 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'])) { if (!empty($contact['protocol'])) {
$apcontact = APContact::getByURL($contact['url']); $protocol = $contact['protocol'];
if (!empty($apcontact)) { } elseif (($contact['network'] === Protocol::DFRN) && empty($dfrn_id)) {
$network = Protocol::ACTIVITYPUB; $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. * 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. * 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']; $public_key = $res['pubkey'];
// Save the private key. Send them the public key. // Save the private key. Send them the public key.
q("UPDATE `contact` SET `prvkey` = '%s' WHERE `id` = %d AND `uid` = %d", $fields = ['prvkey' => $private_key, 'protocol' => Protocol::DFRN];
DBA::escape($private_key), DBA::update('contact', $fields, ['id' => $contact_id]);
intval($contact_id),
intval($uid)
);
$params = []; $params = [];
@ -302,6 +293,8 @@ function dfrn_confirm_post(App $a, $handsfree = null)
if ($status != 0) { if ($status != 0) {
return; 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'); Logger::log('dfrn_confirm: confirm - imported photos');
if ($network === Protocol::DFRN) { if ($protocol === Protocol::DFRN) {
$new_relation = Contact::FOLLOWER; $new_relation = Contact::FOLLOWER;
if (($relation == Contact::SHARING) || ($duplex)) { if (($relation == Contact::SHARING) || ($duplex)) {
@ -344,7 +337,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
intval($contact_id) intval($contact_id)
); );
} else { } else {
if ($network == Protocol::ACTIVITYPUB) { if ($protocol == Protocol::ACTIVITYPUB) {
ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid); 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 // 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. // 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; $pending = false;
} }
// $network !== Protocol::DFRN $arr = Probe::uri($contact['url'], $protocol);
$network = defaults($contact, 'network', Protocol::OSTATUS);
$arr = Probe::uri($contact['url'], $network);
$notify = defaults($contact, 'notify' , $arr['notify']); $notify = defaults($contact, 'notify' , $arr['notify']);
$poll = defaults($contact, 'poll' , $arr['poll']); $poll = defaults($contact, 'poll' , $arr['poll']);
@ -369,7 +359,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
$new_relation = $contact['rel']; $new_relation = $contact['rel'];
$writable = $contact['writable']; $writable = $contact['writable'];
if (in_array($network, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) { if (in_array($protocol, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
if ($duplex) { if ($duplex) {
$new_relation = Contact::FRIEND; $new_relation = Contact::FRIEND;
} else { } else {
@ -386,7 +376,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
$fields = ['name-date' => DateTimeFormat::utcNow(), $fields = ['name-date' => DateTimeFormat::utcNow(),
'uri-date' => DateTimeFormat::utcNow(), 'addr' => $addr, 'uri-date' => DateTimeFormat::utcNow(), 'addr' => $addr,
'notify' => $notify, 'poll' => $poll, 'blocked' => false, 'notify' => $notify, 'poll' => $poll, 'blocked' => false,
'pending' => $pending, 'network' => $network, 'pending' => $pending, 'protocol' => $protocol,
'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation]; 'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation];
DBA::update('contact', $fields, ['id' => $contact_id]); DBA::update('contact', $fields, ['id' => $contact_id]);
} }
@ -397,7 +387,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
// reload contact info // reload contact info
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id]); $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)) { if (DBA::isResult($contact) && ($contact['network'] === Protocol::DIASPORA)) {
$ret = Diaspora::sendShare($user, $contact); $ret = Diaspora::sendShare($user, $contact);
Logger::log('share returns: ' . $ret); 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']); 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); ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
} }

View File

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

View File

@ -167,10 +167,15 @@ class APContact extends BaseObject
$apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers'); $apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
if (!empty($compacted['as:generator'])) {
$apcontact['baseurl'] = JsonLD::fetchElement($compacted['as:generator'], 'as:url', '@id');
$apcontact['generator'] = JsonLD::fetchElement($compacted['as:generator'], 'as:name', '@value');
}
// To-Do // To-Do
// Unhandled // Unhandled
// @context, tag, attachment, image, nomadicLocations, signature, following, followers, featured, movedTo, liked // tag, attachment, image, nomadicLocations, signature, featured, movedTo, liked
// Unhandled from Misskey // Unhandled from Misskey
// sharedInbox, isCat // sharedInbox, isCat
@ -185,6 +190,9 @@ class APContact extends BaseObject
$apcontact['baseurl'] = Network::unparseURL($parts); $apcontact['baseurl'] = Network::unparseURL($parts);
} else { } else {
$apcontact['addr'] = null; $apcontact['addr'] = null;
}
if (empty($apcontact['baseurl'])) {
$apcontact['baseurl'] = null; $apcontact['baseurl'] = null;
} }

View File

@ -689,9 +689,15 @@ class Contact extends BaseObject
if (empty($contact['network'])) { if (empty($contact['network'])) {
return; return;
} }
if (($contact['network'] == Protocol::DFRN) && $dissolve) {
$protocol = $contact['network'];
if (($protocol == Protocol::DFRN) && !self::isLegacyDFRNContact($contact)) {
$protocol = Protocol::ACTIVITYPUB;
}
if (($protocol == Protocol::DFRN) && $dissolve) {
DFRN::deliver($user, $contact, 'placeholder', true); DFRN::deliver($user, $contact, 'placeholder', true);
} elseif (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DFRN])) { } elseif (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
// create an unfollow slap // create an unfollow slap
$item = []; $item = [];
$item['verb'] = NAMESPACE_OSTATUS . "/unfollow"; $item['verb'] = NAMESPACE_OSTATUS . "/unfollow";
@ -706,9 +712,9 @@ class Contact extends BaseObject
if (!empty($contact['notify'])) { if (!empty($contact['notify'])) {
Salmon::slapper($user, $contact['notify'], $slap); Salmon::slapper($user, $contact['notify'], $slap);
} }
} elseif ($contact['network'] == Protocol::DIASPORA) { } elseif ($protocol == Protocol::DIASPORA) {
Diaspora::sendUnshare($user, $contact); Diaspora::sendUnshare($user, $contact);
} elseif ($contact['network'] == Protocol::ACTIVITYPUB) { } elseif ($protocol == Protocol::ACTIVITYPUB) {
ActivityPub\Transmitter::sendContactUndo($contact['url'], $contact['id'], $user['uid']); ActivityPub\Transmitter::sendContactUndo($contact['url'], $contact['id'], $user['uid']);
if ($dissolve) { if ($dissolve) {
@ -1804,6 +1810,40 @@ class Contact extends BaseObject
return true; return true;
} }
/**
* Detects if a given contact array belongs to a legacy DFRN connection
*
* @param array $contact
* @return boolean
*/
public static function isLegacyDFRNContact($contact)
{
// Newer Friendica contacts are connected via AP, then these fields aren't set
return !empty($contact['dfrn-id']) || !empty($contact['issued-id']);
}
/**
* Detects the communication protocol for a given contact url.
* This is used to detect Friendica contacts that we can communicate via AP.
*
* @param string $url contact url
* @param string $network Network of that contact
* @return string with protocol
*/
public static function getProtocol($url, $network)
{
if ($network != Protocol::DFRN) {
return $network;
}
$apcontact = APContact::getByURL($url);
if (!empty($apcontact) && !empty($apcontact['generator'])) {
return Protocol::ACTIVITYPUB;
} else {
return $network;
}
}
/** /**
* Takes a $uid and a url/handle and adds a new contact * Takes a $uid and a url/handle and adds a new contact
* Currently if the contact is DFRN, interactive needs to be true, to redirect to the * Currently if the contact is DFRN, interactive needs to be true, to redirect to the
@ -1879,7 +1919,9 @@ class Contact extends BaseObject
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition); $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
} }
if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($contact)) { $protocol = self::getProtocol($url, $ret['network']);
if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) {
if ($interactive) { if ($interactive) {
if (strlen($a->getURLPath())) { if (strlen($a->getURLPath())) {
$myaddr = bin2hex(System::baseUrl() . '/profile/' . $a->user['nickname']); $myaddr = bin2hex(System::baseUrl() . '/profile/' . $a->user['nickname']);
@ -1898,7 +1940,7 @@ class Contact extends BaseObject
} }
// This extra param just confuses things, remove it // This extra param just confuses things, remove it
if ($ret['network'] === Protocol::DIASPORA) { if ($protocol === Protocol::DIASPORA) {
$ret['url'] = str_replace('?absolute=true', '', $ret['url']); $ret['url'] = str_replace('?absolute=true', '', $ret['url']);
} }
@ -1921,7 +1963,7 @@ class Contact extends BaseObject
return $result; return $result;
} }
if ($ret['network'] === Protocol::OSTATUS && Config::get('system', 'ostatus_disabled')) { if ($protocol === Protocol::OSTATUS && Config::get('system', 'ostatus_disabled')) {
$result['message'] .= L10n::t('The profile address specified belongs to a network which has been disabled on this site.') . EOL; $result['message'] .= L10n::t('The profile address specified belongs to a network which has been disabled on this site.') . EOL;
$ret['notify'] = ''; $ret['notify'] = '';
} }
@ -1930,15 +1972,15 @@ class Contact extends BaseObject
$result['message'] .= L10n::t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL; $result['message'] .= L10n::t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL;
} }
$writeable = ((($ret['network'] === Protocol::OSTATUS) && ($ret['notify'])) ? 1 : 0); $writeable = ((($protocol === Protocol::OSTATUS) && ($ret['notify'])) ? 1 : 0);
$subhub = (($ret['network'] === Protocol::OSTATUS) ? true : false); $subhub = (($protocol === Protocol::OSTATUS) ? true : false);
$hidden = (($ret['network'] === Protocol::MAIL) ? 1 : 0); $hidden = (($protocol === Protocol::MAIL) ? 1 : 0);
$pending = in_array($ret['network'], [Protocol::ACTIVITYPUB]); $pending = in_array($protocol, [Protocol::ACTIVITYPUB]);
if (in_array($ret['network'], [Protocol::MAIL, Protocol::DIASPORA, Protocol::ACTIVITYPUB])) { if (in_array($protocol, [Protocol::MAIL, Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
$writeable = 1; $writeable = 1;
} }
@ -1949,7 +1991,7 @@ class Contact extends BaseObject
$fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false]; $fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false];
DBA::update('contact', $fields, ['id' => $contact['id']]); DBA::update('contact', $fields, ['id' => $contact['id']]);
} else { } else {
$new_relation = (in_array($ret['network'], [Protocol::MAIL]) ? self::FRIEND : self::SHARING); $new_relation = (in_array($protocol, [Protocol::MAIL]) ? self::FRIEND : self::SHARING);
// create contact record // create contact record
DBA::insert('contact', [ DBA::insert('contact', [
@ -1966,6 +2008,7 @@ class Contact extends BaseObject
'name' => $ret['name'], 'name' => $ret['name'],
'nick' => $ret['nick'], 'nick' => $ret['nick'],
'network' => $ret['network'], 'network' => $ret['network'],
'protocol' => $protocol,
'pubkey' => $ret['pubkey'], 'pubkey' => $ret['pubkey'],
'rel' => $new_relation, 'rel' => $new_relation,
'priority'=> $ret['priority'], 'priority'=> $ret['priority'],
@ -1999,7 +2042,7 @@ class Contact extends BaseObject
$owner = User::getOwnerDataById($uid); $owner = User::getOwnerDataById($uid);
if (DBA::isResult($owner)) { if (DBA::isResult($owner)) {
if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DFRN])) { if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
// create a follow slap // create a follow slap
$item = []; $item = [];
$item['verb'] = ACTIVITY_FOLLOW; $item['verb'] = ACTIVITY_FOLLOW;
@ -2015,10 +2058,10 @@ class Contact extends BaseObject
if (!empty($contact['notify'])) { if (!empty($contact['notify'])) {
Salmon::slapper($owner, $contact['notify'], $slap); Salmon::slapper($owner, $contact['notify'], $slap);
} }
} elseif ($contact['network'] == Protocol::DIASPORA) { } elseif ($protocol == Protocol::DIASPORA) {
$ret = Diaspora::sendShare($a->user, $contact); $ret = Diaspora::sendShare($a->user, $contact);
Logger::log('share returns: ' . $ret); Logger::log('share returns: ' . $ret);
} elseif ($contact['network'] == Protocol::ACTIVITYPUB) { } elseif ($protocol == Protocol::ACTIVITYPUB) {
$activity_id = ActivityPub\Transmitter::activityIDFromContact($contact_id); $activity_id = ActivityPub\Transmitter::activityIDFromContact($contact_id);
if (empty($activity_id)) { if (empty($activity_id)) {
// This really should never happen // This really should never happen
@ -2076,7 +2119,7 @@ class Contact extends BaseObject
return $contact; return $contact;
} }
public static function addRelationship($importer, $contact, $datarray, $item = '', $sharing = false) { public static function addRelationship($importer, $contact, $datarray, $item = '', $sharing = false, $note = '') {
// Should always be set // Should always be set
if (empty($datarray['author-id'])) { if (empty($datarray['author-id'])) {
return; return;
@ -2096,18 +2139,25 @@ class Contact extends BaseObject
$network = $pub_contact['network']; $network = $pub_contact['network'];
if (is_array($contact)) { if (is_array($contact)) {
// Make sure that the existing contact isn't archived
self::unmarkForArchival($contact);
$protocol = self::getProtocol($url, $contact['network']);
if (($contact['rel'] == self::SHARING) if (($contact['rel'] == self::SHARING)
|| ($sharing && $contact['rel'] == self::FOLLOWER)) { || ($sharing && $contact['rel'] == self::FOLLOWER)) {
DBA::update('contact', ['rel' => self::FRIEND, 'writable' => true], DBA::update('contact', ['rel' => self::FRIEND, 'writable' => true, 'pending' => false],
['id' => $contact['id'], 'uid' => $importer['uid']]); ['id' => $contact['id'], 'uid' => $importer['uid']]);
} }
if ($contact['network'] == Protocol::ACTIVITYPUB) { if ($protocol == Protocol::ACTIVITYPUB) {
ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']); ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']);
} }
// send email notification to owner? // send email notification to owner?
} else { } else {
$protocol = self::getProtocol($url, $network);
if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($url), 'uid' => $importer['uid'], 'pending' => true])) { if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($url), 'uid' => $importer['uid'], 'pending' => true])) {
Logger::log('ignoring duplicated connection request from pending contact ' . $url); Logger::log('ignoring duplicated connection request from pending contact ' . $url);
return; return;
@ -2146,7 +2196,7 @@ class Contact extends BaseObject
if (is_array($contact_record)) { if (is_array($contact_record)) {
DBA::insert('intro', ['uid' => $importer['uid'], 'contact-id' => $contact_record['id'], DBA::insert('intro', ['uid' => $importer['uid'], 'contact-id' => $contact_record['id'],
'blocked' => false, 'knowyou' => false, 'blocked' => false, 'knowyou' => false, 'note' => $note,
'hash' => $hash, 'datetime' => DateTimeFormat::utcNow()]); 'hash' => $hash, 'datetime' => DateTimeFormat::utcNow()]);
} }
@ -2176,8 +2226,9 @@ class Contact extends BaseObject
DBA::update('contact', ['pending' => false], $condition); DBA::update('contact', ['pending' => false], $condition);
$contact = DBA::selectFirst('contact', ['url', 'network', 'hub-verify'], ['id' => $contact_record['id']]); $contact = DBA::selectFirst('contact', ['url', 'network', 'hub-verify'], ['id' => $contact_record['id']]);
$protocol = self::getProtocol($contact['url'], $contact['network']);
if ($contact['network'] == Protocol::ACTIVITYPUB) { if ($protocol == Protocol::ACTIVITYPUB) {
ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']); ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']);
} }
} }

View File

@ -454,7 +454,7 @@ class Processor
$cid = Contact::getIdForURL($activity['actor'], $uid); $cid = Contact::getIdForURL($activity['actor'], $uid);
if (!empty($cid)) { if (!empty($cid)) {
self::switchContact($cid); self::switchContact($cid);
DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]); DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
$contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]); $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
} else { } else {
$contact = false; $contact = false;
@ -463,17 +463,19 @@ class Processor
$item = ['author-id' => Contact::getIdForURL($activity['actor']), $item = ['author-id' => Contact::getIdForURL($activity['actor']),
'author-link' => $activity['actor']]; 'author-link' => $activity['actor']];
$note = Strings::escapeTags(trim(defaults($activity, 'content', '')));
// Ensure that the contact has got the right network type // Ensure that the contact has got the right network type
self::switchContact($item['author-id']); self::switchContact($item['author-id']);
Contact::addRelationship($owner, $contact, $item); Contact::addRelationship($owner, $contact, $item, '', false, $note);
$cid = Contact::getIdForURL($activity['actor'], $uid); $cid = Contact::getIdForURL($activity['actor'], $uid);
if (empty($cid)) { if (empty($cid)) {
return; return;
} }
if (empty($contact)) { if (empty($contact)) {
DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]); DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
} }
Logger::log('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']); Logger::log('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
@ -578,7 +580,7 @@ class Processor
self::switchContact($cid); self::switchContact($cid);
if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING, 'pending' => true])) { if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING])) {
Contact::remove($cid); Contact::remove($cid);
Logger::log('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', Logger::DEBUG); Logger::log('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', Logger::DEBUG);
} else { } else {
@ -653,7 +655,7 @@ class Processor
private static function switchContact($cid) private static function switchContact($cid)
{ {
$contact = DBA::selectFirst('contact', ['network'], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]); $contact = DBA::selectFirst('contact', ['network'], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
if (!DBA::isResult($contact) || ($contact['network'] == Protocol::ACTIVITYPUB)) { if (!DBA::isResult($contact) || in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
return; return;
} }

View File

@ -48,20 +48,27 @@ class OnePoll
return; return;
} }
if (($contact['network'] == Protocol::DFRN) && !Contact::isLegacyDFRNContact($contact)) {
$protocol = Protocol::ACTIVITYPUB;
} else {
$protocol = $contact['network'];
}
$importer_uid = $contact['uid']; $importer_uid = $contact['uid'];
// Possibly switch the remote contact to AP // Possibly switch the remote contact to AP
if ($contact['network'] === Protocol::OSTATUS) { if ($protocol === Protocol::OSTATUS) {
ActivityPub\Receiver::switchContact($contact['id'], $importer_uid, $contact['url']); ActivityPub\Receiver::switchContact($contact['id'], $importer_uid, $contact['url']);
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id]); $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
} }
$updated = DateTimeFormat::utcNow();
// These three networks can be able to speak AP, so we are trying to fetch AP profile data here // These three networks can be able to speak AP, so we are trying to fetch AP profile data here
if (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN])) { if (in_array($protocol, [Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN])) {
$apcontact = APContact::getByURL($contact['url'], true); $apcontact = APContact::getByURL($contact['url'], true);
$updated = DateTimeFormat::utcNow(); if (($protocol === Protocol::ACTIVITYPUB) && empty($apcontact)) {
if (($contact['network'] === Protocol::ACTIVITYPUB) && empty($apcontact)) {
self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]); self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
Contact::markForArchival($contact); Contact::markForArchival($contact);
Logger::log('Contact archived'); Logger::log('Contact archived');
@ -74,9 +81,8 @@ class OnePoll
} }
// Diaspora users, archived users and followers are only checked if they still exist. // Diaspora users, archived users and followers are only checked if they still exist.
if (($contact['network'] != Protocol::ACTIVITYPUB) && ($contact['archive'] || ($contact["network"] == Protocol::DIASPORA) || ($contact["rel"] == Contact::FOLLOWER))) { if (($protocol != Protocol::ACTIVITYPUB) && ($contact['archive'] || ($contact["network"] == Protocol::DIASPORA) || ($contact["rel"] == Contact::FOLLOWER))) {
$last_updated = PortableContact::lastUpdated($contact["url"], true); $last_updated = PortableContact::lastUpdated($contact["url"], true);
$updated = DateTimeFormat::utcNow();
if ($last_updated) { if ($last_updated) {
Logger::log('Contact '.$contact['id'].' had last update on '.$last_updated, Logger::DEBUG); Logger::log('Contact '.$contact['id'].' had last update on '.$last_updated, Logger::DEBUG);
@ -98,10 +104,9 @@ class OnePoll
} }
// Update the contact entry // Update the contact entry
if (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) { if (in_array($protocol, [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
$updated = DateTimeFormat::utcNow();
// Currently we can't check every AP implementation, so we don't do it at all // Currently we can't check every AP implementation, so we don't do it at all
if (($contact['network'] != Protocol::ACTIVITYPUB) && !PortableContact::reachable($contact['url'])) { if (($protocol != Protocol::ACTIVITYPUB) && !PortableContact::reachable($contact['url'])) {
Logger::log("Skipping probably dead contact ".$contact['url']); Logger::log("Skipping probably dead contact ".$contact['url']);
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
@ -140,25 +145,25 @@ class OnePoll
Logger::log("Don't poll follower"); Logger::log("Don't poll follower");
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return; return;
} }
// Don't poll if polling is deactivated (But we poll feeds and mails anyway) // Don't poll if polling is deactivated (But we poll feeds and mails anyway)
if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && Config::get('system', 'disable_polling')) { if (!in_array($protocol, [Protocol::FEED, Protocol::MAIL]) && Config::get('system', 'disable_polling')) {
Logger::log('Polling is disabled'); Logger::log('Polling is disabled');
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return; return;
} }
// We don't poll AP contacts by now // We don't poll AP contacts by now
if ($contact['network'] === Protocol::ACTIVITYPUB) { if ($protocol === Protocol::ACTIVITYPUB) {
Logger::log("Don't poll AP contact"); Logger::log("Don't poll AP contact");
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return; return;
} }
@ -166,7 +171,7 @@ class OnePoll
Logger::log('Ignore public contacts'); Logger::log('Ignore public contacts');
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return; return;
} }
@ -178,7 +183,7 @@ class OnePoll
Logger::log('No self contact for user '.$importer_uid); Logger::log('No self contact for user '.$importer_uid);
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return; return;
} }
@ -203,9 +208,9 @@ class OnePoll
: DateTimeFormat::utc($contact['last-update'], DateTimeFormat::ATOM) : DateTimeFormat::utc($contact['last-update'], DateTimeFormat::ATOM)
); );
Logger::log("poll: ({$contact['network']}-{$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}"); Logger::log("poll: ({$protocol}-{$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
if ($contact['network'] === Protocol::DFRN) { if ($protocol === Protocol::DFRN) {
$idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
if (intval($contact['duplex']) && $contact['dfrn-id']) { if (intval($contact['duplex']) && $contact['dfrn-id']) {
$idtosend = '0:' . $orig_id; $idtosend = '0:' . $orig_id;
@ -233,7 +238,7 @@ class OnePoll
if (!$curlResult->isSuccess() && ($curlResult->getErrorNumber() == CURLE_OPERATION_TIMEDOUT)) { if (!$curlResult->isSuccess() && ($curlResult->getErrorNumber() == CURLE_OPERATION_TIMEDOUT)) {
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]); self::updateContact($contact, ['last-update' => $updated]);
Contact::markForArchival($contact); Contact::markForArchival($contact);
Logger::log('Contact archived'); Logger::log('Contact archived');
return; return;
@ -251,7 +256,7 @@ class OnePoll
Logger::log("$url appears to be dead - marking for death "); Logger::log("$url appears to be dead - marking for death ");
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
$fields = ['last-update' => DateTimeFormat::utcNow(), 'failure_update' => DateTimeFormat::utcNow()]; $fields = ['last-update' => $updated, 'failure_update' => $updated];
self::updateContact($contact, $fields); self::updateContact($contact, $fields);
Contact::markForArchival($contact); Contact::markForArchival($contact);
return; return;
@ -260,7 +265,7 @@ class OnePoll
if (!strstr($handshake_xml, '<')) { if (!strstr($handshake_xml, '<')) {
Logger::log('response from ' . $url . ' did not contain XML.'); Logger::log('response from ' . $url . ' did not contain XML.');
$fields = ['last-update' => DateTimeFormat::utcNow(), 'failure_update' => DateTimeFormat::utcNow()]; $fields = ['last-update' => $updated, 'failure_update' => $updated];
self::updateContact($contact, $fields); self::updateContact($contact, $fields);
Contact::markForArchival($contact); Contact::markForArchival($contact);
return; return;
@ -274,7 +279,7 @@ class OnePoll
Logger::log("$url replied status 1 - marking for death "); Logger::log("$url replied status 1 - marking for death ");
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
$fields = ['last-update' => DateTimeFormat::utcNow(), 'failure_update' => DateTimeFormat::utcNow()]; $fields = ['last-update' => $updated, 'failure_update' => $updated];
self::updateContact($contact, $fields); self::updateContact($contact, $fields);
Contact::markForArchival($contact); Contact::markForArchival($contact);
} elseif ($contact['term-date'] > DBA::NULL_DATETIME) { } elseif ($contact['term-date'] > DBA::NULL_DATETIME) {
@ -283,7 +288,7 @@ class OnePoll
if ((intval($res->status) != 0) || !strlen($res->challenge) || !strlen($res->dfrn_id)) { if ((intval($res->status) != 0) || !strlen($res->challenge) || !strlen($res->dfrn_id)) {
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
Logger::log('Contact status is ' . $res->status); Logger::log('Contact status is ' . $res->status);
return; return;
} }
@ -326,7 +331,7 @@ class OnePoll
Logger::log('ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id); Logger::log('ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
Contact::markForArchival($contact); Contact::markForArchival($contact);
return; return;
} }
@ -337,9 +342,9 @@ class OnePoll
$xml = Network::post($contact['poll'], $postvars)->getBody(); $xml = Network::post($contact['poll'], $postvars)->getBody();
} elseif (($contact['network'] === Protocol::OSTATUS) } elseif (($protocol === Protocol::OSTATUS)
|| ($contact['network'] === Protocol::DIASPORA) || ($protocol === Protocol::DIASPORA)
|| ($contact['network'] === Protocol::FEED)) { || ($protocol === Protocol::FEED)) {
// Upgrading DB fields from an older Friendica version // Upgrading DB fields from an older Friendica version
// Will only do this once per notify-enabled OStatus contact // Will only do this once per notify-enabled OStatus contact
@ -348,7 +353,7 @@ class OnePoll
$stat_writeable = ((($contact['notify']) && ($contact['rel'] == Contact::FOLLOWER || $contact['rel'] == Contact::FRIEND)) ? 1 : 0); $stat_writeable = ((($contact['notify']) && ($contact['rel'] == Contact::FOLLOWER || $contact['rel'] == Contact::FRIEND)) ? 1 : 0);
// Contacts from OStatus are always writable // Contacts from OStatus are always writable
if ($contact['network'] === Protocol::OSTATUS) { if ($protocol === Protocol::OSTATUS) {
$stat_writeable = 1; $stat_writeable = 1;
} }
@ -360,7 +365,7 @@ class OnePoll
// Are we allowed to import from this person? // Are we allowed to import from this person?
if ($contact['rel'] == Contact::FOLLOWER || $contact['blocked']) { if ($contact['rel'] == Contact::FOLLOWER || $contact['blocked']) {
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
Logger::log('Contact is blocked or only a follower'); Logger::log('Contact is blocked or only a follower');
return; return;
} }
@ -371,7 +376,7 @@ class OnePoll
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]); self::updateContact($contact, ['last-update' => $updated]);
Contact::markForArchival($contact); Contact::markForArchival($contact);
Logger::log('Contact archived'); Logger::log('Contact archived');
return; return;
@ -379,13 +384,13 @@ class OnePoll
$xml = $curlResult->getBody(); $xml = $curlResult->getBody();
} elseif ($contact['network'] === Protocol::MAIL) { } elseif ($protocol === Protocol::MAIL) {
Logger::log("Mail: Fetching for ".$contact['addr'], Logger::DEBUG); Logger::log("Mail: Fetching for ".$contact['addr'], Logger::DEBUG);
$mail_disabled = ((function_exists('imap_open') && !Config::get('system', 'imap_disabled')) ? 0 : 1); $mail_disabled = ((function_exists('imap_open') && !Config::get('system', 'imap_disabled')) ? 0 : 1);
if ($mail_disabled) { if ($mail_disabled) {
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]); self::updateContact($contact, ['last-update' => $updated]);
Contact::markForArchival($contact); Contact::markForArchival($contact);
Logger::log('Contact archived'); Logger::log('Contact archived');
return; return;
@ -406,7 +411,7 @@ class OnePoll
unset($password); unset($password);
Logger::log("Mail: Connect to " . $mailconf['user']); Logger::log("Mail: Connect to " . $mailconf['user']);
if ($mbox) { if ($mbox) {
$fields = ['last_check' => DateTimeFormat::utcNow()]; $fields = ['last_check' => $updated];
DBA::update('mailacct', $fields, ['id' => $mailconf['id']]); DBA::update('mailacct', $fields, ['id' => $mailconf['id']]);
Logger::log("Mail: Connected to " . $mailconf['user']); Logger::log("Mail: Connected to " . $mailconf['user']);
} else { } else {
@ -448,7 +453,7 @@ class OnePoll
// Only delete when mails aren't automatically moved or deleted // Only delete when mails aren't automatically moved or deleted
if (($mailconf['action'] != 1) && ($mailconf['action'] != 3)) if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
if ($meta->deleted && ! $item['deleted']) { if ($meta->deleted && ! $item['deleted']) {
$fields = ['deleted' => true, 'changed' => DateTimeFormat::utcNow()]; $fields = ['deleted' => true, 'changed' => $updated];
Item::update($fields, ['id' => $item['id']]); Item::update($fields, ['id' => $item['id']]);
} }
@ -579,7 +584,7 @@ class OnePoll
if ($datarray['parent-uri'] === $datarray['uri']) { if ($datarray['parent-uri'] === $datarray['uri']) {
$datarray['private'] = 1; $datarray['private'] = 1;
} }
if (($contact['network'] === Protocol::MAIL) && !PConfig::get($importer_uid, 'system', 'allow_public_email_replies')) { if (($protocol === Protocol::MAIL) && !PConfig::get($importer_uid, 'system', 'allow_public_email_replies')) {
$datarray['private'] = 1; $datarray['private'] = 1;
$datarray['allow_cid'] = '<' . $contact['id'] . '>'; $datarray['allow_cid'] = '<' . $contact['id'] . '>';
} }
@ -622,7 +627,7 @@ class OnePoll
if (!strstr($xml, '<')) { if (!strstr($xml, '<')) {
Logger::log('post_handshake: response from ' . $url . ' did not contain XML.'); Logger::log('post_handshake: response from ' . $url . ' did not contain XML.');
$fields = ['last-update' => DateTimeFormat::utcNow(), 'failure_update' => DateTimeFormat::utcNow()]; $fields = ['last-update' => $updated, 'failure_update' => $updated];
self::updateContact($contact, $fields); self::updateContact($contact, $fields);
Contact::markForArchival($contact); Contact::markForArchival($contact);
return; return;
@ -634,16 +639,16 @@ class OnePoll
consume_feed($xml, $importer, $contact, $hub); consume_feed($xml, $importer, $contact, $hub);
// do it a second time for DFRN so that any children find their parents. // do it a second time for DFRN so that any children find their parents.
if ($contact['network'] === Protocol::DFRN) { if ($protocol === Protocol::DFRN) {
consume_feed($xml, $importer, $contact, $hub); consume_feed($xml, $importer, $contact, $hub);
} }
$hubmode = 'subscribe'; $hubmode = 'subscribe';
if ($contact['network'] === Protocol::DFRN || $contact['blocked']) { if ($protocol === Protocol::DFRN || $contact['blocked']) {
$hubmode = 'unsubscribe'; $hubmode = 'unsubscribe';
} }
if (($contact['network'] === Protocol::OSTATUS || $contact['network'] == Protocol::FEED) && (! $contact['hub-verify'])) { if (($protocol === Protocol::OSTATUS || $protocol == Protocol::FEED) && (! $contact['hub-verify'])) {
$hub_update = true; $hub_update = true;
} }
@ -651,9 +656,9 @@ class OnePoll
$hub_update = true; $hub_update = true;
} }
Logger::log("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$contact['network']." Relation: ".$contact['rel']." Update: ".$hub_update); Logger::log("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$protocol." Relation: ".$contact['rel']." Update: ".$hub_update);
if (strlen($hub) && $hub_update && (($contact['rel'] != Contact::FOLLOWER) || $contact['network'] == Protocol::FEED)) { if (strlen($hub) && $hub_update && (($contact['rel'] != Contact::FOLLOWER) || $protocol == Protocol::FEED)) {
Logger::log('hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']); Logger::log('hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
$hubs = explode(',', $hub); $hubs = explode(',', $hub);
@ -670,19 +675,15 @@ class OnePoll
} }
} }
$updated = DateTimeFormat::utcNow();
self::updateContact($contact, ['last-update' => $updated, 'success_update' => $updated]); self::updateContact($contact, ['last-update' => $updated, 'success_update' => $updated]);
DBA::update('gcontact', ['last_contact' => $updated], ['nurl' => $contact['nurl']]); DBA::update('gcontact', ['last_contact' => $updated], ['nurl' => $contact['nurl']]);
Contact::unmarkForArchival($contact); Contact::unmarkForArchival($contact);
} elseif (in_array($contact["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED])) { } elseif (in_array($contact["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED])) {
$updated = DateTimeFormat::utcNow();
self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]); self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
DBA::update('gcontact', ['last_failure' => $updated], ['nurl' => $contact['nurl']]); DBA::update('gcontact', ['last_failure' => $updated], ['nurl' => $contact['nurl']]);
Contact::markForArchival($contact); Contact::markForArchival($contact);
} else { } else {
self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]); self::updateContact($contact, ['last-update' => $updated]);
} }
Logger::log('End'); Logger::log('End');