fix(app): mark deep-linked chat sessions read
This commit is contained in:
@@ -68,6 +68,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
..refresh();
|
||||
final _search = TextEditingController();
|
||||
Timer? _undoTimer;
|
||||
String? _markedActiveSessionId;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -78,6 +79,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
/// Reports the loaded rows at the end of the frame: the destination learns a
|
||||
/// routed row without this screen calling back inside its own build.
|
||||
void _reportSessions() {
|
||||
_markActiveSessionRead();
|
||||
if (widget.onSessions == null) return;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
@@ -85,10 +87,28 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
void _markActiveSessionRead() {
|
||||
final id = widget.activeSessionId;
|
||||
if (id == null) {
|
||||
_markedActiveSessionId = null;
|
||||
return;
|
||||
}
|
||||
if (id == _markedActiveSessionId) return;
|
||||
for (final session in _controller.sessions) {
|
||||
if (_sessionId(session) != id) continue;
|
||||
// Mark synchronously so row activation and subsequent list notifications
|
||||
// cannot write the same read watermark twice.
|
||||
_markedActiveSessionId = id;
|
||||
unawaited(_controller.markOpened(session));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatSessionsScreen oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_controller.activeSessionId = widget.activeSessionId;
|
||||
_markActiveSessionRead();
|
||||
if (oldWidget.gateway != widget.gateway) {
|
||||
_controller.replaceRepository(ChatRepository(widget.gateway));
|
||||
} else if (oldWidget.syncToken != widget.syncToken) {
|
||||
@@ -141,6 +161,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
}
|
||||
|
||||
void _open(JsonMap session) {
|
||||
_markedActiveSessionId = _sessionId(session);
|
||||
unawaited(_controller.markOpened(session));
|
||||
widget.onOpen(session);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,61 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('deep-linked active chat is marked read when its row loads', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
final localStore = MemoryChatSessionLocalStore();
|
||||
final pending = Completer<JsonMap>();
|
||||
gateway.pendingSessions.add(pending);
|
||||
const updatedAt = '2026-10-22T12:00:00Z';
|
||||
final session = {
|
||||
'id': 'deep-linked',
|
||||
'title': 'Deep linked chat',
|
||||
'directory': '/work',
|
||||
'updated_at': updatedAt,
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
localStore: localStore,
|
||||
activeSessionId: 'deep-linked',
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
pending.complete({'chat_sessions': [session]});
|
||||
await tester.pumpAndSettle();
|
||||
expect(localStore.state?.watermark('deep-linked'), greaterThan(0));
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
localStore: localStore,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-refresh')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('New'), findsNothing);
|
||||
expect(localStore.state?.watermark('deep-linked'), greaterThan(0));
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'material list keeps closed starred rows once and groups directories once',
|
||||
(tester) async {
|
||||
|
||||
Reference in New Issue
Block a user