Athena — roomy-mobile/archive/changes/2026-01-05-implement-notifications/tasks/004-implement-notification-service.md


skill-level: medior status: done

Task: Implement Notification Service

End Goal

A Flutter service that handles incoming notifications, manages notification state, and provides reactive access to notifications for the inbox UI.

Currently

  • InboxViewModel has an empty Informer<List<MessageDto>>([])
  • No notification API or service exists
  • No Firestore collection for notifications

Should

  • NotificationService streams notifications from Firestore
  • Notifications are sorted by creation time descending
  • Read/unread state is tracked and updatable
  • Unread count is available for badge display
  • Service integrates with existing inbox infrastructure

Constraints

  • [ ] Follow existing sync service patterns (HouseholdCollectionSyncService or similar)
  • [ ] Use existing MessageDto structure with extensions for notification fields
  • [ ] Maintain ID maps for O(1) lookups
  • [ ] Single loop for state updates in sync handler

Acceptance Criteria

  • [ ] NotificationService is registered in LocatorService
  • [ ] Notifications stream in real-time from Firestore
  • [ ] Unread count is reactively available
  • [ ] markAsRead(notificationId) updates Firestore
  • [ ] InboxViewModel uses NotificationService for data

Implementation Checklist

  • [ ] 4.1 Add notifications to FirestoreCollection enum
  • [ ] 4.2 Create NotificationsApi extending RmyApi
  • [ ] 4.3 Create NotificationService as LazySingleton
  • [ ] 4.4 Implement Firestore stream subscription
  • [ ] 4.5 Implement beforeSyncNotifyUpdate with single-loop processing
  • [ ] 4.6 Implement unread count Informer
  • [ ] 4.7 Implement markAsRead method
  • [ ] 4.8 Implement markAllAsRead method
  • [ ] 4.9 Update InboxViewModel to use NotificationService
  • [ ] 4.10 Add Firestore security rules for notifications collection
  • [ ] 4.11 Register service in LocatorService

Notes

  • Query: where('recipientId', '==', userId).orderBy('created', 'desc').limit(100)
  • Consider pagination for users with many notifications
  • readAt field is null for unread, timestamp for read

Reacties

Nog geen reacties