Merge pull request #4687 from pixelfed/staging

Update ApiV1Controller, hydrate reblog interactions. Fixes #4686
This commit is contained in:
daniel 2023-10-09 13:08:27 -06:00 committed by GitHub
commit d679ae4f11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2507,7 +2507,7 @@ class ApiV1Controller extends Controller
{
abort_if(!$request->user(), 403);
$user = $request->user();
$pid = $request->user()->profile_id;
$res = $request->has(self::PF_API_ENTITY_KEY) ? StatusService::get($id, false) : StatusService::getMastodon($id, false);
if(!$res || !isset($res['visibility'])) {
@ -2517,17 +2517,23 @@ class ApiV1Controller extends Controller
$scope = $res['visibility'];
if(!in_array($scope, ['public', 'unlisted'])) {
if($scope === 'private') {
if(intval($res['account']['id']) !== intval($user->profile_id)) {
abort_unless(FollowerService::follows($user->profile_id, $res['account']['id']), 403);
if(intval($res['account']['id']) !== intval($pid)) {
abort_unless(FollowerService::follows($pid, $res['account']['id']), 403);
}
} else {
abort(400, 'Invalid request');
}
}
$res['favourited'] = LikeService::liked($user->profile_id, $res['id']);
$res['reblogged'] = ReblogService::get($user->profile_id, $res['id']);
$res['bookmarked'] = BookmarkService::get($user->profile_id, $res['id']);
if(!empty($res['reblog']) && isset($res['reblog']['id'])) {
$res['reblog']['favourited'] = (bool) LikeService::liked($pid, $res['reblog']['id']);
$res['reblog']['reblogged'] = (bool) ReblogService::get($pid, $res['reblog']['id']);
$res['reblog']['bookmarked'] = BookmarkService::get($pid, $res['reblog']['id']);
}
$res['favourited'] = LikeService::liked($pid, $res['id']);
$res['reblogged'] = ReblogService::get($pid, $res['id']);
$res['bookmarked'] = BookmarkService::get($pid, $res['id']);
return $this->json($res);
}