import '../core/servers/chat/chat_server_pool.dart'; import 'package:flutter/material.dart'; import '../features/chat/screen.dart'; import '../ui/adaptive/host.dart'; import '../ui/adaptive/top_bar_notices.dart'; import 'app_session.dart'; import 'connection_status.dart'; import 'server_endpoint.dart'; /// The Chat destination: the shared session list and one read-only thread. /// /// Before the shared socket accepts its first connection nothing is requested, /// so an offline launch cannot look like an empty chat list. After that the /// screen stays mounted through drops; a reconnect advances [syncToken] so the /// open conversation re-subscribes and re-reads without losing its selection. class ChatDestination extends StatelessWidget { const ChatDestination({ super.key, required this.session, required this.server, this.pool, this.initialSessionId, this.onSessionSelected, this.onBack, this.onWorkspaceEmpty, this.onAvailableSessionsChanged, }); final AppSession session; final ChatServerPool? pool; final ServerEndpoint server; final String? initialSessionId; final ValueChanged? onSessionSelected; final VoidCallback? onBack; final VoidCallback? onWorkspaceEmpty; final ValueChanged>? onAvailableSessionsChanged; @override Widget build(BuildContext context) => AnimatedBuilder( animation: Listenable.merge([session, ?pool]), builder: (context, _) { final cupertino = usesCupertinoHost(context); // Saved machines connect independently; their state and sign-in live // in Settings, so the chat itself carries no connection chrome. if (pool != null && pool!.servers.catalog.servers.isNotEmpty) { return _chatScreen(); } if ((server.requiresConfiguration || server.error != null) && session.endpoint == null) { return ConnectionGate( session: session, server: server, cupertino: cupertino, ); } if (!session.everConnected) { if (session.connected) return _chatScreen(); return ConnectionGate( session: session, server: server, cupertino: cupertino, ); } // The banner stays below the top bar; without it the chat screen // reaches the top edge (an open chat beside the list draws its own bar // there). return TopBarNotices( notices: [ if (!session.connected) ConnectionBanner(session: session, cupertino: cupertino), ], child: _chatScreen(), ); }, ); Widget _chatScreen() => ChatScreen( gateway: pool?.gateway ?? session.gateway, persistWorkspace: true, initialSessionId: initialSessionId == null ? null : pool?.gateway.normalizeId(initialSessionId!) ?? initialSessionId, syncToken: pool?.revision ?? session.connectionEpoch, onSessionSelected: onSessionSelected, onBack: onBack, onWorkspaceEmpty: onWorkspaceEmpty, onAvailableSessionsChanged: onAvailableSessionsChanged, ); }