Skip to content

Commit

Permalink
Update HomeTimeline api
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Oct 7, 2021
1 parent bef959f commit e545462
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/Http/Controllers/PublicApiController.php
Expand Up @@ -309,7 +309,7 @@ public function publicTimelineApi(Request $request)
->limit($limit)
->get()
->map(function($s) use ($user) {
$status = StatusService::get($s->id);
$status = StatusService::getFull($s->id, $user->profile_id);
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
return $status;
});
Expand Down Expand Up @@ -341,10 +341,15 @@ public function publicTimelineApi(Request $request)
->whereLocal(true)
->whereScope('public')
->orderBy('id', 'desc')
->simplePaginate($limit);
->limit($limit)
->get()
->map(function($s) use ($user) {
$status = StatusService::getFull($s->id, $user->profile_id);
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
return $status;
});

$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
$res = $this->fractal->createData($fractal)->toArray();
$res = $timeline->toArray();
}

return response()->json($res);
Expand Down
7 changes: 7 additions & 0 deletions app/Services/StatusService.php
Expand Up @@ -40,6 +40,13 @@ public static function get($id, $publicOnly = true)
});
}

public static function getFull($id, $pid, $publicOnly = true)
{
$res = self::get($id, $publicOnly);
$res['relationship'] = RelationshipService::get($pid, $res['account']['id']);
return $res;
}

public static function del($id)
{
$status = self::get($id);
Expand Down

0 comments on commit e545462

Please sign in to comment.