forked from mirror/pixelfed
Update ApiV1Controller, fix public timeline scope, properly support both local + remote parameters
This commit is contained in:
parent
6cb1484b3e
commit
d6eac65555
1 changed files with 35 additions and 3 deletions
|
@ -2634,8 +2634,8 @@ class ApiV1Controller extends Controller
|
||||||
}
|
}
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
$remote = $request->has('remote');
|
$remote = $request->has('remote') && $request->boolean('remote');
|
||||||
$local = $request->has('local');
|
$local = $request->boolean('local');
|
||||||
$userRoleKey = $remote ? 'can-view-network-feed' : 'can-view-public-feed';
|
$userRoleKey = $remote ? 'can-view-network-feed' : 'can-view-public-feed';
|
||||||
if ($user->has_roles && ! UserRoleService::can($userRoleKey, $user->id)) {
|
if ($user->has_roles && ! UserRoleService::can($userRoleKey, $user->id)) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -2646,7 +2646,36 @@ class ApiV1Controller extends Controller
|
||||||
$hideNsfw = config('instance.hide_nsfw_on_public_feeds');
|
$hideNsfw = config('instance.hide_nsfw_on_public_feeds');
|
||||||
$amin = SnowflakeService::byDate(now()->subDays(config('federation.network_timeline_days_falloff')));
|
$amin = SnowflakeService::byDate(now()->subDays(config('federation.network_timeline_days_falloff')));
|
||||||
|
|
||||||
if ($remote) {
|
if ($local && $remote) {
|
||||||
|
$feed = Status::select(
|
||||||
|
'id',
|
||||||
|
'uri',
|
||||||
|
'type',
|
||||||
|
'scope',
|
||||||
|
'created_at',
|
||||||
|
'profile_id',
|
||||||
|
'in_reply_to_id',
|
||||||
|
'reblog_of_id'
|
||||||
|
)
|
||||||
|
->when($minOrMax, function ($q, $minOrMax) use ($min, $max) {
|
||||||
|
$dir = $min ? '>' : '<';
|
||||||
|
$id = $min ?? $max;
|
||||||
|
|
||||||
|
return $q->where('id', $dir, $id);
|
||||||
|
})
|
||||||
|
->whereNull(['in_reply_to_id', 'reblog_of_id'])
|
||||||
|
->when($hideNsfw, function ($q, $hideNsfw) {
|
||||||
|
return $q->where('is_nsfw', false);
|
||||||
|
})
|
||||||
|
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
|
->whereScope('public')
|
||||||
|
->where('id', '>', $amin)
|
||||||
|
->orderByDesc('id')
|
||||||
|
->limit(($limit * 2))
|
||||||
|
->pluck('id')
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
} elseif ($remote && ! $local) {
|
||||||
if (config('instance.timeline.network.cached')) {
|
if (config('instance.timeline.network.cached')) {
|
||||||
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function () {
|
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function () {
|
||||||
if (NetworkTimelineService::count() == 0) {
|
if (NetworkTimelineService::count() == 0) {
|
||||||
|
@ -2799,6 +2828,9 @@ class ApiV1Controller extends Controller
|
||||||
if ($remote) {
|
if ($remote) {
|
||||||
$baseUrl .= 'remote=1&';
|
$baseUrl .= 'remote=1&';
|
||||||
}
|
}
|
||||||
|
if ($local) {
|
||||||
|
$baseUrl .= 'local=1&';
|
||||||
|
}
|
||||||
$minId = $res->map(function ($s) {
|
$minId = $res->map(function ($s) {
|
||||||
return ['id' => $s['id']];
|
return ['id' => $s['id']];
|
||||||
})->min('id');
|
})->min('id');
|
||||||
|
|
Loading…
Reference in a new issue