feat: Firebase FCM push notification channel#78
Merged
Conversation
Adds push as a first-class notification channel alongside email and in-app,
following the existing INotificationChannelHandler plug-in model.
- UserDeviceToken entity: one row per (UserId, DeviceId); token rotates,
deviceId is stable. EF migration: AddUserDeviceToken
- POST /api/me/device-tokens — register/refresh FCM token (upsert by deviceId)
- DELETE /api/me/device-tokens/{deviceId} — unregister
- PushNotificationChannelSender: fetches active tokens, sends FCM multicast,
deactivates stale tokens on UNREGISTERED/INVALID_ARGUMENT errors
- FirebaseMessagingService wraps FirebaseAdmin SDK with singleton guard
(DefaultInstance ?? Create) and forwards CancellationToken
- Firebase section in appsettings; channel skipped cleanly when unconfigured
- MetaData added to RenderedNotification so handlers can pass deep-link
context (postId, communityId, etc.) into FCM data payload
- NotificationChannel.Push added to all existing notification handlers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Firebase FCM as a fourth notification channel (
Push = 3) using the existingINotificationChannelHandlerplug-in model — no changes toNotificationGatewaydispatch logic, the channel just registers itself.Device token management
UserDeviceTokenentity: one row per(UserId, DeviceId).DeviceIdis a stable client-generated UUID;Tokenis the rotating FCM registration token. Upsert onDeviceIdmeans re-installing the app refreshes the token without creating duplicates.POST /api/me/device-tokens— register or refresh (requires auth, all non-anonymous roles)DELETE /api/me/device-tokens/{deviceId}— unregisterAddUserDeviceToken(unique index on(user_id, device_id), index on(user_id, is_active), index ontoken)Push delivery
PushNotificationChannelSenderfetches all active tokens for the recipient, sends a single FCM multicast, then bulk-deactivates any tokens FCM rejects asUNREGISTERED,INVALID_ARGUMENT, orSENDER_ID_MISMATCH— keeps the token table clean without a separate job.FirebaseMessagingServicewraps theFirebaseAdminSDK v3.1.0 with a singleton guard (DefaultInstance ?? Create) safe for hot-reload.CancellationTokenis forwarded toSendEachForMulticastAsync.Firebase:ProjectIdorFirebase:ServiceAccountJsonare empty, neitherIFirebaseMessagingServicenorPushNotificationChannelSenderare registered — both APIs start cleanly without credentials.MetaDataadded toRenderedNotificationso notification handlers can forward context (postId, communityId, locale, templateCode) into the FCM data payload for client-side deep-linking.NotificationChannel.Pushadded to all existing notification handlers (ExpertRegistrationApproved/Rejected, NewsPublished, ResourcePublished, CountryContentRequest Approved/Rejected).Admin test endpoint
POST /api/admin/notifications/test-push(Internal API,Notification_Sendpermission) — fires a raw FCM multicast to a single token, returns{ sent, failed }. Verified live: real device received the push (sent: 1, failed: 0).Test plan
POST /api/me/device-tokenswith a real FCM token → row appears inuser_device_tokenwithis_active = 1deviceId, newtoken→ row updated (no duplicate),tokenrefreshedDELETE /api/me/device-tokens/{deviceId}→is_active = 0POST /api/admin/notifications/test-pushwith a valid FCM token →sent: 1, failed: 0, push received on devicesent: 0, failed: 1, token row deactivated on next real dispatchFirebasesection from appsettings → both APIs start without error, push channel silently skipped on dispatchPushin its channels (e.g. publish a news article) → FCM multicast fires alongside email/in-app,notification_logrow created for Push channel─────────────────────────────────────────────────────