ASA Go: Send FCM push notifications when fire behaviour advisories are issued#5246
ASA Go: Send FCM push notifications when fire behaviour advisories are issued#5246
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5246 +/- ##
============================================
+ Coverage 67.66% 68.10% +0.43%
- Complexity 0 26 +26
============================================
Files 357 451 +94
Lines 15531 17817 +2286
Branches 1728 2108 +380
============================================
+ Hits 10509 12134 +1625
- Misses 4493 5068 +575
- Partials 529 615 +86
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mobile/asa-go/src/components/settings/SubscriptionAccordion.tsx
Outdated
Show resolved
Hide resolved
| } | ||
| }; | ||
|
|
||
| export const getUpdatedSubscriptions = ( |
There was a problem hiding this comment.
getUpdatedSubscriptions is no longer used in this slice, it's only called in the useNotificationSettings hook. Perhaps move it into the hook or a utility module?
There was a problem hiding this comment.
Hmm no it's still used here, and useNotificationSettings is no longer.
There was a problem hiding this comment.
What do you mean by useNotificationSettings is no longer?
There was a problem hiding this comment.
I was on the wrong branch.
| const { networkStatus } = useSelector(selectNetworkStatus); | ||
| const isActive = useAppIsActive(); | ||
|
|
||
| const initPushNotifications = useCallback(async () => { |
There was a problem hiding this comment.
Should initPushNotifications set a registrationError as well? Currently it only logs errors
There was a problem hiding this comment.
I'm not sure, if it's for permission denied retrying won't help and registrationError would be misleading.
If it's from getToken failing as a transient failure, it's related to registration, but also tied specifically to FCM, I guess we could retry in that case...
There was a problem hiding this comment.
I came here to ask the same question.
retryRegistration() has a guard if (!registrationError) return; so if the initial attempt at registration fails retryRegistration will always return due to the guard.
There was a problem hiding this comment.
I think this is a pretty unlikely situation though.
There was a problem hiding this comment.
Ok if getToken fails, it will set registrationError so it will be retried: 9b8ef97
| ), | ||
| ); | ||
| dispatch(setRegistrationError(false)); | ||
| dispatch(resetRegistrationAttempts()); |
There was a problem hiding this comment.
I think this only resets on a successful registration, so I don't think that will ever let us retry in the same session. Maybe we can we add a test that does something like "initial registration failed, then opening Settings/drawer retries registration"
There was a problem hiding this comment.
Ok since retryRegistration is a deliberate call used in Settings/drawer, I made it reset attempts here: b401ed8
dgboss
left a comment
There was a problem hiding this comment.
Thanks for tackling this beast!
brettedw
left a comment
There was a problem hiding this comment.
Thanks for taking this big one on! You probably already have it in mind but I think just the timing of the notifications needs adjusting before merging
|



Adds backend logic to send FCM push notifications to subscribed devices when forecast
advisories for today are processed.
firebase-admindependency to nats consumer for sending notificationsFCM_CREDSenv var (JSON service accountcredentials)
trigger_notificationslooks up zones with active advisories, fetches subscribed devicetokens, and sends multicast FCM messages
UnregisteredErrorare considered marked as inactivein the DB, successful tokens are left as active
SFMS Notes
todayis today in Vancouver time, as that's what legacy SFMS runs inFCM registration (mobile client)
Registration is managed entirely within
usePushNotifications— the hook owns initialization,token refresh handling, the registration-on-connect effect, and retry.
Apponly callsinitPushNotificationswhen authenticated;SettingsandFireShapeActionsDrawercallretryRegistrationdirectly from the hook. Firebase token refresh events flow through thehook's
tokenReceivedlistener into re-registration withoutAppneeding to coordinate betweenthe hook and Redux.
Invariants for subscription updates (see diagram for visual)
A subscription update can only proceed if all of the following hold:
useDeviceId()returns non-nullnetworkStatus.connectedis trueregisteredFcmTokenis non-nullsubscriptionsInitializedis true (initial fetch complete)These are composed into
selectNotificationSettingsDisabled, which disables the subscribebutton in both components. The guard in
updateSubscriptionsmirrors the selector as alast-resort defence, but the button should be unreachable before all four hold.
subscriptionsInitializedas an invariant eliminates a race condition: without it, a user couldtoggle a subscription while the initial fetch was still in-flight and have it overwritten by
the server response.
Setup error states (before updates are possible)
The notification setup flows through these states, derived in
selectNotificationSetupState:permissionDeniedunregistered+ connected + no device errorregistrationFaileddeviceIdErrorDevice.getId()failedreadyUpdate error states (once updates are possible)
Within the
readystate, updates go through:subscriptionsInitializedis falsetoggleSubscriptionin flightOn failure: the optimistic store update is rolled back to the previous subscription list.
The snackbar (
updateError) is shown in both the map drawer and the settings accordion. In thesettings accordion only, the specific
LoadingSwitchthat failed also shows an inline error —the map drawer has a single subscribe button so no per-item error is needed there.
Testing
tif_pusherenv to point to dev bucket andhttps://wps-pr-5246-e1e498-dev.apps.silver.devops.gov.bc.ca/apisfms/uploads/forecast/AND thatthey're named with today's date AND that their
created_atmetadata info is set to today'sdate.
tif_pusherCloses #5165
Test Links:
Landing Page
MoreCast
Percentile
Calculator
C-Haines
FireCalc
FireCalc bookmark
Auto Spatial Advisory
(ASA)
HFI Calculator
SFMS Insights
Fire Watch