forked from friendica/friendica-addons
Bluesky: probing for bluesky handles
This commit is contained in:
parent
454e9834bf
commit
ebf2d1736d
|
@ -130,7 +130,12 @@ function bluesky_probe_detect(array &$hookData)
|
|||
if (parse_url($hookData['uri'], PHP_URL_SCHEME) == 'did') {
|
||||
$did = $hookData['uri'];
|
||||
} elseif (preg_match('#^' . BLUESKY_WEB . '/profile/(.+)#', $hookData['uri'], $matches)) {
|
||||
$did = bluesky_get_did($matches[1]);
|
||||
$did = bluesky_get_did($matches[1], $pconfig['uid']);
|
||||
if (empty($did)) {
|
||||
return;
|
||||
}
|
||||
} elseif (parse_url($hookData['uri'], PHP_URL_PATH) == $hookData['uri'] && strpos($hookData['uri'], '@') === false) {
|
||||
$did = bluesky_get_did($hookData['uri'], $pconfig['uid']);
|
||||
if (empty($did)) {
|
||||
return;
|
||||
}
|
||||
|
@ -181,7 +186,7 @@ function bluesky_item_by_link(array &$hookData)
|
|||
return;
|
||||
}
|
||||
|
||||
$did = bluesky_get_did($matches[1]);
|
||||
$did = bluesky_get_did($matches[1], $hookData['uid']);
|
||||
if (empty($did)) {
|
||||
return;
|
||||
}
|
||||
|
@ -1757,7 +1762,6 @@ function bluesky_get_did_by_wellknown(string $handle): string
|
|||
Logger::notice('Invalid DID', ['handle' => $handle, 'did' => $did]);
|
||||
return '';
|
||||
}
|
||||
Logger::debug('Got DID by wellknown', ['handle' => $handle, 'did' => $did]);
|
||||
return $did;
|
||||
}
|
||||
return '';
|
||||
|
@ -1776,14 +1780,13 @@ function bluesky_get_did_by_dns(string $handle): string
|
|||
Logger::notice('Invalid DID', ['handle' => $handle, 'did' => $did]);
|
||||
return '';
|
||||
}
|
||||
Logger::debug('Got DID by DNS', ['handle' => $handle, 'did' => $did]);
|
||||
return $did;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function bluesky_get_did(string $handle): string
|
||||
function bluesky_get_did(string $handle, int $uid): string
|
||||
{
|
||||
if ($handle == '') {
|
||||
return '';
|
||||
|
@ -1793,19 +1796,39 @@ function bluesky_get_did(string $handle): string
|
|||
$handle .= '.' . BLUESKY_HOSTNAME;
|
||||
}
|
||||
|
||||
// At first we use the user PDS. That should cover most cases.
|
||||
$pds = DI::pConfig()->get($uid, 'bluesky', 'pds');
|
||||
if (!empty($pds)) {
|
||||
$data = bluesky_get($pds . '/xrpc/com.atproto.identity.resolveHandle?handle=' . urlencode($handle));
|
||||
if (!empty($data) && !empty($data->did)) {
|
||||
Logger::debug('Got DID by user PDS call', ['handle' => $handle, 'did' => $data->did]);
|
||||
return $data->did;
|
||||
}
|
||||
}
|
||||
|
||||
// Then we query the DNS, which is used for third party handles (DNS should be faster than wellknown)
|
||||
$did = bluesky_get_did_by_dns($handle);
|
||||
if ($did != '') {
|
||||
Logger::debug('Got DID by DNS', ['handle' => $handle, 'did' => $did]);
|
||||
return $did;
|
||||
}
|
||||
|
||||
// Then we query wellknown, which should mostly cover the rest.
|
||||
$did = bluesky_get_did_by_wellknown($handle);
|
||||
if ($did != '') {
|
||||
Logger::debug('Got DID by wellknown', ['handle' => $handle, 'did' => $did]);
|
||||
return $did;
|
||||
}
|
||||
|
||||
// And finally we use the default PDS from Bluesky.
|
||||
$data = bluesky_get(BLUESKY_PDS . '/xrpc/com.atproto.identity.resolveHandle?handle=' . urlencode($handle));
|
||||
if (!empty($data) && !empty($data->did)) {
|
||||
Logger::debug('Got DID by PDS call', ['handle' => $handle, 'did' => $data->did]);
|
||||
Logger::debug('Got DID by system PDS call', ['handle' => $handle, 'did' => $data->did]);
|
||||
return $data->did;
|
||||
}
|
||||
|
||||
// Possibly a custom PDS.
|
||||
$did = bluesky_get_did_by_dns($handle);
|
||||
if ($did != '') {
|
||||
return $did;
|
||||
}
|
||||
|
||||
return bluesky_get_did_by_wellknown($handle);
|
||||
Logger::notice('No DID detected', ['handle' => $handle]);
|
||||
return '';
|
||||
}
|
||||
|
||||
function bluesky_get_user_did(int $uid, bool $refresh = false): ?string
|
||||
|
@ -1822,7 +1845,7 @@ function bluesky_get_user_did(int $uid, bool $refresh = false): ?string
|
|||
return null;
|
||||
}
|
||||
|
||||
$did = bluesky_get_did($handle);
|
||||
$did = bluesky_get_did($handle, $uid);
|
||||
if (empty($did)) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue