Athena — roomy-mobile/archive/changes/2026-01-05-implement-notifications/tasks/002-implement-fcm-token-service.md


skill-level: medior status: done

Task: Implement FCM Token Service

End Goal

A Flutter service that manages FCM token registration, refresh, and storage in Firestore, enabling push notifications to reach user devices.

Currently

  • No FCM token management exists
  • No Firestore collection for device tokens
  • No service to handle token lifecycle

Should

  • FcmTokenService handles token registration and refresh
  • FCM tokens are stored in users/{userId}/fcmTokens/{tokenId} subcollection
  • Token refresh events trigger Firestore updates
  • Multi-device support via separate token documents
  • Firestore security rules protect token documents

Constraints

  • [ ] Follow existing service patterns (LazySingleton, emoji markers)
  • [ ] Use existing FirestoreCollection enum pattern
  • [ ] Handle token refresh without blocking app startup
  • [ ] Support both iOS and Android platforms

Acceptance Criteria

  • [ ] FcmTokenService is registered in LocatorService
  • [ ] Token is registered on app launch after permission grant
  • [ ] Token refresh events update Firestore
  • [ ] Multiple devices per user are supported
  • [ ] Firestore security rules allow user to read/write own tokens

Implementation Checklist

  • [x] 2.1 Create lib/notifications/ feature directory structure
  • [x] 2.2 Create FcmTokenDto with token, platform, createdAt, lastActiveAt fields
  • [x] 2.3 Add fcmTokens to FirestoreCollection enum
  • [x] 2.4 Create FcmTokensApi extending RmyApi
  • [x] 2.5 Create FcmTokenService as LazySingleton
  • [x] 2.6 Implement token registration in FcmTokenService
  • [x] 2.7 Implement token refresh listener
  • [x] 2.8 Add Firestore security rules for fcmTokens subcollection
  • [x] 2.9 Register service in LocatorService
  • [x] 2.10 Call token registration after notification permission grant

Notes

  • Token registration should be idempotent (same device, same token = no-op)
  • Platform detection: Platform.isIOS vs Platform.isAndroid
  • Token document ID can be a hash of the token for deduplication

Reacties

Nog geen reacties