skill-level: medior
status: done
Task: Implement Permission Sync in NotificationPreferencesService
End Goal
NotificationPreferencesService synchronizes Firestore globalEnabled with OS permission status on app startup when user has previously made a permission decision.
Currently
- Service streams preferences from Firestore
- No interaction with OS permission status
- Preferences and OS state can diverge
Should
- On initialise, if
osPermissionGranted != null:
- Check actual OS permission status
- If OS status differs from
globalEnabled, update Firestore
- When permission is granted/denied via consent flow:
- Update
osPermissionGranted to true/false
- Update
globalEnabled to match
Constraints
- [ ] Only sync when
osPermissionGranted is not null
- [ ] Use
NotificationPermissionService to check OS status
- [ ] Do not sync on first launch (undetermined state)
- [ ] Update should be silent (no toast)
Acceptance Criteria
- [ ] App startup syncs Firestore with OS when applicable
- [ ] User who revoked permission in Settings has
globalEnabled set to false
- [ ] User who granted permission in Settings has
globalEnabled set to true
- [ ] First-time users (null) are not affected
Implementation Checklist
- [x] 3.1 Add
NotificationPermissionService dependency to NotificationPreferencesService
- [x] 3.2 Add
syncPermissionState() method
- [x] 3.3 In
syncPermissionState: check if osPermissionGranted != null
- [x] 3.4 Get actual OS permission status via
NotificationPermissionService
- [x] 3.5 Compare OS status with
globalEnabled
- [x] 3.6 Update Firestore if they differ
- [x] 3.7 Call
syncPermissionState() after stream initializes in service
- [x] 3.8 Add
updateOsPermissionGranted(bool granted) method for consent flow
- [x] 3.9 Run
flutter analyze to verify no issues
Notes
- This ensures Firestore reflects reality when user changes permission in system Settings
- The sync only runs for users who have previously interacted with the permission dialog
Reacties