Skip to content

Commit

Permalink
Merge pull request #4974 from pixelfed/staging
Browse files Browse the repository at this point in the history
API fixes
  • Loading branch information
dansup committed Mar 5, 2024
2 parents eb19c35 + 03165ea commit 1251bf5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
- Update AccountTransformer, fix follower/following count visibility bug ([542d1106](https://github.com/pixelfed/pixelfed/commit/542d1106))
- Update ProfileMigration model, add target relation ([3f053997](https://github.com/pixelfed/pixelfed/commit/3f053997))
- Update ApiV1Controller, update Notifications endpoint to filter notifications with missing activities ([a933615b](https://github.com/pixelfed/pixelfed/commit/a933615b))
- Update ApiV1Controller, fix public timeline scope, properly support both local + remote parameters ([d6eac655](https://github.com/pixelfed/pixelfed/commit/d6eac655))
- Update ApiV1Controller, handle public feed parameter bug to gracefully fallback to min_id=1 when max_id=0 ([e3826c58](https://github.com/pixelfed/pixelfed/commit/e3826c58))
- Update ApiV1Controller, fix hashtag feed to include private posts from accounts you follow or your own, and your own unlisted posts ([3b5500b3](https://github.com/pixelfed/pixelfed/commit/3b5500b3))
- ([](https://github.com/pixelfed/pixelfed/commit/))
- ([](https://github.com/pixelfed/pixelfed/commit/))

## [v0.11.12 (2024-02-16)](https://github.com/pixelfed/pixelfed/compare/v0.11.11...v0.11.12)
Expand Down
69 changes: 58 additions & 11 deletions app/Http/Controllers/Api/ApiV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2627,15 +2627,18 @@ public function timelinePublic(Request $request)
$napi = $request->has(self::PF_API_ENTITY_KEY);
$min = $request->input('min_id');
$max = $request->input('max_id');
if ($max == 0) {
$min = 1;
}
$minOrMax = $request->anyFilled(['max_id', 'min_id']);
$limit = $request->input('limit') ?? 20;
if ($limit > 40) {
$limit = 40;
}
$user = $request->user();

$remote = $request->has('remote');
$local = $request->has('local');
$remote = $request->has('remote') && $request->boolean('remote');
$local = $request->boolean('local');
$userRoleKey = $remote ? 'can-view-network-feed' : 'can-view-public-feed';
if ($user->has_roles && ! UserRoleService::can($userRoleKey, $user->id)) {
return [];
Expand All @@ -2646,7 +2649,36 @@ public function timelinePublic(Request $request)
$hideNsfw = config('instance.hide_nsfw_on_public_feeds');
$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')) {
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function () {
if (NetworkTimelineService::count() == 0) {
Expand Down Expand Up @@ -2799,6 +2831,9 @@ public function timelinePublic(Request $request)
if ($remote) {
$baseUrl .= 'remote=1&';
}
if ($local) {
$baseUrl .= 'local=1&';
}
$minId = $res->map(function ($s) {
return ['id' => $s['id']];
})->min('id');
Expand Down Expand Up @@ -3600,7 +3635,7 @@ public function timelineHashtag(Request $request, $hashtag)
'min_id' => 'nullable|integer|min:0|max:'.PHP_INT_MAX,
'max_id' => 'nullable|integer|min:0|max:'.PHP_INT_MAX,
'limit' => 'sometimes|integer|min:1',
'only_media' => 'sometimes|boolean',
'only_media' => 'sometimes',
'_pe' => 'sometimes',
]);

Expand Down Expand Up @@ -3635,7 +3670,7 @@ public function timelineHashtag(Request $request, $hashtag)
if ($limit > 40) {
$limit = 40;
}
$onlyMedia = $request->input('only_media', true);
$onlyMedia = $request->boolean('only_media', true);
$pe = $request->has(self::PF_API_ENTITY_KEY);
$pid = $request->user()->profile_id;

Expand All @@ -3661,20 +3696,32 @@ public function timelineHashtag(Request $request, $hashtag)
}

$res = StatusHashtag::whereHashtagId($tag->id)
->whereStatusVisibility('public')
->whereIn('status_visibility', ['public', 'private', 'unlisted'])
->where('status_id', $dir, $id)
->orderBy('status_id', 'desc')
->limit(100)
->pluck('status_id')
->map(function ($i) use ($pe) {
return $pe ? StatusService::get($i) : StatusService::getMastodon($i);
return $pe ? StatusService::get($i, false) : StatusService::getMastodon($i, false);
})
->filter(function ($i) use ($onlyMedia) {
if (! $i) {
->filter(function ($i) use ($onlyMedia, $pid) {
if (! $i || ! isset($i['account'], $i['account']['id'])) {
return false;
}
if ($onlyMedia && ! isset($i['media_attachments']) || ! count($i['media_attachments'])) {
return false;
if ($i['visibility'] === 'unlisted') {
if ((int) $i['account']['id'] !== $pid) {
return false;
}
}
if ($i['visibility'] === 'private') {
if ((int) $i['account']['id'] !== $pid) {
return FollowerService::follows($pid, $i['account']['id'], true);
}
}
if ($onlyMedia == true) {
if (! isset($i['media_attachments']) || ! count($i['media_attachments'])) {
return false;
}
}

return $i && isset($i['account'], $i['url']);
Expand Down

0 comments on commit 1251bf5

Please sign in to comment.