From 0b9d8a65740476ad40616cfd779963460999ff00 Mon Sep 17 00:00:00 2001
From: Matthias Nott <mnott@mnsoft.org>
Date: Sun, 22 Mar 2026 09:30:59 +0100
Subject: [PATCH] fix: flush messages before session switch to prevent data loss
---
TODO.md | 12 ++++++++----
lib/providers/providers.dart | 3 ++-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/TODO.md b/TODO.md
index b2fc759..05ec6fc 100644
--- a/TODO.md
+++ b/TODO.md
@@ -14,10 +14,14 @@
- Deliver transcript + images together as one message to Claude
- Ensures voice prefix sets reply channel correctly
-### Push Notifications (iOS APNs)
-- Notify when messages arrive while app is backgrounded/closed
-- Requires Apple Developer Portal APNs key setup
-- Server-side message queue for offline delivery
+### Push Notifications (iOS APNs) — NEXT SESSION with user at computer
+- **Step 1**: User creates APNs key in Apple Developer Portal (needs login)
+- **Step 2**: Save `.p8` key to `~/.aibroker/apns-key.p8`, add env vars (key ID, team ID)
+- **Step 3**: Server-side APNs HTTP/2 sender (`src/daemon/apns.ts`) with JWT auth
+- **Step 4**: App sends device token on WebSocket connect
+- **Step 5**: Gateway buffers messages when no WS clients, sends push notification
+- **Step 6**: App receives push → user taps → opens app → catch_up drains messages
+- Optional: silent push to wake app briefly for critical messages
### App Name Renaming (Runner → PAILot)
- Rename Xcode target from Runner to PAILot (like Glidr did)
diff --git a/lib/providers/providers.dart b/lib/providers/providers.dart
index 530f78e..d4654dd 100644
--- a/lib/providers/providers.dart
+++ b/lib/providers/providers.dart
@@ -92,9 +92,10 @@
/// Switch to a new session and load its messages.
Future<void> switchSession(String sessionId) async {
- // Save current session before switching
+ // Force-flush current session to disk before switching
if (_currentSessionId != null && state.isNotEmpty) {
MessageStore.save(_currentSessionId!, state);
+ await MessageStore.flush();
}
_currentSessionId = sessionId;
--
Gitblit v1.3.1