Browse Source

Update AP helpers, fix Moved account support

Daniel Supernault 10 tháng trước cách đây
mục cha
commit
f1497655ba
1 tập tin đã thay đổi với 16 bổ sung8 xóa
  1. 16 8
      app/Util/ActivityPub/Helpers.php

+ 16 - 8
app/Util/ActivityPub/Helpers.php

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