feat: add persistent mobile notifications
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\UpdateNotificationPreferencesRequest;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NotificationPreferenceController extends Controller
|
||||
{
|
||||
public function show(Request $request): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'data' => $this->preferences($request),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateNotificationPreferencesRequest $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$validated = $request->validated();
|
||||
|
||||
$user->forceFill([
|
||||
'social_notifications_enabled' => $validated['socialNotificationsEnabled']
|
||||
?? $user->social_notifications_enabled,
|
||||
'engagement_reminders_enabled' => $validated['engagementRemindersEnabled']
|
||||
?? $user->engagement_reminders_enabled,
|
||||
])->save();
|
||||
|
||||
return response()->json([
|
||||
'data' => $this->preferences($request),
|
||||
'message' => __('api.notifications.preferences_updated'),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array{socialNotificationsEnabled: bool, engagementRemindersEnabled: bool} */
|
||||
private function preferences(Request $request): array
|
||||
{
|
||||
return [
|
||||
'socialNotificationsEnabled' => (bool) $request->user()->social_notifications_enabled,
|
||||
'engagementRemindersEnabled' => (bool) $request->user()->engagement_reminders_enabled,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user