Matthias Nott
2026-03-22 0b9d8a65740476ad40616cfd779963460999ff00
fix: flush messages before session switch to prevent data loss
2 files modified
changed files
TODO.md patch | view | blame | history
lib/providers/providers.dart patch | view | blame | history
TODO.md
....@@ -14,10 +14,14 @@
1414 - Deliver transcript + images together as one message to Claude
1515 - Ensures voice prefix sets reply channel correctly
1616
17
-### Push Notifications (iOS APNs)
18
-- Notify when messages arrive while app is backgrounded/closed
19
-- Requires Apple Developer Portal APNs key setup
20
-- Server-side message queue for offline delivery
17
+### Push Notifications (iOS APNs) — NEXT SESSION with user at computer
18
+- **Step 1**: User creates APNs key in Apple Developer Portal (needs login)
19
+- **Step 2**: Save `.p8` key to `~/.aibroker/apns-key.p8`, add env vars (key ID, team ID)
20
+- **Step 3**: Server-side APNs HTTP/2 sender (`src/daemon/apns.ts`) with JWT auth
21
+- **Step 4**: App sends device token on WebSocket connect
22
+- **Step 5**: Gateway buffers messages when no WS clients, sends push notification
23
+- **Step 6**: App receives push → user taps → opens app → catch_up drains messages
24
+- Optional: silent push to wake app briefly for critical messages
2125
2226 ### App Name Renaming (Runner → PAILot)
2327 - Rename Xcode target from Runner to PAILot (like Glidr did)
lib/providers/providers.dart
....@@ -92,9 +92,10 @@
9292
9393 /// Switch to a new session and load its messages.
9494 Future<void> switchSession(String sessionId) async {
95
- // Save current session before switching
95
+ // Force-flush current session to disk before switching
9696 if (_currentSessionId != null && state.isNotEmpty) {
9797 MessageStore.save(_currentSessionId!, state);
98
+ await MessageStore.flush();
9899 }
99100
100101 _currentSessionId = sessionId;