Update StatusController, use transactions for status views

This commit is contained in:
Daniel Supernault 2021-05-31 23:54:20 -06:00
parent e3899d3684
commit 7cbd6bc36d
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -14,7 +14,7 @@ use App\StatusView;
use App\Transformer\ActivityPub\StatusTransformer;
use App\Transformer\ActivityPub\Verb\Note;
use App\User;
use Auth, Cache;
use Auth, DB, Cache;
use Illuminate\Http\Request;
use League\Fractal;
use App\Util\Media\Filter;
@ -75,12 +75,6 @@ class StatusController extends Controller
}
$template = $status->in_reply_to_id ? 'status.reply' : 'status.show';
// $template = $status->type === 'video' &&
// $request->has('video_beta') &&
// $request->video_beta == 1 &&
// $request->user() ?
// 'status.show_video' : 'status.show';
return view($template, compact('user', 'status'));
}
@ -403,27 +397,25 @@ class StatusController extends Controller
public function storeView(Request $request)
{
abort_if(!$request->user(), 403);
$this->validate($request, [
'_v' => 'required|array'
]);
$views = $request->input('_v');
$uid = $request->user()->profile_id;
if(empty($views)) {
return;
if(empty($views) || !is_array($views)) {
return response()->json(0);
}
foreach($views as $view) {
if(!isset($view['sid']) || !isset($view['pid'])) {
continue;
}
StatusView::firstOrCreate([
'status_id' => $view['sid'],
'status_profile_id' => $view['pid'],
'profile_id' => $uid
]);
DB::transaction(function () use($view, $uid) {
StatusView::firstOrCreate([
'status_id' => $view['sid'],
'status_profile_id' => $view['pid'],
'profile_id' => $uid
]);
});
}
return response()->json(1);