Merge pull request #7647 from annando/inter-transport

Always use direct DFRN transport on local contacts
This commit is contained in:
Hypolite Petovan 2019-09-21 10:23:29 -04:00 committed by GitHub
commit 775324bd07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 9 deletions

View file

@ -270,14 +270,17 @@ class Contact extends BaseObject
* @param string $url The contact link * @param string $url The contact link
* *
* @return string basepath * @return string basepath
* @return boolean $dont_update Don't update the contact
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function getBasepath($url) public static function getBasepath($url, $dont_update = false)
{ {
$contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]); $contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
if (!empty($contact['baseurl'])) { if (!empty($contact['baseurl'])) {
return $contact['baseurl']; return $contact['baseurl'];
} elseif ($dont_update) {
return '';
} }
self::updateFromProbeByURL($url, true); self::updateFromProbeByURL($url, true);
@ -290,6 +293,18 @@ class Contact extends BaseObject
return ''; return '';
} }
/**
* Check if the given contact url is on the same server
*
* @param string $url The contact link
*
* @return boolean Is it the same server?
*/
public static function isLocal($url)
{
return Strings::compareLink(self::getBasepath($url, true), System::baseUrl());
}
/** /**
* Returns the public contact id of the given user id * Returns the public contact id of the given user id
* *
@ -2486,6 +2501,9 @@ class Contact extends BaseObject
['id' => $contact['id'], 'uid' => $importer['uid']]); ['id' => $contact['id'], 'uid' => $importer['uid']]);
} }
// Ensure to always have the correct network type, independent from the connection request method
self::updateFromProbe($contact['id'], '', true);
return true; return true;
} else { } else {
// send email notification to owner? // send email notification to owner?
@ -2511,15 +2529,14 @@ class Contact extends BaseObject
'writable' => 1, 'writable' => 1,
]); ]);
$contact_record = [ $contact_id = DBA::lastInsertId();
'id' => DBA::lastInsertId(),
'network' => $network,
'name' => $name,
'url' => $url,
'photo' => $photo
];
Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true); // Ensure to always have the correct network type, independent from the connection request method
self::updateFromProbe($contact_id, '', true);
Contact::updateAvatar($photo, $importer["uid"], $contact_id, true);
$contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo'], ['id' => $contact_id]);
/// @TODO Encapsulate this into a function/method /// @TODO Encapsulate this into a function/method
$fields = ['uid', 'username', 'email', 'page-flags', 'notify-flags', 'language']; $fields = ['uid', 'username', 'email', 'page-flags', 'notify-flags', 'language'];

View file

@ -544,6 +544,10 @@ class Transmitter
$contacts = DBA::select('contact', ['url', 'network', 'protocol'], $condition); $contacts = DBA::select('contact', ['url', 'network', 'protocol'], $condition);
while ($contact = DBA::fetch($contacts)) { while ($contact = DBA::fetch($contacts)) {
if (Contact::isLocal($contact['url'])) {
continue;
}
if (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB)) { if (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB)) {
continue; continue;
} }
@ -611,6 +615,10 @@ class Transmitter
if ($receiver == $item_profile['followers']) { if ($receiver == $item_profile['followers']) {
$inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal)); $inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
} else { } else {
if (Contact::isLocal($receiver)) {
continue;
}
$profile = APContact::getByURL($receiver, false); $profile = APContact::getByURL($receiver, false);
if (!empty($profile)) { if (!empty($profile)) {
if (empty($profile['sharedinbox']) || $personal || $blindcopy) { if (empty($profile['sharedinbox']) || $personal || $blindcopy) {

View file

@ -568,6 +568,11 @@ class Notifier
*/ */
private static function skipDFRN($contact, $item, $cmd) private static function skipDFRN($contact, $item, $cmd)
{ {
// Use DFRN if we are on the same site
if (!empty($contact['url']) && Contact::isLocal($contact['url'])) {
return false;
}
// Don't skip when author or owner don't have AP profiles // Don't skip when author or owner don't have AP profiles
if ((!empty($item['author-link']) && empty(APContact::getByURL($item['author-link'], false))) || (!empty($item['owner-link']) && empty(APContact::getByURL($item['owner-link'], false)))) { if ((!empty($item['author-link']) && empty(APContact::getByURL($item['author-link'], false))) || (!empty($item['owner-link']) && empty(APContact::getByURL($item['owner-link'], false)))) {
return false; return false;