Implement Read Receipt Service
epic-contact-detail-and-edit-main-screen-task-009 — Build the read receipt service that consumes field-encryption-utils to record when sensitive Blindeforbundet fields are first viewed by a coordinator. Write receipt records to Supabase with user ID, timestamp, and field identifier. Provide a stream of receipt status so the encrypted-field-display widget can show 'read' vs 'unread' state. Ensure RLS prevents cross-user receipt leakage.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 1 - 540 tasks
Can start after Tier 0 completes
Implementation Notes
Use Supabase's `upsert()` with `onConflict: 'user_id,contact_id,field_identifier'` and `ignoreDuplicates: true` to achieve idempotency at the database level. Define the `field_read_receipts` table with a composite unique constraint on these three columns. For `watchReceiptStatus()`, perform an initial SELECT on subscription, then optionally subscribe to Supabase Realtime changes filtered to the current user. If Realtime is not enabled, a simple periodic poll (every 30s) is acceptable for v1.
Keep the service stateless — do not cache receipt state in memory, as the source of truth is Supabase. Provide the service as a Riverpod `Provider` (not `StateNotifier`) since it has no mutable local state.
Testing Requirements
Unit tests (flutter_test): mock Supabase client; verify `recordReceipt()` performs upsert with correct payload; verify idempotent behaviour on duplicate call; verify `watchReceiptStatus()` emits `unread` before insert and `read` after. Integration test against local Supabase: verify RLS prevents reading receipts created by a different user ID. Test network failure scenario — service should not throw, should emit `unread`. Target ≥85% line coverage.
The Peer Mentor Profile tab on the contact detail screen depends on the peer-mentor-detail-screen-widget being delivered by the separate Peer Mentor Detail feature. If that feature is delayed, the navigation affordance will be present but lead to a stub screen, which may confuse coordinators in the TestFlight pilot.
Mitigation & Contingency
Mitigation: Implement the peer mentor tab with a feature flag guard. When the Peer Mentor Detail feature is incomplete, the flag disables the tab. Coordinate delivery timelines with the team responsible for Peer Mentor Detail to align TestFlight releases.
Contingency: If the Peer Mentor Detail feature is significantly delayed, ship the contact detail screen without the peer mentor tab in the first TestFlight build and add it as an incremental update once the dependent screen is ready.
The contact detail screen must adapt its layout significantly based on organisation context: NHF shows affiliation chips, Blindeforbundet shows encrypted fields and assignment status, standard contacts show neither. Managing this conditional rendering without introducing bugs in each variant is complex and increases the risk of organisation-specific regressions.
Mitigation & Contingency
Mitigation: Define a ContactDetailViewModel that resolves all org-specific flags (showEncryptedFields, showAssignmentStatus, showMultiChapterChips) from the organisation config before the widget tree renders. Widget tests must cover all three organisation variants as separate test cases to catch regressions.
Contingency: If conditional rendering logic grows unwieldy, refactor into separate composable section widgets (ProfileHeaderSection, AffiliationSection, EncryptedFieldsSection) that are conditionally included by the parent screen, isolating org-specific logic to individual components.