1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-27 10:16:47 +00:00
pixelfed/app/Transformer/Api/RelationshipTransformer.php

41 lines
1.1 KiB
PHP
Raw Normal View History

2018-11-19 04:53:05 +00:00
<?php
namespace App\Transformer\Api;
use Auth;
2019-08-06 03:16:29 +00:00
use App\{
FollowRequest,
Profile
};
2018-11-19 04:53:05 +00:00
use League\Fractal;
class RelationshipTransformer extends Fractal\TransformerAbstract
{
public function transform(Profile $profile)
{
2019-06-10 02:36:08 +00:00
$auth = Auth::check();
2019-09-02 00:27:13 +00:00
if(!$auth) {
return [];
}
2019-06-10 02:36:08 +00:00
$user = $auth ? Auth::user()->profile : false;
2019-08-06 03:16:29 +00:00
$requested = false;
if($user) {
$requested = FollowRequest::whereFollowerId($user->id)
->whereFollowingId($profile->id)
->exists();
}
2018-11-19 04:53:05 +00:00
return [
'id' => (string) $profile->id,
2019-06-10 02:36:08 +00:00
'following' => $auth ? $user->follows($profile) : false,
'followed_by' => $auth ? $user->followedBy($profile) : false,
'blocking' => $auth ? $user->blockedIds()->contains($profile->id) : false,
'muting' => $auth ? $user->mutedIds()->contains($profile->id) : false,
2018-11-19 04:53:05 +00:00
'muting_notifications' => null,
2019-08-06 03:16:29 +00:00
'requested' => $requested,
2018-11-19 04:53:05 +00:00
'domain_blocking' => null,
'showing_reblogs' => null,
'endorsed' => false
2018-11-19 04:53:05 +00:00
];
}
}