Matthias Nott
2026-03-22 798112d632b970ab1649af541a43de6912d2d43a
fix: seq-based dedup prevents catch_up from duplicating messages
1 files modified
changed files
lib/screens/chat_screen.dart patch | view | blame | history
lib/screens/chat_screen.dart
....@@ -42,6 +42,7 @@
4242 int _lastSeq = 0;
4343 bool _isCatchingUp = false;
4444 bool _screenshotForChat = false;
45
+ final Set<int> _seenSeqs = {};
4546
4647 @override
4748 void initState() {
....@@ -153,9 +154,19 @@
153154 void _handleMessage(Map<String, dynamic> msg) {
154155 // Track sequence numbers for catch_up protocol
155156 final seq = msg['seq'] as int?;
156
- if (seq != null && seq > _lastSeq) {
157
- _lastSeq = seq;
158
- _saveLastSeq();
157
+ if (seq != null) {
158
+ // Dedup: skip messages we've already processed
159
+ if (_seenSeqs.contains(seq)) return;
160
+ _seenSeqs.add(seq);
161
+ // Keep set bounded
162
+ if (_seenSeqs.length > 500) {
163
+ final sorted = _seenSeqs.toList()..sort();
164
+ _seenSeqs.removeAll(sorted.sublist(0, sorted.length - 300));
165
+ }
166
+ if (seq > _lastSeq) {
167
+ _lastSeq = seq;
168
+ _saveLastSeq();
169
+ }
159170 }
160171
161172 final type = msg['type'] as String?;