1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-25 01:05:36 +00:00

Update ApiV1Controller, improve favourites endpoint

This commit is contained in:
Daniel Supernault 2022-02-13 00:23:29 -07:00
parent 0a8b9f61f5
commit 151dc17c25
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -1026,33 +1026,38 @@ class ApiV1Controller extends Controller
$user = $request->user();
$status = Status::findOrFail($id);
$status = StatusService::getMastodon($id, false);
if($status->profile_id !== $user->profile_id) {
if($status->scope == 'private') {
abort_if(!$status->profile->followedBy($user->profile), 403);
abort_unless($status, 400);
$spid = $status['account']['id'];
if($spid !== $user->profile_id) {
if($status['visibility'] == 'private') {
abort_if(!FollowerService::follows($user->profile_id, $spid), 403);
} else {
abort_if(!in_array($status->scope, ['public','unlisted']), 403);
abort_if(!in_array($status['visibility'], ['public','unlisted']), 403);
}
}
$like = Like::firstOrCreate([
'profile_id' => $user->profile_id,
'status_id' => $status->id
'status_id' => $status['id']
]);
if($like->wasRecentlyCreated == true) {
$like->status_profile_id = $status->profile_id;
$like->is_comment = !empty($status->in_reply_to_id);
$like->status_profile_id = $spid;
$like->is_comment = !empty($status['in_reply_to_id']);
$like->save();
$status->likes_count = $status->likes()->count();
$status->save();
Status::findOrFail($status['id'])->update([
'favourites_count' => ($status['favourites_count'] ?? 0) + 1
]);
LikePipeline::dispatch($like);
}
$res = StatusService::getMastodon($status->id, false);
$res['favourited'] = true;
return response()->json($res);
$status['favourited'] = true;
$status['favourites_count'] = $status['favourites_count'] + 1;
return response()->json($status);
}
/**