mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 22:41:27 +00:00
Update StatusController, cache AP object
This commit is contained in:
parent
21d97f6f10
commit
a75b89b239
1 changed files with 25 additions and 19 deletions
|
@ -35,8 +35,22 @@ class StatusController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
$status = StatusService::get($id, false);
|
||||||
|
|
||||||
|
abort_if(
|
||||||
|
!$status ||
|
||||||
|
!isset($status['account'], $status['account']['username']) ||
|
||||||
|
$status['account']['username'] != $username ||
|
||||||
|
isset($status['reblog'])
|
||||||
|
, 404);
|
||||||
|
|
||||||
|
abort_if($status['visibility'] != 'public' && !$request->user(), 403, 'Invalid permission');
|
||||||
|
|
||||||
|
if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
|
||||||
|
return $this->showActivityPub($request, $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||||
if ($user->status != null) {
|
if ($user->status != null) {
|
||||||
return ProfileController::accountCheck($user);
|
return ProfileController::accountCheck($user);
|
||||||
}
|
}
|
||||||
|
@ -71,18 +85,6 @@ class StatusController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->user() && $request->user()->profile_id != $status->profile_id) {
|
|
||||||
StatusView::firstOrCreate([
|
|
||||||
'status_id' => $status->id,
|
|
||||||
'status_profile_id' => $status->profile_id,
|
|
||||||
'profile_id' => $request->user()->profile_id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
|
|
||||||
return $this->showActivityPub($request, $status);
|
|
||||||
}
|
|
||||||
|
|
||||||
$template = $status->in_reply_to_id ? 'status.reply' : 'status.show';
|
$template = $status->in_reply_to_id ? 'status.reply' : 'status.show';
|
||||||
|
|
||||||
return view($template, compact('user', 'status'));
|
return view($template, compact('user', 'status'));
|
||||||
|
@ -170,7 +172,7 @@ class StatusController extends Controller
|
||||||
intval($status['account']['id']) !== intval($profile['id']) ||
|
intval($status['account']['id']) !== intval($profile['id']) ||
|
||||||
$status['sensitive'] ||
|
$status['sensitive'] ||
|
||||||
$status['visibility'] !== 'public' ||
|
$status['visibility'] !== 'public' ||
|
||||||
$status['pf_type'] !== 'photo'
|
!in_array($status['pf_type'], ['photo', 'photo:album'])
|
||||||
) {
|
) {
|
||||||
$content = view('status.embed-removed');
|
$content = view('status.embed-removed');
|
||||||
|
|
||||||
|
@ -347,12 +349,16 @@ class StatusController extends Controller
|
||||||
|
|
||||||
public function showActivityPub(Request $request, $status)
|
public function showActivityPub(Request $request, $status)
|
||||||
{
|
{
|
||||||
$object = $status->type == 'poll' ? new Question() : new Note();
|
$key = 'pf:status:ap:v1:sid:' . $status['id'];
|
||||||
$fractal = new Fractal\Manager();
|
return Cache::remember($key, 3600, function() use($status) {
|
||||||
$resource = new Fractal\Resource\Item($status, $object);
|
$status = Status::findOrFail($status['id']);
|
||||||
$res = $fractal->createData($resource)->toArray();
|
$object = $status->type == 'poll' ? new Question() : new Note();
|
||||||
|
$fractal = new Fractal\Manager();
|
||||||
|
$resource = new Fractal\Resource\Item($status, $object);
|
||||||
|
$res = $fractal->createData($resource)->toArray();
|
||||||
|
|
||||||
return response()->json($res['data'], 200, ['Content-Type' => 'application/activity+json'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
return response()->json($res['data'], 200, ['Content-Type' => 'application/activity+json'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(Request $request, $username, $id)
|
public function edit(Request $request, $username, $id)
|
||||||
|
|
Loading…
Reference in a new issue