Update AP helpers, fix Moved account support

This commit is contained in:
Daniel Supernault 2024-09-11 04:04:45 -06:00
parent d0c376f579
commit f1497655ba
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -801,12 +801,19 @@ class Helpers
return self::profileUpdateOrCreate($url); return self::profileUpdateOrCreate($url);
} }
public static function profileUpdateOrCreate($url) public static function profileUpdateOrCreate($url, $movedToCheck = false)
{ {
$movedToPid = null;
$res = self::fetchProfileFromUrl($url); $res = self::fetchProfileFromUrl($url);
if (! $res || isset($res['id']) == false) { if (! $res || isset($res['id']) == false) {
return; return;
} }
if (! self::validateUrl($res['inbox'])) {
return;
}
if (! self::validateUrl($res['id'])) {
return;
}
$urlDomain = parse_url($url, PHP_URL_HOST); $urlDomain = parse_url($url, PHP_URL_HOST);
$domain = parse_url($res['id'], PHP_URL_HOST); $domain = parse_url($res['id'], PHP_URL_HOST);
if (strtolower($urlDomain) !== strtolower($domain)) { if (strtolower($urlDomain) !== strtolower($domain)) {
@ -829,13 +836,6 @@ class Helpers
$remoteUsername = $username; $remoteUsername = $username;
$webfinger = "@{$username}@{$domain}"; $webfinger = "@{$username}@{$domain}";
if (! self::validateUrl($res['inbox'])) {
return;
}
if (! self::validateUrl($res['id'])) {
return;
}
$instance = Instance::updateOrCreate([ $instance = Instance::updateOrCreate([
'domain' => $domain, 'domain' => $domain,
]); ]);
@ -843,6 +843,13 @@ class Helpers
\App\Jobs\InstancePipeline\FetchNodeinfoPipeline::dispatch($instance)->onQueue('low'); \App\Jobs\InstancePipeline\FetchNodeinfoPipeline::dispatch($instance)->onQueue('low');
} }
if (! $movedToCheck && isset($res['movedTo']) && Helpers::validateUrl($res['movedTo'])) {
$movedTo = self::profileUpdateOrCreate($res['movedTo'], true);
if ($movedTo) {
$movedToPid = $movedTo->id;
}
}
$profile = Profile::updateOrCreate( $profile = Profile::updateOrCreate(
[ [
'domain' => strtolower($domain), 'domain' => strtolower($domain),
@ -859,6 +866,7 @@ class Helpers
'outbox_url' => isset($res['outbox']) ? $res['outbox'] : null, 'outbox_url' => isset($res['outbox']) ? $res['outbox'] : null,
'public_key' => $res['publicKey']['publicKeyPem'], 'public_key' => $res['publicKey']['publicKeyPem'],
'indexable' => isset($res['indexable']) && is_bool($res['indexable']) ? $res['indexable'] : false, 'indexable' => isset($res['indexable']) && is_bool($res['indexable']) ? $res['indexable'] : false,
'moved_to_profile_id' => $movedToPid,
] ]
); );