|
|
|
|
@ -5,7 +5,6 @@ namespace App\Transformer\Api;
|
|
|
|
|
use App\Models\Profile;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\UserSetting;
|
|
|
|
|
use App\Services\AccountService;
|
|
|
|
|
use App\Services\PronounService;
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
use League\Fractal;
|
|
|
|
|
@ -26,7 +25,6 @@ class AccountTransformer extends Fractal\TransformerAbstract
|
|
|
|
|
return User::whereIsAdmin(true)->pluck('profile_id')->toArray();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$local = $profile->private_key != null;
|
|
|
|
|
$local = $profile->user_id && $profile->private_key != null;
|
|
|
|
|
$hideFollowing = false;
|
|
|
|
|
$hideFollowers = false;
|
|
|
|
|
@ -75,20 +73,38 @@ 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'],
|
|
|
|
|
'avatar' => $newProfile['avatar'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$moved = $this->resolveMoved($profile);
|
|
|
|
|
if ($moved) {
|
|
|
|
|
$res['moved'] = $moved;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function resolveMoved(Profile $profile): ?array
|
|
|
|
|
{
|
|
|
|
|
$targetId = $profile->moved_to_profile_id;
|
|
|
|
|
|
|
|
|
|
if (! $targetId || (string) $targetId === (string) $profile->id) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Cache::remember('pf:acct-trans:moved:'.$targetId, 3600, function () use ($targetId) {
|
|
|
|
|
$target = Profile::find($targetId);
|
|
|
|
|
if (! $target) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$targetLocal = $target->user_id && $target->private_key != null;
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'id' => (string) $target->id,
|
|
|
|
|
'acct' => $targetLocal ? $target->username : substr($target->username, 1),
|
|
|
|
|
'avatar' => $target->avatarUrl(),
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function includeRelationship(Profile $profile)
|
|
|
|
|
{
|
|
|
|
|
return $this->item($profile, new RelationshipTransformer);
|
|
|
|
|
|