mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Add hashtag timeline to v1 api
This commit is contained in:
parent
dac326e949
commit
241ae0368f
1 changed files with 42 additions and 3 deletions
|
@ -13,11 +13,13 @@ use App\{
|
|||
Bookmark,
|
||||
Follower,
|
||||
FollowRequest,
|
||||
Hashtag,
|
||||
Like,
|
||||
Media,
|
||||
Notification,
|
||||
Profile,
|
||||
Status,
|
||||
StatusHashtag,
|
||||
User,
|
||||
UserFilter,
|
||||
};
|
||||
|
@ -1988,9 +1990,46 @@ class ApiV1Controller extends Controller
|
|||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
|
||||
// todo
|
||||
$res = [];
|
||||
return response()->json($res);
|
||||
$this->validate($request,[
|
||||
'page' => 'nullable|integer|max:40',
|
||||
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||
'limit' => 'nullable|integer|max:40'
|
||||
]);
|
||||
|
||||
$tag = Hashtag::whereName($hashtag)
|
||||
->orWhere('slug', $hashtag)
|
||||
->first();
|
||||
|
||||
if(!$tag) {
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
$min = $request->input('min_id');
|
||||
$max = $request->input('max_id');
|
||||
$limit = $request->input('limit', 20);
|
||||
|
||||
if(!$min && !$max) {
|
||||
$id = 1;
|
||||
$dir = '>';
|
||||
} else {
|
||||
$dir = $min ? '>' : '<';
|
||||
$id = $min ?? $max;
|
||||
}
|
||||
|
||||
$res = StatusHashtag::whereHashtagId($tag->id)
|
||||
->whereStatusVisibility('public')
|
||||
->whereHas('media')
|
||||
->where('status_id', $dir, $id)
|
||||
->latest()
|
||||
->limit($limit)
|
||||
->pluck('status_id')
|
||||
->map(function ($i) {
|
||||
return StatusService::get($i);
|
||||
})
|
||||
->all();
|
||||
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue