mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Update LikeController, hide like counts
This commit is contained in:
parent
477db75896
commit
ea68724054
1 changed files with 49 additions and 49 deletions
|
@ -13,60 +13,60 @@ use App\Services\StatusService;
|
|||
|
||||
class LikeController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'item' => 'required|integer|min:1',
|
||||
]);
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'item' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
$status = Status::findOrFail($request->input('item'));
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
$status = Status::findOrFail($request->input('item'));
|
||||
|
||||
$count = $status->likes()->count();
|
||||
$count = $status->likes()->count();
|
||||
|
||||
if ($status->likes()->whereProfileId($profile->id)->count() !== 0) {
|
||||
$like = Like::whereProfileId($profile->id)->whereStatusId($status->id)->firstOrFail();
|
||||
$like->forceDelete();
|
||||
$count--;
|
||||
$status->likes_count = $count;
|
||||
$status->save();
|
||||
} else {
|
||||
$like = Like::firstOrCreate([
|
||||
'profile_id' => $user->profile_id,
|
||||
'status_id' => $status->id
|
||||
]);
|
||||
if($like->wasRecentlyCreated == true) {
|
||||
$count++;
|
||||
$status->likes_count = $count;
|
||||
$like->status_profile_id = $status->profile_id;
|
||||
$like->is_comment = in_array($status->type, [
|
||||
'photo',
|
||||
'photo:album',
|
||||
'video',
|
||||
'video:album',
|
||||
'photo:video:album'
|
||||
]) == false;
|
||||
$like->save();
|
||||
$status->save();
|
||||
LikePipeline::dispatch($like);
|
||||
}
|
||||
}
|
||||
if ($status->likes()->whereProfileId($profile->id)->count() !== 0) {
|
||||
$like = Like::whereProfileId($profile->id)->whereStatusId($status->id)->firstOrFail();
|
||||
$like->forceDelete();
|
||||
$count--;
|
||||
$status->likes_count = $count;
|
||||
$status->save();
|
||||
} else {
|
||||
$like = Like::firstOrCreate([
|
||||
'profile_id' => $user->profile_id,
|
||||
'status_id' => $status->id
|
||||
]);
|
||||
if($like->wasRecentlyCreated == true) {
|
||||
$count++;
|
||||
$status->likes_count = $count;
|
||||
$like->status_profile_id = $status->profile_id;
|
||||
$like->is_comment = in_array($status->type, [
|
||||
'photo',
|
||||
'photo:album',
|
||||
'video',
|
||||
'video:album',
|
||||
'photo:video:album'
|
||||
]) == false;
|
||||
$like->save();
|
||||
$status->save();
|
||||
LikePipeline::dispatch($like);
|
||||
}
|
||||
}
|
||||
|
||||
Cache::forget('status:'.$status->id.':likedby:userid:'.$user->id);
|
||||
StatusService::del($status->id);
|
||||
Cache::forget('status:'.$status->id.':likedby:userid:'.$user->id);
|
||||
StatusService::del($status->id);
|
||||
|
||||
if ($request->ajax()) {
|
||||
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count];
|
||||
} else {
|
||||
$response = redirect($status->url());
|
||||
}
|
||||
if ($request->ajax()) {
|
||||
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => 0];
|
||||
} else {
|
||||
$response = redirect($status->url());
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue