Skip to content

Commit

Permalink
Update ApiV1Controller, improve timeline account hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Mar 25, 2023
1 parent 5bf1c61 commit 4e79c77
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions app/Http/Controllers/Api/ApiV1Controller.php
Expand Up @@ -2130,6 +2130,10 @@ public function timelineHome(Request $request)
->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;
Expand All @@ -2138,6 +2142,8 @@ public function timelineHome(Request $request)
return false;
}

$status['account'] = $account;

if($pid) {
$status['favourited'] = (bool) LikeService::liked($pid, $s['id']);
$status['reblogged'] = (bool) ReblogService::get($pid, $status['id']);
Expand Down Expand Up @@ -2167,7 +2173,7 @@ public function timelineHome(Request $request)
->get()
->map(function($s) use($pid, $napi) {
try {
$account = AccountService::get($s['profile_id'], true);
$account = $napi ? AccountService::get($s['profile_id'], true) : AccountService::getMastodon($s['profile_id'], true);
if(!$account) {
return false;
}
Expand All @@ -2179,6 +2185,8 @@ public function timelineHome(Request $request)
return false;
}

$status['account'] = $account;

if($pid) {
$status['favourited'] = (bool) LikeService::liked($pid, $s['id']);
$status['reblogged'] = (bool) ReblogService::get($pid, $status['id']);
Expand Down Expand Up @@ -2289,11 +2297,21 @@ public function timelinePublic(Request $request)
}
})
->map(function($k) use($user, $napi) {
$status = $napi ? StatusService::get($k) : StatusService::getMastodon($k);
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
try {
$status = $napi ? StatusService::get($k) : StatusService::getMastodon($k);
} catch(\Exception $e) {
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
return false;
}
}

$account = $napi ? AccountService::get($status['account']['id'], true) : AccountService::getMastodon($status['account']['id'], true);
if(!$account) {
return false;
}

$status['account'] = $account;

if($user) {
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $status['id']);
Expand Down

0 comments on commit 4e79c77

Please sign in to comment.