fix(chat): keep a pushed phone conversation marked as read
This commit is contained in:
@@ -219,7 +219,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
controller: _sessions,
|
||||
onOpen: _open,
|
||||
onSessions: _adoptRows,
|
||||
activeSessionId: narrow ? null : selected,
|
||||
activeSessionId: selected,
|
||||
publishShellBar: narrow || selected == null,
|
||||
);
|
||||
if (narrow) return list;
|
||||
return Stack(
|
||||
|
||||
@@ -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<ChatSessionsScreen> {
|
||||
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(
|
||||
|
||||
@@ -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<JsonMap> 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<String?>('s1');
|
||||
addTearDown(selected.dispose);
|
||||
final screen = ShellBarScope(
|
||||
registry: bar,
|
||||
destination: AppDestination.chat,
|
||||
child: ValueListenableBuilder<String?>(
|
||||
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<ChatSessionsScreen>(
|
||||
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());
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user