Updated Map View
This commit is contained in:
@@ -9,38 +9,77 @@ use App\Settings\SettingsRegistry;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function follow(User $user): JsonResponse
|
||||
{
|
||||
abort_if($user->id === auth()->id(), 403);
|
||||
|
||||
$existing = Followee::where('user_id', auth()->id())
|
||||
->where('followee_id', $user->id)
|
||||
->first();
|
||||
|
||||
if ($existing) {
|
||||
$existing->delete();
|
||||
return response()->json(['following' => false]);
|
||||
return response()->json(['status' => 'none']);
|
||||
}
|
||||
|
||||
$canView = Gate::allows('viewProfileData', $user);
|
||||
|
||||
Followee::create([
|
||||
'user_id' => auth()->id(),
|
||||
'followee_id' => $user->id,
|
||||
'verified' => $canView,
|
||||
]);
|
||||
|
||||
Notification::create([
|
||||
'user_id' => $user->id,
|
||||
'title' => 'New follower',
|
||||
'body' => auth()->user()->name . ' is now following you.',
|
||||
'user_id' => $user->id,
|
||||
'title' => $canView ? 'New follower' : 'Follow request',
|
||||
'body' => $canView
|
||||
? auth()->user()->name . ' is now following you.'
|
||||
: auth()->user()->name . ' wants to follow you.',
|
||||
'is_achievement' => false,
|
||||
'url' => '/u/'. auth()->user()->name,
|
||||
'url' => $canView ? '/u/' . auth()->user()->name : '/follow-requests',
|
||||
]);
|
||||
|
||||
return response()->json(['following' => true]);
|
||||
return response()->json(['status' => $canView ? 'following' : 'requested']);
|
||||
}
|
||||
|
||||
public function settings(){
|
||||
public function approveRequest(User $follower): JsonResponse
|
||||
{
|
||||
$followee = Followee::where('user_id', $follower->id)
|
||||
->where('followee_id', auth()->id())
|
||||
->pending()
|
||||
->firstOrFail();
|
||||
|
||||
$followee->update(['verified' => true]);
|
||||
|
||||
Notification::create([
|
||||
'user_id' => $follower->id,
|
||||
'title' => 'Follow request accepted',
|
||||
'body' => auth()->user()->name . ' accepted your follow request.',
|
||||
'is_achievement' => false,
|
||||
'url' => '/u/' . auth()->user()->name,
|
||||
]);
|
||||
|
||||
return response()->json(['approved' => true]);
|
||||
}
|
||||
|
||||
public function denyRequest(User $follower): JsonResponse
|
||||
{
|
||||
Followee::where('user_id', $follower->id)
|
||||
->where('followee_id', auth()->id())
|
||||
->pending()
|
||||
->delete();
|
||||
|
||||
return response()->json(['denied' => true]);
|
||||
}
|
||||
|
||||
public function settings(?string $category = null){
|
||||
$allowedTabs = ['general', 'followers'];
|
||||
$user = auth()->user();
|
||||
$current = array_merge(SettingsRegistry::defaults(), $user->settings ?? []);
|
||||
$fields = array_map(fn($field) => array_merge($field, [
|
||||
@@ -50,6 +89,7 @@ class UserController extends Controller
|
||||
return Inertia::render('UserSettings', [
|
||||
'fields' => $fields,
|
||||
'categories' => SettingsRegistry::categories(),
|
||||
'defaultTab' => in_array($category, $allowedTabs, true) ? $category : 'general',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user