diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f032f0e0..5864089c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ - Updated StatusTransformers, add liked_by attribute. ([372bacb0](https://github.com/pixelfed/pixelfed/commit/372bacb0)) - Updated PostComponent, change like logic. ([0a35f5d6](https://github.com/pixelfed/pixelfed/commit/0a35f5d6)) - Updated Timeline component, change like logic. ([7bcbf96b](https://github.com/pixelfed/pixelfed/commit/7bcbf96b)) +- Updated LikeService, fix likedBy method. ([a5e64da6](https://github.com/pixelfed/pixelfed/commit/a5e64da6)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10) diff --git a/app/Services/LikeService.php b/app/Services/LikeService.php index 8ed2bfc3a..36f31ee44 100644 --- a/app/Services/LikeService.php +++ b/app/Services/LikeService.php @@ -50,13 +50,27 @@ class LikeService { public static function likedBy($status) { - if(!$status->likes_count) { - return [ - 'username' => null, - 'others' => false - ]; + $empty = [ + 'username' => null, + 'others' => false + ]; + + if(!$status) { + return $empty; } - $id = Like::whereStatusId($status->id)->first()->profile_id; + + if(!$status->likes_count) { + return $empty; + } + + $like = Like::whereStatusId($status->id)->first(); + + if(!$like) { + return $empty; + } + + $id = $like->profile_id; + return [ 'username' => ProfileService::get($id)['username'], 'others' => $status->likes_count >= 5,