mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-25 06:23:18 +00:00
Update ApiV1Controller, fix context entities
This commit is contained in:
parent
a0e15d89e2
commit
b1ab41e0c4
1 changed files with 36 additions and 27 deletions
|
@ -1896,40 +1896,49 @@ class ApiV1Controller extends Controller
|
||||||
abort_if(!$request->user(), 403);
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
$status = StatusService::getMastodon($id, false);
|
||||||
|
|
||||||
$status = Status::findOrFail($id);
|
if(!$status || !isset($status['account'])) {
|
||||||
|
return response('', 404);
|
||||||
|
}
|
||||||
|
|
||||||
if($status->profile_id !== $user->profile_id) {
|
if($status['account']['id'] != $user->profile_id) {
|
||||||
if($status->scope == 'private') {
|
if($status['visibility'] == 'private') {
|
||||||
abort_if(!FollowerService::follows($user->profile_id, $status->profile_id), 403);
|
if(!FollowerService::follows($user->profile_id, $status['account']['id'])) {
|
||||||
|
return response('', 404);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
abort_if(!in_array($status->scope, ['public','unlisted']), 403);
|
if(!in_array($status['visibility'], ['public','unlisted'])) {
|
||||||
|
return response('', 404);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($status->comments_disabled) {
|
|
||||||
$res = [
|
|
||||||
'ancestors' => [],
|
|
||||||
'descendants' => []
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$ancestors = $status->parent();
|
|
||||||
if($ancestors) {
|
|
||||||
$ares = new Fractal\Resource\Item($ancestors, new StatusTransformer());
|
|
||||||
$ancestors = [
|
|
||||||
$this->fractal->createData($ares)->toArray()
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$ancestors = [];
|
$ancestors = [];
|
||||||
|
$descendants = [];
|
||||||
|
|
||||||
|
if($status['in_reply_to_id']) {
|
||||||
|
$ancestors[] = StatusService::getMastodon($status['in_reply_to_id'], false);
|
||||||
}
|
}
|
||||||
$descendants = Status::whereInReplyToId($id)->latest()->limit(20)->get();
|
|
||||||
$dres = new Fractal\Resource\Collection($descendants, new StatusTransformer());
|
if($status['replies_count']) {
|
||||||
$descendants = $this->fractal->createData($dres)->toArray();
|
$descendants = DB::table('statuses')
|
||||||
|
->where('in_reply_to_id', $id)
|
||||||
|
->limit(20)
|
||||||
|
->pluck('id')
|
||||||
|
->map(function($sid) {
|
||||||
|
return StatusService::getMastodon($sid, false);
|
||||||
|
})
|
||||||
|
->filter(function($post) {
|
||||||
|
return $post && isset($post['account']);
|
||||||
|
})
|
||||||
|
->values();
|
||||||
|
}
|
||||||
|
|
||||||
$res = [
|
$res = [
|
||||||
'ancestors' => $ancestors,
|
'ancestors' => $ancestors,
|
||||||
'descendants' => $descendants
|
'descendants' => $descendants
|
||||||
];
|
];
|
||||||
}
|
|
||||||
|
|
||||||
return $this->json($res);
|
return $this->json($res);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue