Merge pull request #2747 from pixelfed/staging

Update LikeService, fix likedBy method
This commit is contained in:
daniel 2021-05-03 17:57:56 -06:00 committed by GitHub
commit 4ad3de3b88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View file

@ -82,6 +82,7 @@
- Updated StatusTransformers, add liked_by attribute. ([372bacb0](https://github.com/pixelfed/pixelfed/commit/372bacb0)) - 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 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 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/)) - ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)

View file

@ -50,13 +50,27 @@ class LikeService {
public static function likedBy($status) public static function likedBy($status)
{ {
if(!$status->likes_count) { $empty = [
return [
'username' => null, 'username' => null,
'others' => false '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 [ return [
'username' => ProfileService::get($id)['username'], 'username' => ProfileService::get($id)['username'],
'others' => $status->likes_count >= 5, 'others' => $status->likes_count >= 5,