feat: Firebase Cloud Messaging push notifications #66

Merged
rafaga21 merged 7 commits from feat/fcm-notifications into master 2026-06-13 14:05:44 -04:00
Collaborator

Firebase Cloud Messaging — Push Notificaciones

Integración completa de FCM para notificaciones push al dispositivo Android.

Cambios incluidos

  • FCMService: Servicio PHP para enviar notificaciones push vía HTTP v1 (OAuth2 con service account) y legacy API.
  • ServerManagerFirebaseService: Receptor de FCM en Android que procesa onNewToken y onMessageReceived.
  • LoginViewModel: Registra el token FCM al iniciar sesión y al abrir la app con sesión activa. Manejo de errores con logs.
  • ApiController: Endpoint POST /api/fcm/register para almacenar tokens.
  • AdminController: Envía push al crear notificaciones desde el panel.
  • Config: config/firebase-service-account.json o FCM_SERVER_KEY.
  • Migración: 010_user_fcm_tokens.sql.
  • APK: Compilado v1.8.1 (versionCode 13).
### Firebase Cloud Messaging — Push Notificaciones Integración completa de FCM para notificaciones push al dispositivo Android. #### Cambios incluidos - **FCMService**: Servicio PHP para enviar notificaciones push vía HTTP v1 (OAuth2 con service account) y legacy API. - **ServerManagerFirebaseService**: Receptor de FCM en Android que procesa `onNewToken` y `onMessageReceived`. - **LoginViewModel**: Registra el token FCM al iniciar sesión y al abrir la app con sesión activa. Manejo de errores con logs. - **ApiController**: Endpoint `POST /api/fcm/register` para almacenar tokens. - **AdminController**: Envía push al crear notificaciones desde el panel. - **Config**: `config/firebase-service-account.json` o `FCM_SERVER_KEY`. - **Migración**: `010_user_fcm_tokens.sql`. - **APK**: Compilado v1.8.1 (versionCode 13).
agent added 6 commits 2026-06-13 14:04:32 -04:00
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)
- google-services.json now has real Firebase project values
- Added firebase-messaging-ktx dependency (was missing)
- Updated google-services plugin to 4.4.4
- FCMService now supports both HTTP v1 API (service account) and legacy API (server key)
- v1 API uses OAuth2 JWT auth with Firebase service account; tries this first
- Falls back to legacy HTTP API if only server key is configured
- Removes invalid tokens from DB automatically (NotRegistered, INVALID_ARGUMENT, etc.)
- AdminController now logs push result status and shows in UI response
- .env updated with FCM_SERVER_KEY placeholder and docs
- Migration 010 run in dev
- LoginViewModel now calls Tasks.await(FirebaseMessaging.getInstance().token)
  to actively fetch the FCM token if not yet saved in prefs
- Previous code relied solely on onNewToken callback, which may not fire
  before the user logs in on a fresh install
rafaga21 added 1 commit 2026-06-13 14:05:15 -04:00
rafaga21 merged commit 63e55ecf7e into master 2026-06-13 14:05:44 -04:00
rafaga21 deleted branch feat/fcm-notifications 2026-06-13 14:05:46 -04:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: devlab/server-manager#66