mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update ApiV1Controller, improve favourites endpoint
This commit is contained in:
parent
0a8b9f61f5
commit
151dc17c25
1 changed files with 18 additions and 13 deletions
|
@ -1026,33 +1026,38 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
$status = Status::findOrFail($id);
|
$status = StatusService::getMastodon($id, false);
|
||||||
|
|
||||||
if($status->profile_id !== $user->profile_id) {
|
abort_unless($status, 400);
|
||||||
if($status->scope == 'private') {
|
|
||||||
abort_if(!$status->profile->followedBy($user->profile), 403);
|
$spid = $status['account']['id'];
|
||||||
|
|
||||||
|
if($spid !== $user->profile_id) {
|
||||||
|
if($status['visibility'] == 'private') {
|
||||||
|
abort_if(!FollowerService::follows($user->profile_id, $spid), 403);
|
||||||
} else {
|
} else {
|
||||||
abort_if(!in_array($status->scope, ['public','unlisted']), 403);
|
abort_if(!in_array($status['visibility'], ['public','unlisted']), 403);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$like = Like::firstOrCreate([
|
$like = Like::firstOrCreate([
|
||||||
'profile_id' => $user->profile_id,
|
'profile_id' => $user->profile_id,
|
||||||
'status_id' => $status->id
|
'status_id' => $status['id']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if($like->wasRecentlyCreated == true) {
|
if($like->wasRecentlyCreated == true) {
|
||||||
$like->status_profile_id = $status->profile_id;
|
$like->status_profile_id = $spid;
|
||||||
$like->is_comment = !empty($status->in_reply_to_id);
|
$like->is_comment = !empty($status['in_reply_to_id']);
|
||||||
$like->save();
|
$like->save();
|
||||||
$status->likes_count = $status->likes()->count();
|
Status::findOrFail($status['id'])->update([
|
||||||
$status->save();
|
'favourites_count' => ($status['favourites_count'] ?? 0) + 1
|
||||||
|
]);
|
||||||
LikePipeline::dispatch($like);
|
LikePipeline::dispatch($like);
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = StatusService::getMastodon($status->id, false);
|
$status['favourited'] = true;
|
||||||
$res['favourited'] = true;
|
$status['favourites_count'] = $status['favourites_count'] + 1;
|
||||||
return response()->json($res);
|
return response()->json($status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue