1
0
Fork 0
forked from mirror/pixelfed

Update ApiV1Controller, fix timelline pagination

This commit is contained in:
Daniel Supernault 2022-04-02 16:18:13 -06:00
parent 9da9b4c41a
commit a5cdc28b6c
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -1684,7 +1684,7 @@ class ApiV1Controller extends Controller
->whereIn('profile_id', $following)
->whereIn('visibility',['public', 'unlisted', 'private'])
->latest()
->take($limit)
->take(($limit * 2))
->get()
->map(function($s) use($pid) {
$status = StatusService::getMastodon($s['id']);
@ -1701,6 +1701,7 @@ class ApiV1Controller extends Controller
->filter(function($status) {
return $status && isset($status['account']);
})
->take($limit)
->values()
->toArray();
} else {
@ -1715,7 +1716,7 @@ class ApiV1Controller extends Controller
->whereIn('profile_id', $following)
->whereIn('visibility',['public', 'unlisted', 'private'])
->latest()
->take($limit)
->take(($limit * 2))
->get()
->map(function($s) use($pid) {
$status = StatusService::getMastodon($s['id']);
@ -1732,6 +1733,7 @@ class ApiV1Controller extends Controller
->filter(function($status) {
return $status && isset($status['account']);
})
->take($limit)
->values()
->toArray();
}
@ -1739,6 +1741,63 @@ class ApiV1Controller extends Controller
return $this->json($res);
}
/**
* GET /api/v1/timelines/public
*
*
* @return StatusTransformer
*/
public function timelinePublic(Request $request)
{
$this->validate($request,[
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'limit' => 'nullable|integer|max:100'
]);
$min = $request->input('min_id');
$max = $request->input('max_id');
$limit = $request->input('limit') ?? 20;
$user = $request->user();
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
Cache::remember('api:v1:timelines:public:cache_check', 10368000, function() {
if(PublicTimelineService::count() == 0) {
PublicTimelineService::warmCache(true, 400);
}
});
if ($max) {
$feed = PublicTimelineService::getRankedMaxId($max, $limit + 5);
} else if ($min) {
$feed = PublicTimelineService::getRankedMinId($min, $limit + 5);
} else {
$feed = PublicTimelineService::get(0, $limit + 5);
}
$res = collect($feed)
->map(function($k) use($user) {
$status = StatusService::getMastodon($k);
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
return false;
}
if($user) {
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $status['id']);
}
return $status;
})
->filter(function($s) use($filtered) {
return $s && isset($s['account']) && in_array($s['account']['id'], $filtered) == false;
})
->take($limit)
->values()
->toArray();
return $this->json($res);
}
/**
* GET /api/v1/conversations
*
@ -1805,62 +1864,6 @@ class ApiV1Controller extends Controller
return $this->json($dms);
}
/**
* GET /api/v1/timelines/public
*
*
* @return StatusTransformer
*/
public function timelinePublic(Request $request)
{
$this->validate($request,[
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'limit' => 'nullable|integer|max:100'
]);
$min = $request->input('min_id');
$max = $request->input('max_id');
$limit = $request->input('limit') ?? 20;
$user = $request->user();
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
Cache::remember('api:v1:timelines:public:cache_check', 10368000, function() {
if(PublicTimelineService::count() == 0) {
PublicTimelineService::warmCache(true, 400);
}
});
if ($max) {
$feed = PublicTimelineService::getRankedMaxId($max, $limit);
} else if ($min) {
$feed = PublicTimelineService::getRankedMinId($min, $limit);
} else {
$feed = PublicTimelineService::get(0, $limit);
}
$res = collect($feed)
->map(function($k) use($user) {
$status = StatusService::getMastodon($k);
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
return false;
}
if($user) {
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $status['id']);
}
return $status;
})
->filter(function($s) use($filtered) {
return $s && isset($s['account']) && in_array($s['account']['id'], $filtered) == false;
})
->values()
->toArray();
return $this->json($res);
}
/**
* GET /api/v1/statuses/{id}
*