diff --git a/app/Transformer/Api/AccountTransformer.php b/app/Transformer/Api/AccountTransformer.php index 4e0426f02..f9d9ca529 100644 --- a/app/Transformer/Api/AccountTransformer.php +++ b/app/Transformer/Api/AccountTransformer.php @@ -3,6 +3,7 @@ namespace App\Transformer\Api; use App\Profile; +use App\Services\AccountService; use App\Services\PronounService; use App\User; use App\UserSetting; @@ -74,6 +75,16 @@ class AccountTransformer extends Fractal\TransformerAbstract 'location' => $profile->location, ]; + if ($profile->moved_to_profile_id) { + $newProfile = AccountService::get($profile->moved_to_profile_id); + if ($newProfile && isset($newProfile['id'], $newProfile['acct'])) { + $res['moved'] = [ + 'id' => $newProfile['id'], + 'acct' => $newProfile['acct'], + ]; + } + } + return $res; } diff --git a/app/Transformer/Api/Mastodon/v1/AccountTransformer.php b/app/Transformer/Api/Mastodon/v1/AccountTransformer.php index 36830fa79..d7911d617 100644 --- a/app/Transformer/Api/Mastodon/v1/AccountTransformer.php +++ b/app/Transformer/Api/Mastodon/v1/AccountTransformer.php @@ -3,6 +3,7 @@ namespace App\Transformer\Api\Mastodon\v1; use App\Profile; +use App\Services\AccountService; use League\Fractal; class AccountTransformer extends Fractal\TransformerAbstract @@ -12,7 +13,7 @@ class AccountTransformer extends Fractal\TransformerAbstract $local = $profile->domain == null; $username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0]; - return [ + $res = [ 'id' => (string) $profile->id, 'username' => $username, 'acct' => $username, @@ -34,5 +35,17 @@ class AccountTransformer extends Fractal\TransformerAbstract 'moved' => null, 'fields' => [], ]; + + if ($profile->moved_to_profile_id) { + $newProfile = AccountService::get($profile->moved_to_profile_id); + if ($newProfile && isset($newProfile['id'], $newProfile['acct'])) { + $res['moved'] = [ + 'id' => $newProfile['id'], + 'acct' => $newProfile['acct'], + ]; + } + } + + return $res; } }