mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-01-30 16:30:45 +00:00
Update PublicApiController
This commit is contained in:
parent
14261543ae
commit
9a96145285
1 changed files with 62 additions and 40 deletions
|
@ -328,6 +328,7 @@ class PublicApiController extends Controller
|
||||||
->orWhere('status', '!=', null)
|
->orWhere('status', '!=', null)
|
||||||
->pluck('id');
|
->pluck('id');
|
||||||
});
|
});
|
||||||
|
|
||||||
$filters = UserFilter::whereUserId($pid)
|
$filters = UserFilter::whereUserId($pid)
|
||||||
->whereFilterableType('App\Profile')
|
->whereFilterableType('App\Profile')
|
||||||
->whereIn('filter_type', ['mute', 'block'])
|
->whereIn('filter_type', ['mute', 'block'])
|
||||||
|
@ -457,51 +458,72 @@ class PublicApiController extends Controller
|
||||||
'only_media' => 'nullable',
|
'only_media' => 'nullable',
|
||||||
'pinned' => 'nullable',
|
'pinned' => 'nullable',
|
||||||
'exclude_replies' => 'nullable',
|
'exclude_replies' => 'nullable',
|
||||||
'max_id' => 'nullable|integer|min:1',
|
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
'since_id' => 'nullable|integer|min:1',
|
'since_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
'min_id' => 'nullable|integer|min:1',
|
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
'limit' => 'nullable|integer|min:1|max:24'
|
'limit' => 'nullable|integer|min:1|max:24'
|
||||||
]);
|
]);
|
||||||
$limit = $request->limit ?? 20;
|
|
||||||
$max_id = $request->max_id ?? false;
|
|
||||||
$min_id = $request->min_id ?? false;
|
|
||||||
$since_id = $request->since_id ?? false;
|
|
||||||
$only_media = $request->only_media ?? false;
|
|
||||||
$user = Auth::user();
|
|
||||||
$account = Profile::whereNull('status')->findOrFail($id);
|
|
||||||
$statuses = Status::whereProfileId($id)
|
|
||||||
->whereNull('uri');
|
|
||||||
|
|
||||||
if(!$user || $user->profile->id != $account->id && !$user->profile->follows($account)) {
|
$profile = Profile::whereNull('status')->findOrFail($id);
|
||||||
$statuses = $statuses->whereVisibility('public');
|
|
||||||
|
$limit = $request->limit ?? 9;
|
||||||
|
$max_id = $request->max_id;
|
||||||
|
$min_id = $request->min_id;
|
||||||
|
$scope = $request->only_media == true ?
|
||||||
|
['photo', 'photo:album', 'video', 'video:album'] :
|
||||||
|
['photo', 'photo:album', 'video', 'video:album', 'share', 'reply'];
|
||||||
|
|
||||||
|
if($profile->is_private) {
|
||||||
|
if(!Auth::check()) {
|
||||||
|
return response()->json([]);
|
||||||
|
}
|
||||||
|
$pid = Auth::user()->profile->id;
|
||||||
|
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
|
||||||
|
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
||||||
|
return $following->push($pid)->toArray();
|
||||||
|
});
|
||||||
|
$visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : [];
|
||||||
} else {
|
} else {
|
||||||
$statuses = $statuses->whereIn('visibility', ['public', 'unlisted', 'private']);
|
if(Auth::check()) {
|
||||||
|
$pid = Auth::user()->profile->id;
|
||||||
|
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
|
||||||
|
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
||||||
|
return $following->push($pid)->toArray();
|
||||||
|
});
|
||||||
|
$visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : ['public'];
|
||||||
|
} else {
|
||||||
|
$visibility = ['public'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if($only_media == true) {
|
|
||||||
$statuses = $statuses
|
|
||||||
->whereHas('media')
|
$dir = $min_id ? '>' : '<';
|
||||||
->whereNull('in_reply_to_id')
|
$id = $min_id ?? $max_id;
|
||||||
->whereNull('reblog_of_id');
|
$timeline = Status::select(
|
||||||
}
|
'id',
|
||||||
if($id == $account->id && !$max_id && !$min_id && !$since_id) {
|
'uri',
|
||||||
$statuses = $statuses->orderBy('id', 'desc')
|
'caption',
|
||||||
->simplePaginate($limit);
|
'rendered',
|
||||||
} else if($since_id) {
|
'profile_id',
|
||||||
$statuses = $statuses->where('id', '>', $since_id)
|
'type',
|
||||||
->orderBy('id', 'DESC')
|
'in_reply_to_id',
|
||||||
->simplePaginate($limit);
|
'reblog_of_id',
|
||||||
} else if($min_id) {
|
'is_nsfw',
|
||||||
$statuses = $statuses->where('id', '>', $min_id)
|
'scope',
|
||||||
->orderBy('id', 'ASC')
|
'local',
|
||||||
->simplePaginate($limit);
|
'created_at',
|
||||||
} else if($max_id) {
|
'updated_at'
|
||||||
$statuses = $statuses->where('id', '<', $max_id)
|
)->whereProfileId($profile->id)
|
||||||
->orderBy('id', 'DESC')
|
->whereIn('type', $scope)
|
||||||
->simplePaginate($limit);
|
->whereLocal(true)
|
||||||
} else {
|
->whereNull('uri')
|
||||||
$statuses = $statuses->orderBy('id', 'desc')->simplePaginate($limit);
|
->where('id', $dir, $id)
|
||||||
}
|
->whereIn('visibility',$visibility)
|
||||||
$resource = new Fractal\Resource\Collection($statuses, new StatusTransformer());
|
->orderBy('created_at', 'desc')
|
||||||
|
->limit($limit)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$resource = new Fractal\Resource\Collection($timeline, new StatusTransformer());
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
$res = $this->fractal->createData($resource)->toArray();
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
|
|
Loading…
Reference in a new issue