feat: Firebase Cloud Messaging push notifications

Backend:
- New user_fcm_tokens table (migration 010) for storing device tokens
- FCMService sends push via Firebase HTTP legacy API (server key from .env)
- POST /api/fcm/register endpoint for Android to register its FCM token
- AdminController::sendNotification() triggers FCM push after DB insert
- FCM config added to config.php

Android:
- Firebase Cloud Messaging service (ServerManagerFirebaseService)
  receives push notifications and shows them via NotificationHelper
- FCM token registered with backend on new token and on login
- google-services.json template (must be replaced with real Firebase config)
- firebase-setup.sh script with configuration instructions
- FCM dependency + google-services plugin added to Gradle
- Bump to v1.8.0 (versionCode 12)
This commit is contained in:
2026-06-13 12:37:40 -04:00
parent bdc4d73d89
commit 136eebc4c3
17 changed files with 383 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ use ServerManager\Core\Validator;
use ServerManager\Models\Notification;
use ServerManager\Models\User;
use ServerManager\Services\AuditService;
use ServerManager\Services\FCMService;
class AdminController
{
@@ -280,13 +281,20 @@ class AdminController
}
$notificationModel = new Notification();
$notificationModel->create([
$noteId = $notificationModel->create([
'user_id' => $userId,
'title' => $title,
'message' => $message,
'type' => $type,
]);
$fcm = new FCMService();
if ($userId) {
$fcm->sendToUser($userId, $title, $message, $type, $noteId);
} else {
$fcm->sendToAll($title, $message, $type, $noteId);
}
$this->auditService->log('notification_sent', 'notification', null, ['title' => $title, 'target' => $userId ? "user #{$userId}" : 'all users']);
$this->view->json(['success' => true, 'message' => 'Notification sent successfully.']);