Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix photo_reblogs_only not working (wasn't implemented) #12

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 62 additions & 105 deletions app/Http/Controllers/Api/ApiV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,7 @@ public function timelineHome(Request $request)
'max_id' => 'sometimes|integer|min:0|max:'.PHP_INT_MAX,
'limit' => 'sometimes|integer|min:1',
'include_reblogs' => 'sometimes',
'photos_reblogs_only' => 'sometimes',
]);

$napi = $request->has(self::PF_API_ENTITY_KEY);
Expand All @@ -2481,12 +2482,10 @@ public function timelineHome(Request $request)
}
$pid = $request->user()->profile_id;
$includeReblogs = $request->filled('include_reblogs') ? $request->boolean('include_reblogs') : false;
$nullFields = $includeReblogs ?
['in_reply_to_id'] :
['in_reply_to_id', 'reblog_of_id'];
$inTypes = $includeReblogs ?
['photo', 'photo:album', 'video', 'video:album', 'photo:video:album', 'share'] :
['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'];
$PhotosReblogsOnly = $request->filled('photos_reblogs_only') ? $request->boolean('photos_reblogs_only') : true;
$nullFields = $includeReblogs ? ['statuses.in_reply_to_id'] : ['statuses.in_reply_to_id', 'statuses.reblog_of_id'];
$inTypesStrict = ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'];
$inTypes = $includeReblogs ? [...$inTypesStrict, 'share'] : $inTypesStrict;
AccountService::setLastActive($request->user()->id);

if (config('exp.cached_home_timeline')) {
Expand Down Expand Up @@ -2578,118 +2577,76 @@ public function timelineHome(Request $request)
$following = array_diff($following, $muted);
}

$query = Status::select(
'statuses.id as id',
'statuses.profile_id as profile_id',
'statuses.type as type',
'statuses.visibility as visibility',
'statuses.in_reply_to_id as in_reply_to_id',
'statuses.reblog_of_id as reblog_of_id',
'reblog.type as reblog_type'
);

if ($min || $max) {
$dir = $min ? '>' : '<';
$id = $min ?? $max;
$res = Status::select(
'id',
'profile_id',
'type',
'visibility',
'in_reply_to_id',
'reblog_of_id'
)
->where('id', $dir, $id)
->whereNull($nullFields)
->whereIntegerInRaw('profile_id', $following)
->whereIn('type', $inTypes)
->whereIn('visibility', ['public', 'unlisted', 'private'])
->orderByDesc('id')
->take(($limit * 2))
->get()
->map(function ($s) use ($pid, $napi) {
try {
$account = $napi ? AccountService::get($s['profile_id'], true) : AccountService::getMastodon($s['profile_id'], true);
if (! $account) {
return false;
}
$status = $napi ? StatusService::get($s['id'], false) : StatusService::getMastodon($s['id'], false);
if (! $status || ! isset($status['account']) || ! isset($status['account']['id'])) {
return false;
}
} catch (\Exception $e) {
return false;
}
$query = $query->where('statuses.id', $dir, $id);
}

$status['account'] = $account;
$query = $query->whereNull($nullFields)
->whereIntegerInRaw('statuses.profile_id', $following)
->whereIn('statuses.type', $inTypes)
->whereIn('statuses.visibility', ['public', 'unlisted', 'private'])
->leftJoin('statuses as reblog','reblog.id', '=', 'statuses.reblog_of_id');

if ($pid) {
$status['favourited'] = (bool) LikeService::liked($pid, $s['id']);
$status['reblogged'] = (bool) ReblogService::get($pid, $status['id']);
$status['bookmarked'] = (bool) BookmarkService::get($pid, $status['id']);
}
if ($PhotosReblogsOnly) {
$query = $query->where(function ($query) use ($inTypesStrict) {
$query->whereNull('statuses.reblog_of_id')
->orWhereIn('reblog.type', $inTypesStrict);
});
}

return $status;
})
->filter(function ($status) {
return $status && isset($status['account']);
})
->map(function ($status) use ($pid) {
if (! empty($status['reblog'])) {
$status['reblog']['favourited'] = (bool) LikeService::liked($pid, $status['reblog']['id']);
$status['reblog']['reblogged'] = (bool) ReblogService::get($pid, $status['reblog']['id']);
$status['bookmarked'] = (bool) BookmarkService::get($pid, $status['id']);
$res = $query->orderByDesc('id')
->take(($limit * 2))
->get()
->map(function ($s) use ($pid, $napi) {
try {
$account = $napi ? AccountService::get($s['profile_id'], true) : AccountService::getMastodon($s['profile_id'], true);
if (! $account) {
return false;
}

return $status;
})
->take($limit)
->values();
} else {
$res = Status::select(
'id',
'profile_id',
'type',
'visibility',
'in_reply_to_id',
'reblog_of_id',
)
->whereNull($nullFields)
->whereIntegerInRaw('profile_id', $following)
->whereIn('type', $inTypes)
->whereIn('visibility', ['public', 'unlisted', 'private'])
->orderByDesc('id')
->take(($limit * 2))
->get()
->map(function ($s) use ($pid, $napi) {
try {
$account = $napi ? AccountService::get($s['profile_id'], true) : AccountService::getMastodon($s['profile_id'], true);
if (! $account) {
return false;
}
$status = $napi ? StatusService::get($s['id'], false) : StatusService::getMastodon($s['id'], false);
if (! $status || ! isset($status['account']) || ! isset($status['account']['id'])) {
return false;
}
} catch (\Exception $e) {
$status = $napi ? StatusService::get($s['id'], false) : StatusService::getMastodon($s['id'], false);
if (! $status || ! isset($status['account']) || ! isset($status['account']['id'])) {
return false;
}
} catch (\Exception $e) {
return false;
}

$status['account'] = $account;
$status['account'] = $account;

if ($pid) {
$status['favourited'] = (bool) LikeService::liked($pid, $s['id']);
$status['reblogged'] = (bool) ReblogService::get($pid, $status['id']);
$status['bookmarked'] = (bool) BookmarkService::get($pid, $status['id']);
}
if ($pid) {
$status['favourited'] = (bool) LikeService::liked($pid, $s['id']);
$status['reblogged'] = (bool) ReblogService::get($pid, $status['id']);
$status['bookmarked'] = (bool) BookmarkService::get($pid, $status['id']);
}

return $status;
})
->filter(function ($status) {
return $status && isset($status['account']);
})
->map(function ($status) use ($pid) {
if (! empty($status['reblog'])) {
$status['reblog']['favourited'] = (bool) LikeService::liked($pid, $status['reblog']['id']);
$status['reblog']['reblogged'] = (bool) ReblogService::get($pid, $status['reblog']['id']);
$status['bookmarked'] = (bool) BookmarkService::get($pid, $status['id']);
}
return $status;
})
->filter(function ($status) {
return $status && isset($status['account']);
})
->map(function ($status) use ($pid) {
if (! empty($status['reblog'])) {
$status['reblog']['favourited'] = (bool) LikeService::liked($pid, $status['reblog']['id']);
$status['reblog']['reblogged'] = (bool) ReblogService::get($pid, $status['reblog']['id']);
$status['bookmarked'] = (bool) BookmarkService::get($pid, $status['id']);
}

return $status;
})
->take($limit)
->values();
}
return $status;
})
->take($limit)
->values();

$baseUrl = config('app.url').'/api/v1/timelines/home?limit='.$limit.'&';
$minId = $res->map(function ($s) {
Expand Down
2 changes: 0 additions & 2 deletions public/js/home.chunk.413bd879230ad9b9.js

This file was deleted.

2 changes: 2 additions & 0 deletions public/js/home.chunk.b48e99de4a776af7.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"/js/groups.js": "/js/groups.js?id=f34a0c482adfc25f4399cf9e47c899f2",
"/js/group-status.js": "/js/group-status.js?id=a1e47d8989344c4750fb7658d548de65",
"/js/group-topic-feed.js": "/js/group-topic-feed.js?id=16fa7d88f104424ad33c244af6cf5d77",
"/js/manifest.js": "/js/manifest.js?id=a906cf9298fc002d56ecbcb6e2ab9abe",
"/js/home.chunk.413bd879230ad9b9.js": "/js/home.chunk.413bd879230ad9b9.js?id=187339638c82ee4413d22c3442b6b45b",
"/js/manifest.js": "/js/manifest.js?id=ae167fd2472fc8a55a838c2c1469a6ee",
"/js/home.chunk.b48e99de4a776af7.js": "/js/home.chunk.b48e99de4a776af7.js?id=326454add948d0480f6cea04fcf33335",
"/js/compose.chunk.0845b41cb5aa952c.js": "/js/compose.chunk.0845b41cb5aa952c.js?id=4dd930fbcfe5ec41f94ad59f18a6fd86",
"/js/post.chunk.097d29f0092356e6.js": "/js/post.chunk.097d29f0092356e6.js?id=cd3f40a60eb992272f220483ed44315c",
"/js/profile.chunk.40bdacf2d010d090.js": "/js/profile.chunk.40bdacf2d010d090.js?id=2486af4ac742c31faade375e45e7582f",
Expand Down
Loading
Loading