5593e2451e
Saved machines' state and sign-in live in Settings; the chat no longer shows "<machine> · Connected" above both panes, which also pushed the thread pane below a bar that belongs to neither pane.
91 lines
3.0 KiB
Dart
91 lines
3.0 KiB
Dart
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<String>? onSessionSelected;
|
|
final VoidCallback? onBack;
|
|
final VoidCallback? onWorkspaceEmpty;
|
|
final ValueChanged<Set<String>>? 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,
|
|
);
|
|
}
|