forked from mirror/pixelfed
Merge pull request #1418 from pixelfed/frontend-ui-refactor
Update StatusTransformer, cache counts
This commit is contained in:
commit
0b4dc109f8
7 changed files with 38 additions and 16 deletions
|
@ -20,10 +20,11 @@ class LikeController extends Controller
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($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'));
|
$status = Status::withCount('likes')->findOrFail($request->input('item'));
|
||||||
|
|
||||||
$count = $status->likes_count;
|
$count = $status->likes_count;
|
||||||
|
@ -32,19 +33,24 @@ class LikeController extends Controller
|
||||||
$like = Like::whereProfileId($profile->id)->whereStatusId($status->id)->firstOrFail();
|
$like = Like::whereProfileId($profile->id)->whereStatusId($status->id)->firstOrFail();
|
||||||
$like->forceDelete();
|
$like->forceDelete();
|
||||||
$count--;
|
$count--;
|
||||||
|
if($count >= 0) {
|
||||||
|
$status->likes_count = $count;
|
||||||
|
$status->save();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$like = new Like();
|
$like = new Like();
|
||||||
$like->profile_id = $profile->id;
|
$like->profile_id = $profile->id;
|
||||||
$like->status_id = $status->id;
|
$like->status_id = $status->id;
|
||||||
$like->save();
|
$like->save();
|
||||||
$count++;
|
$count++;
|
||||||
|
if($count >= 0) {
|
||||||
|
$status->likes_count = $count;
|
||||||
|
$status->save();
|
||||||
|
}
|
||||||
LikePipeline::dispatch($like);
|
LikePipeline::dispatch($like);
|
||||||
}
|
}
|
||||||
|
|
||||||
$likes = Like::whereProfileId($profile->id)
|
Cache::forget('status:'.$status->id.':likedby:userid:'.$user->id);
|
||||||
->orderBy('id', 'desc')
|
|
||||||
->take(1000)
|
|
||||||
->pluck('status_id');
|
|
||||||
|
|
||||||
if ($request->ajax()) {
|
if ($request->ajax()) {
|
||||||
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count];
|
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count];
|
||||||
|
|
|
@ -234,7 +234,8 @@ class StatusController extends Controller
|
||||||
'item' => 'required|integer|min:1',
|
'item' => 'required|integer|min:1',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$profile = Auth::user()->profile;
|
$user = Auth::user();
|
||||||
|
$profile = $user->profile;
|
||||||
$status = Status::withCount('shares')->findOrFail($request->input('item'));
|
$status = Status::withCount('shares')->findOrFail($request->input('item'));
|
||||||
|
|
||||||
$count = $status->shares_count;
|
$count = $status->shares_count;
|
||||||
|
@ -259,6 +260,13 @@ class StatusController extends Controller
|
||||||
$count++;
|
$count++;
|
||||||
SharePipeline::dispatch($share);
|
SharePipeline::dispatch($share);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($count >= 0) {
|
||||||
|
$status->reblogs_count = $count;
|
||||||
|
$status->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache::forget('status:'.$status->id.':sharedby:userid:'.$user->id);
|
||||||
|
|
||||||
if ($request->ajax()) {
|
if ($request->ajax()) {
|
||||||
$response = ['code' => 200, 'msg' => 'Share saved', 'count' => $count];
|
$response = ['code' => 200, 'msg' => 'Share saved', 'count' => $count];
|
||||||
|
|
|
@ -150,8 +150,12 @@ class Status extends Model
|
||||||
if(Auth::check() == false) {
|
if(Auth::check() == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$profile = Auth::user()->profile;
|
$user = Auth::user();
|
||||||
return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count();
|
$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()
|
public function likedBy()
|
||||||
|
@ -191,9 +195,12 @@ class Status extends Model
|
||||||
if(Auth::check() == false) {
|
if(Auth::check() == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$profile = Auth::user()->profile;
|
$user = Auth::user();
|
||||||
|
$id = $this->id;
|
||||||
return self::whereProfileId($profile->id)->whereReblogOfId($this->id)->count();
|
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()
|
public function sharedBy()
|
||||||
|
|
|
@ -27,8 +27,8 @@ class StatusTransformer extends Fractal\TransformerAbstract
|
||||||
'content' => $status->rendered ?? $status->caption,
|
'content' => $status->rendered ?? $status->caption,
|
||||||
'created_at' => $status->created_at->format('c'),
|
'created_at' => $status->created_at->format('c'),
|
||||||
'emojis' => [],
|
'emojis' => [],
|
||||||
'reblogs_count' => $status->shares()->count(),
|
'reblogs_count' => $status->reblogs_count != 0 ? $status->reblogs_count: $status->shares()->count(),
|
||||||
'favourites_count' => $status->likes()->count(),
|
'favourites_count' => $status->likes_count != 0 ? $status->likes_count: $status->likes()->count(),
|
||||||
'reblogged' => $status->shared(),
|
'reblogged' => $status->shared(),
|
||||||
'favourited' => $status->liked(),
|
'favourited' => $status->liked(),
|
||||||
'muted' => null,
|
'muted' => null,
|
||||||
|
@ -47,7 +47,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
|
||||||
'comments_disabled' => $status->comments_disabled ? true : false,
|
'comments_disabled' => $status->comments_disabled ? true : false,
|
||||||
'thread' => false,
|
'thread' => false,
|
||||||
'replies' => [],
|
'replies' => [],
|
||||||
'parent' => $status->parent() ? $this->transform($status->parent()) : [],
|
'parent' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
public/js/activity.js
vendored
BIN
public/js/activity.js
vendored
Binary file not shown.
Binary file not shown.
|
@ -225,6 +225,7 @@ export default {
|
||||||
break;
|
break;
|
||||||
case 'like':
|
case 'like':
|
||||||
case 'favourite':
|
case 'favourite':
|
||||||
|
case 'comment':
|
||||||
return n.status.url;
|
return n.status.url;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue