From 399d520c7127a3a953b5a30a94a3c6272ca329ca Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 24 Oct 2026 11:13:48 +0100 Subject: [PATCH] fix(chat): keep a pushed phone conversation marked as read --- app/lib/features/chat/screen.dart | 3 +- .../ui/sessions/chat_sessions_screen.dart | 7 +- .../chat/chat_active_session_test.dart | 93 +++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 app/test/features/chat/chat_active_session_test.dart diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index 1d040c31..3ebaa7cc 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -219,7 +219,8 @@ class _ChatScreenState extends State { controller: _sessions, onOpen: _open, onSessions: _adoptRows, - activeSessionId: narrow ? null : selected, + activeSessionId: selected, + publishShellBar: narrow || selected == null, ); if (narrow) return list; return Stack( diff --git a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart index 6d83c106..f4d8ea5d 100644 --- a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart +++ b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart @@ -26,6 +26,7 @@ class ChatSessionsScreen extends StatefulWidget { this.localStore, this.controller, this.activeSessionId, + this.publishShellBar, }); final ApiGateway gateway; final void Function(JsonMap session) onOpen; @@ -46,6 +47,10 @@ class ChatSessionsScreen extends StatefulWidget { /// Pushed activity for it is being read, so it never raises a New mark. final String? activeSessionId; + /// A pushed phone page owns separate chrome. Keep the underlying list's bar + /// ready without pretending its open conversation is unread/inactive. + final bool? publishShellBar; + /// Overrides the device-local hidden/read store in tests. final ChatSessionLocalStore? localStore; @@ -249,7 +254,7 @@ class _ChatSessionsScreenState extends State { if (widget.embedded) { if (ShellBar.available(context)) { return ShellBar( - active: widget.activeSessionId == null, + active: widget.publishShellBar ?? widget.activeSessionId == null, actions: _actions(), // The Chat tab counts chats with messages not yet seen. child: ShellBadge( diff --git a/app/test/features/chat/chat_active_session_test.dart b/app/test/features/chat/chat_active_session_test.dart new file mode 100644 index 00000000..9d939198 --- /dev/null +++ b/app/test/features/chat/chat_active_session_test.dart @@ -0,0 +1,93 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:pipelines_app/core/api_gateway.dart'; +import 'package:pipelines_app/features/chat/screen.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart'; +import 'package:pipelines_app/shell/destination.dart'; +import 'package:pipelines_app/shell/shell_bar.dart'; + +import 'conversation/chat_thread_fixtures.dart'; + +class _Gateway extends FakeChatGateway { + @override + Future call(String type, [JsonMap fields = const {}]) { + if (type == 'chat_sessions') + return Future.value({ + 'chat_sessions': [ + { + 'id': 's1', + 'title': 'Open conversation', + 'updated_at': '2026-10-24T12:00:00Z', + }, + { + 'id': 's2', + 'title': 'Other conversation', + 'updated_at': '2026-10-24T12:00:00Z', + }, + ], + }); + return super.call(type, fields); + } +} + +void main() { + for (final cupertino in [false, true]) { + testWidgets( + 'a pushed phone chat stays read and preserves underlying list chrome ($cupertino)', + (tester) async { + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + SharedPreferences.setMockInitialValues({}); + final gateway = _Gateway()..history = (_) async => chatPage([]); + addTearDown(gateway.close); + final bar = ShellBarRegistry(); + addTearDown(bar.dispose); + final selected = ValueNotifier('s1'); + addTearDown(selected.dispose); + final screen = ShellBarScope( + registry: bar, + destination: AppDestination.chat, + child: ValueListenableBuilder( + valueListenable: selected, + builder: (_, id, _) => ChatScreen( + gateway: gateway, + initialSessionId: id, + onBack: () => selected.value = null, + ), + ), + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: screen)) + : MaterialApp(home: Scaffold(body: screen)), + ); + await tester.pumpAndSettle(); + final list = tester.widget( + find.byType(ChatSessionsScreen, skipOffstage: false), + ); + final controller = list.controller!; + expect(controller.activeSessionId, 's1'); + expect(bar.specFor(AppDestination.chat)?.actions, isNotEmpty); + gateway.emitEvent(chatTextFrame('New live answer', session: 's1')); + await tester.pumpAndSettle(); + expect(controller.sessions.where(controller.isUnseen), isEmpty); + gateway.emitEvent(chatTextFrame('Different answer', session: 's2')); + await tester.pumpAndSettle(); + expect( + controller.sessions + .where(controller.isUnseen) + .map((row) => row['id']), + ['s2'], + ); + await tester.binding.handlePopRoute(); + await tester.pumpAndSettle(); + expect(controller.activeSessionId, isNull); + expect(find.text('Open conversation'), findsOneWidget); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); + } +}