mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
Merge pull request #1418 from pixelfed/frontend-ui-refactor
Update StatusTransformer, cache counts
This commit is contained in:
commit
0b4dc109f8
7 changed files with 40 additions and 18 deletions
|
@ -20,10 +20,11 @@ class LikeController extends Controller
|
|||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'item' => 'required|integer|min:1',
|
||||
]);
|
||||
'item' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$profile = Auth::user()->profile;
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
$status = Status::withCount('likes')->findOrFail($request->input('item'));
|
||||
|
||||
$count = $status->likes_count;
|
||||
|
@ -32,19 +33,24 @@ class LikeController extends Controller
|
|||
$like = Like::whereProfileId($profile->id)->whereStatusId($status->id)->firstOrFail();
|
||||
$like->forceDelete();
|
||||
$count--;
|
||||
if($count >= 0) {
|
||||
$status->likes_count = $count;
|
||||
$status->save();
|
||||
}
|
||||
} else {
|
||||
$like = new Like();
|
||||
$like->profile_id = $profile->id;
|
||||
$like->status_id = $status->id;
|
||||
$like->save();
|
||||
$count++;
|
||||
if($count >= 0) {
|
||||
$status->likes_count = $count;
|
||||
$status->save();
|
||||
}
|
||||
LikePipeline::dispatch($like);
|
||||
}
|
||||
|
||||
$likes = Like::whereProfileId($profile->id)
|
||||
->orderBy('id', 'desc')
|
||||
->take(1000)
|
||||
->pluck('status_id');
|
||||
Cache::forget('status:'.$status->id.':likedby:userid:'.$user->id);
|
||||
|
||||
if ($request->ajax()) {
|
||||
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count];
|
||||
|
|
|
@ -234,7 +234,8 @@ class StatusController extends Controller
|
|||
'item' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$profile = Auth::user()->profile;
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
$status = Status::withCount('shares')->findOrFail($request->input('item'));
|
||||
|
||||
$count = $status->shares_count;
|
||||
|
@ -259,6 +260,13 @@ class StatusController extends Controller
|
|||
$count++;
|
||||
SharePipeline::dispatch($share);
|
||||
}
|
||||
|
||||
if($count >= 0) {
|
||||
$status->reblogs_count = $count;
|
||||
$status->save();
|
||||
}
|
||||
|
||||
Cache::forget('status:'.$status->id.':sharedby:userid:'.$user->id);
|
||||
|
||||
if ($request->ajax()) {
|
||||
$response = ['code' => 200, 'msg' => 'Share saved', 'count' => $count];
|
||||
|
|
|
@ -150,8 +150,12 @@ class Status extends Model
|
|||
if(Auth::check() == false) {
|
||||
return false;
|
||||
}
|
||||
$profile = Auth::user()->profile;
|
||||
return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count();
|
||||
$user = Auth::user();
|
||||
$id = $this->id;
|
||||
return Cache::remember('status:'.$this->id.':likedby:userid:'.$user->id, now()->addHours(30), function() use($user, $id) {
|
||||
$profile = $user->profile;
|
||||
return Like::whereProfileId($profile->id)->whereStatusId($id)->count();
|
||||
});
|
||||
}
|
||||
|
||||
public function likedBy()
|
||||
|
@ -191,9 +195,12 @@ class Status extends Model
|
|||
if(Auth::check() == false) {
|
||||
return false;
|
||||
}
|
||||
$profile = Auth::user()->profile;
|
||||
|
||||
return self::whereProfileId($profile->id)->whereReblogOfId($this->id)->count();
|
||||
$user = Auth::user();
|
||||
$id = $this->id;
|
||||
return Cache::remember('status:'.$this->id.':sharedby:userid:'.$user->id, now()->addHours(30), function() use($user, $id) {
|
||||
$profile = $user->profile;
|
||||
return self::whereProfileId($profile->id)->whereReblogOfId($id)->count();
|
||||
});
|
||||
}
|
||||
|
||||
public function sharedBy()
|
||||
|
|
|
@ -27,8 +27,8 @@ class StatusTransformer extends Fractal\TransformerAbstract
|
|||
'content' => $status->rendered ?? $status->caption,
|
||||
'created_at' => $status->created_at->format('c'),
|
||||
'emojis' => [],
|
||||
'reblogs_count' => $status->shares()->count(),
|
||||
'favourites_count' => $status->likes()->count(),
|
||||
'reblogs_count' => $status->reblogs_count != 0 ? $status->reblogs_count: $status->shares()->count(),
|
||||
'favourites_count' => $status->likes_count != 0 ? $status->likes_count: $status->likes()->count(),
|
||||
'reblogged' => $status->shared(),
|
||||
'favourited' => $status->liked(),
|
||||
'muted' => null,
|
||||
|
@ -47,7 +47,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
|
|||
'comments_disabled' => $status->comments_disabled ? true : false,
|
||||
'thread' => false,
|
||||
'replies' => [],
|
||||
'parent' => $status->parent() ? $this->transform($status->parent()) : [],
|
||||
'parent' => [],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
2
public/js/activity.js
vendored
2
public/js/activity.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"/js/manifest.js": "/js/manifest.js?id=01c8731923a46c30aaed",
|
||||
"/js/vendor.js": "/js/vendor.js?id=cb03d3c4fd7d4093f5b1",
|
||||
"/js/activity.js": "/js/activity.js?id=988d3df8e9dc2d16a43c",
|
||||
"/js/activity.js": "/js/activity.js?id=e9d373d06150ccd77557",
|
||||
"/js/app.js": "/js/app.js?id=025bc09bbc4e2d1898e3",
|
||||
"/css/app.css": "/css/app.css?id=461b8782fc167f734ffa",
|
||||
"/css/appdark.css": "/css/appdark.css?id=34cd81dd9c8bc68cfd51",
|
||||
|
|
|
@ -225,6 +225,7 @@ export default {
|
|||
break;
|
||||
case 'like':
|
||||
case 'favourite':
|
||||
case 'comment':
|
||||
return n.status.url;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue