From 62fc4821c4a66313c300328aa1cf19808a41e0de Mon Sep 17 00:00:00 2001
From: Matthias Nott <mnott@mnsoft.org>
Date: Tue, 24 Mar 2026 09:41:36 +0100
Subject: [PATCH] fix: send catch_up on app resume to fetch messages missed during background

---
 lib/screens/chat_screen.dart |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart
index f8d360d..f6d7dd5 100644
--- a/lib/screens/chat_screen.dart
+++ b/lib/screens/chat_screen.dart
@@ -164,6 +164,12 @@
       _sendCommand('sync', activeId != null ? {'activeSessionId': activeId} : null);
       // catch_up is sent after sessions arrive (in _handleSessions)
     };
+    _ws!.onResume = () {
+      // App came back from background with connection still alive.
+      // Send catch_up to fetch any messages missed during suspend.
+      _chatLog('onResume: sending catch_up with lastSeq=$_lastSeq');
+      _sendCommand('catch_up', {'lastSeq': _lastSeq});
+    };
     _ws!.onError = (error) {
       debugPrint('MQTT error: $error');
     };

--
Gitblit v1.3.1