1
0
Fork 0

Merge pull request #8119 from annando/localdfrn

Ensure that local contacts always are DFRN contacts
This commit is contained in:
Hypolite Petovan 2020-01-16 07:31:28 -05:00 committed by GitHub
commit d656facabb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 9 deletions

View file

@ -314,6 +314,29 @@ class Contact
return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl()); return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl());
} }
/**
* Check if the given contact ID is on the same server
*
* @param string $url The contact link
*
* @return boolean Is it the same server?
*/
public static function isLocalById(int $cid)
{
$contact = DBA::selectFirst('contact', ['url', 'baseurl'], ['id' => $cid]);
if (!DBA::isResult($contact)) {
return false;
}
if (empty($contact['baseurl'])) {
$baseurl = self::getBasepath($contact['url'], true);
} else {
$baseurl = $contact['baseurl'];
}
return Strings::compareLink($baseurl, DI::baseUrl());
}
/** /**
* Returns the public contact id of the given user id * Returns the public contact id of the given user id
* *
@ -2126,6 +2149,12 @@ class Contact
if ($force) { if ($force) {
self::updateContact($id, $uid, $ret['url'], ['last-update' => $updated, 'success_update' => $updated]); self::updateContact($id, $uid, $ret['url'], ['last-update' => $updated, 'success_update' => $updated]);
} }
// Update the public contact
if ($uid != 0) {
self::updateFromProbeByURL($ret['url']);
}
return true; return true;
} }

View file

@ -401,6 +401,11 @@ class Probe
$data['network'] = Protocol::PHANTOM; $data['network'] = Protocol::PHANTOM;
} }
// Ensure that local connections always are DFRN
if (($network == '') && ($data['network'] != Protocol::PHANTOM) && (self::ownHost($data['baseurl'] ?? '') || self::ownHost($data['url']))) {
$data['network'] = Protocol::DFRN;
}
if (!isset($data['hide']) && in_array($data['network'], Protocol::FEDERATED)) { if (!isset($data['hide']) && in_array($data['network'], Protocol::FEDERATED)) {
$data['hide'] = self::getHideStatus($data['url']); $data['hide'] = self::getHideStatus($data['url']);
} }

View file

@ -857,13 +857,13 @@ 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', 'url'], ['id' => $cid]);
if (!DBA::isResult($contact) || in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) { if (!DBA::isResult($contact) || in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN]) || Contact::isLocal($contact['url'])) {
return; return;
} }
Logger::log('Change existing contact ' . $cid . ' from ' . $contact['network'] . ' to ActivityPub.'); Logger::info('Change existing contact', ['cid' => $cid, 'previous' => $contact['network']]);
Contact::updateFromProbe($cid, Protocol::ACTIVITYPUB); Contact::updateFromProbe($cid);
} }
/** /**

View file

@ -177,12 +177,12 @@ class Cron
FROM `user` FROM `user`
STRAIGHT_JOIN `contact` STRAIGHT_JOIN `contact`
ON `contact`.`uid` = `user`.`uid` AND `contact`.`poll` != '' ON `contact`.`uid` = `user`.`uid` AND `contact`.`poll` != ''
AND `contact`.`network` IN (?, ?, ?, ?) AND `contact`.`network` IN (?, ?, ?, ?, ?)
AND NOT `contact`.`self` AND NOT `contact`.`blocked` AND NOT `contact`.`self` AND NOT `contact`.`blocked`
AND `contact`.`rel` != ? AND `contact`.`rel` != ?
WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed`"; WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed`";
$parameters = [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Contact::FOLLOWER]; $parameters = [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Contact::FOLLOWER];
// Only poll from those with suitable relationships, // Only poll from those with suitable relationships,
// and which have a polling address and ignore Diaspora since // and which have a polling address and ignore Diaspora since
@ -209,6 +209,11 @@ class Cron
$contact['priority'] = 3; $contact['priority'] = 3;
} }
// ActivityPub is checked once a week
if ($contact['network'] == Protocol::ACTIVITYPUB) {
$contact['priority'] = 4;
}
// Check archived contacts once a month // Check archived contacts once a month
if ($contact['archive']) { if ($contact['archive']) {
$contact['priority'] = 5; $contact['priority'] = 5;

View file

@ -38,9 +38,7 @@ class OnePoll
return; return;
} }
if ($force) { Contact::updateFromProbe($contact_id, '', $force);
Contact::updateFromProbe($contact_id, '', true);
}
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id]); $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
@ -48,6 +46,12 @@ class OnePoll
return; return;
} }
// Special treatment for wrongly detected local contacts
if (!$force && ($contact['network'] != Protocol::DFRN) && Contact::isLocalById($contact_id)) {
Contact::updateFromProbe($contact_id, Protocol::DFRN, true);
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
}
if (($contact['network'] == Protocol::DFRN) && !Contact::isLegacyDFRNContact($contact)) { if (($contact['network'] == Protocol::DFRN) && !Contact::isLegacyDFRNContact($contact)) {
$protocol = Protocol::ACTIVITYPUB; $protocol = Protocol::ACTIVITYPUB;
} else { } else {