middleware('auth'); } public function showForm(Request $request): View { $this->validate($request, [ 'type' => 'required|alpha_dash|in:comment,group,post,user', 'id' => 'required|integer|min:1', ]); $type = $request->input('type'); $id = $request->input('id'); $pid = $request->user()->profile_id; switch ($request->input('type')) { case 'post': case 'comment': Status::findOrFail($id); break; case 'user': Profile::findOrFail($id); break; case 'group': Group::where('profile_id', '!=', $pid)->findOrFail($id); break; default: // code... break; } return view('report.form'); } public function notInterestedForm(Request $request): View { return view('report.not-interested'); } public function spamForm(Request $request): View { return view('report.spam'); } public function spamCommentForm(Request $request): View { return view('report.spam.comment'); } public function spamPostForm(Request $request): View { return view('report.spam.post'); } public function spamProfileForm(Request $request): View { return view('report.spam.profile'); } public function sensitiveCommentForm(Request $request): View { return view('report.sensitive.comment'); } public function sensitivePostForm(Request $request): View { return view('report.sensitive.post'); } public function sensitiveProfileForm(Request $request): View { return view('report.sensitive.profile'); } public function abusiveCommentForm(Request $request): View { return view('report.abusive.comment'); } public function abusivePostForm(Request $request): View { return view('report.abusive.post'); } public function abusiveProfileForm(Request $request): View { return view('report.abusive.profile'); } public function formStore(Request $request): JsonResponse|RedirectResponse { $this->validate($request, [ 'report' => 'required|alpha_dash', 'type' => 'required|alpha_dash', 'id' => 'required|integer|min:1', 'msg' => 'nullable|string|max:150', ]); $profile = $request->user()->profile; $reportType = $request->input('report'); $object_id = $request->input('id'); $object_type = $request->input('type'); $msg = $request->input('msg'); $object = null; $types = [ // original 3 'spam', 'sensitive', 'abusive', // new 'underage', 'copyright', 'impersonation', 'scam', 'terrorism', ]; if (! in_array($reportType, $types)) { if ($request->wantsJson()) { return abort(400, 'Invalid report type'); } return redirect('/timeline')->with('error', 'Invalid report type'); } $rpid = null; switch ($object_type) { case 'post': case 'comment': $object = Status::find($object_id); // Direct messages are reported from the thread view as a // post. They are no longer statuses, so look there next. if (! $object) { $object = DmMessage::findOrFail($object_id); $isParticipant = DmConversationParticipant::where('conversation_id', $object->conversation_id) ->where('profile_id', $profile->id) ->exists(); abort_if(! $isParticipant, 404); $object_type = DmMessage::class; } else { $object_type = Status::class; } $exists = Report::whereUserId(Auth::id()) ->whereObjectId($object->id) ->whereObjectType($object_type) ->count(); $rpid = $object->profile_id; break; case 'user': $object = Profile::findOrFail($object_id); $object_type = Profile::class; $exists = Report::whereUserId(Auth::id()) ->whereObjectId($object->id) ->whereObjectType(Profile::class) ->count(); $rpid = $object->id; break; case 'group': $object = Group::findOrFail($object_id); $object_type = Group::class; $exists = Report::whereUserId(Auth::id()) ->whereObjectId($object->id) ->whereObjectType(Group::class) ->count(); $rpid = $object->profile_id; break; default: if ($request->wantsJson()) { return abort(400, 'Invalid report type'); } return redirect('/timeline')->with('error', 'Invalid report type'); } if ($exists !== 0) { if ($request->wantsJson()) { return response()->json(200); } return redirect('/timeline')->with('error', 'You have already reported this!'); } if ($object->profile_id == $profile->id) { if ($request->wantsJson()) { return response()->json(200); } return redirect('/timeline')->with('error', 'You cannot report your own content!'); } $report = new Report; $report->profile_id = $profile->id; $report->user_id = Auth::id(); $report->object_id = $object->id; $report->object_type = $object_type; $report->reported_profile_id = $rpid; $report->type = $request->input('report'); $report->message = e($request->input('msg')); $report->save(); if (config('instance.reports.email.enabled')) { ReportNotifyAdminViaEmail::dispatch($report)->onQueue('default'); } if ($request->wantsJson()) { return response()->json(200); } return redirect('/timeline')->with('status', 'Report successfully sent!'); } }