Servers: name a machine after its hostname once it connects
A saved server still named by the app ('My server', 'This server',
'Original legacy server' or its address host/IP) takes the hostname the
machine reports in get_status the first time the app connects; typed
names are kept. New servers (legacy migration, Settings with a blank
name, onboarding) start with the address host. A browser on its page
origin with no saved profile shows the reported hostname too. No server
change: get_status already reports the hostname.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import '../../transport/pipelines_client.dart';
|
||||
import '../../../features/settings/server_connections.dart';
|
||||
import '../machine_access.dart';
|
||||
import '../server_catalog.dart';
|
||||
import '../server_naming.dart';
|
||||
import 'browser_peer.dart';
|
||||
import 'chat_server_gateway.dart';
|
||||
import 'federated_chat_gateway.dart';
|
||||
@@ -27,6 +28,9 @@ class ChatMachineStatus {
|
||||
|
||||
/// Why the machine is not connected, once classified; null while unknown.
|
||||
MachineAccessResult? access;
|
||||
|
||||
/// The machine reported its hostname to this pool; asked once per pool.
|
||||
bool hostnameKnown = false;
|
||||
}
|
||||
|
||||
/// Probes one saved machine with its own kept sign-in (see
|
||||
@@ -180,6 +184,7 @@ class ChatServerPool extends ChangeNotifier implements MachineAuthenticator {
|
||||
if (item.connected && !was) {
|
||||
revision++;
|
||||
unawaited(ackSync.connected());
|
||||
unawaited(_learnHostname(item, generation));
|
||||
}
|
||||
if (!item.connected && !item.connecting && item.access == null) {
|
||||
unawaited(_classify(item, generation));
|
||||
@@ -189,6 +194,7 @@ class ChatServerPool extends ChangeNotifier implements MachineAuthenticator {
|
||||
revision++;
|
||||
if (item.connected) {
|
||||
unawaited(ackSync.connected());
|
||||
unawaited(_learnHostname(item, generation));
|
||||
} else {
|
||||
unawaited(_classify(item, generation));
|
||||
}
|
||||
@@ -207,6 +213,21 @@ class ChatServerPool extends ChangeNotifier implements MachineAuthenticator {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
/// Names a machine the app named by its address after the hostname it
|
||||
/// reports (see [ServerConnections.learnHostname]); typed names are kept.
|
||||
Future<void> _learnHostname(ChatMachineStatus item, int generation) async {
|
||||
final adapter = item.adapter;
|
||||
if (item.hostnameKnown || adapter == null) return;
|
||||
item.hostnameKnown = true;
|
||||
final hostname = await fetchServerHostname(adapter.gateway);
|
||||
if (_disposed || generation != item.generation) return;
|
||||
if (hostname.isEmpty) {
|
||||
item.hostnameKnown = false;
|
||||
return;
|
||||
}
|
||||
await servers.learnHostname(item.server.id, hostname);
|
||||
}
|
||||
|
||||
/// A native socket that did not open says nothing about why. Ask the web
|
||||
/// login with this machine's own kept sign-in: a form means it wants its
|
||||
/// password, a redirect means the sign-in is fine and the socket failed.
|
||||
|
||||
Reference in New Issue
Block a user