1
1
Fork 0

Improved detection for a local contact

This commit is contained in:
Michael 2021-07-19 04:15:57 +00:00
parent 424a85bb94
commit aa6313dee6
3 changed files with 24 additions and 3 deletions

View file

@ -54,6 +54,20 @@ class APContact
return []; return [];
} }
if (Contact::isLocal($addr) && ($local_uid = User::getIdForURL($addr)) && ($local_owner = User::getOwnerDataById($local_uid))) {
$data = [
'addr' => $local_owner['addr'],
'baseurl' => $local_owner['baseurl'],
'url' => $local_owner['url'],
'subscribe' => $local_owner['baseurl'] . '/follow?url={uri}'];
if (!empty($local_owner['alias']) && ($local_owner['url'] != $local_owner['alias'])) {
$data['alias'] = $local_owner['alias'];
}
return $data;
}
$data = ['addr' => $addr]; $data = ['addr' => $addr];
$template = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr); $template = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
$webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), 'application/jrd+json'); $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), 'application/jrd+json');

View file

@ -453,6 +453,13 @@ class Contact
*/ */
public static function isLocal($url) public static function isLocal($url)
{ {
if (!parse_url($url, PHP_URL_SCHEME)) {
$addr_parts = explode('@', $url);
if (count($addr_parts) == 2) {
return $addr_parts[1] == DI::baseUrl()->getHostname();
}
}
return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl()); return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl());
} }

View file

@ -333,7 +333,7 @@ class Probe
public static function uri($uri, $network = '', $uid = -1) public static function uri($uri, $network = '', $uid = -1)
{ {
// Local profiles aren't probed via network // Local profiles aren't probed via network
if (empty($network) && strpos($uri, DI::baseUrl()->getHostname())) { if (empty($network) && Contact::isLocal($uri)) {
$data = self::localProbe($uri); $data = self::localProbe($uri);
if (!empty($data)) { if (!empty($data)) {
return $data; return $data;