From 2d66e426243cac64b27f1b36abf5a33f7a75b9d7 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 25 Nov 2021 18:13:36 -0800 Subject: [PATCH 1/2] support for server metrics --- lib/cwtch/cwtchNotifier.dart | 6 ++++++ lib/l10n/intl_fr.arb | 1 + lib/models/servers.dart | 31 ++++++++++++++++++++++++++++ lib/views/addeditservers.dart | 39 ++++++++++++++++++++++++++++------- 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index d3c01c55..29ec9ce4 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -79,6 +79,12 @@ class CwtchNotifier { server.setRunning(data["Intent"] == "running"); } break; + case "ServerStatsUpdate": + EnvironmentConfig.debugLog("ServerStatsUpdate $data"); + var totalMessages = int.parse(data["TotalMessages"]); + var connections = int.parse(data["Connections"]); + serverListState.updateServerStats(data["Identity"], totalMessages, connections); + break; case "GroupCreated": // Retrieve Server Status from Cache... String status = ""; diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 66c5b046..218346d3 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -8,6 +8,7 @@ "serverConnectionsLabel": "Connexion", "manageKnownServersShort": "Serveurs", "manageKnownServersLong": "Gérer les serveurs connus", + "displayNameTooltip": "Veuillez entrer un nom d'usage s'il vous plaît", "manageKnownServersButton": "Gérer les serveurs connus", "importLocalServerSelectText": "Sélectionnez le serveur local", "importLocalServerLabel": "Importer un serveur hébergé localement", diff --git a/lib/models/servers.dart b/lib/models/servers.dart index 2850668b..cd059cbf 100644 --- a/lib/models/servers.dart +++ b/lib/models/servers.dart @@ -39,11 +39,34 @@ class ServerListState extends ChangeNotifier { notifyListeners(); } + void updateServerStats(String onion, int newTotalMessages, int newConnections) { + var server = getServer(onion); + if (server != null) { + server.setStats(newTotalMessages, newConnections); + resort(); + notifyListeners(); + } + } + void delete(String onion) { _servers.removeWhere((element) => element.onion == onion); notifyListeners(); } + void resort() { + _servers.sort((ServerInfoState a, ServerInfoState b) { + // return -1 = a first in list + // return 1 = b first in list + if (a.totalMessages > b.totalMessages) { + return -1; + } else if (b.totalMessages > a.totalMessages) { + return 1; + } + + return 0; + }); + } + List get servers => _servers.sublist(0); //todo: copy?? dont want caller able to bypass changenotifier } @@ -55,6 +78,8 @@ class ServerInfoState extends ChangeNotifier { bool running; bool autoStart; bool isEncrypted; + int totalMessages = 0; + int connections = 0; ServerInfoState({required this.onion, required this.serverBundle, required this.running, required this.description, required this.autoStart, required this.isEncrypted}); @@ -72,4 +97,10 @@ class ServerInfoState extends ChangeNotifier { description = val; notifyListeners(); } + + void setStats(int newTotalMessages, int newConnections) { + totalMessages = newTotalMessages; + connections = newConnections; + notifyListeners(); + } } diff --git a/lib/views/addeditservers.dart b/lib/views/addeditservers.dart index b2a5cacf..aec67bfe 100644 --- a/lib/views/addeditservers.dart +++ b/lib/views/addeditservers.dart @@ -81,20 +81,14 @@ class _AddEditServerViewState extends State { child: Form( key: _formKey, child: Container( - margin: EdgeInsets.fromLTRB(30, 0, 30, 10), - padding: EdgeInsets.fromLTRB(20, 0, 20, 10), + margin: EdgeInsets.fromLTRB(30, 5, 30, 10), + padding: EdgeInsets.fromLTRB(20, 5, 20, 10), child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ // Onion Visibility( visible: serverInfoState.onion.isNotEmpty, child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - SizedBox( - height: 20, - ), CwtchLabel(label: AppLocalizations.of(context)!.serverAddress), - SizedBox( - height: 20, - ), SelectableText(serverInfoState.onion) ])), @@ -156,6 +150,35 @@ class _AddEditServerViewState extends State { secondary: Icon(CwtchIcons.favorite_24dp, color: settings.current().mainTextColor()), ), + // metrics + Visibility( + visible: serverInfoState.onion.isNotEmpty, + child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + SizedBox( + height: 20, + ), + Text(AppLocalizations.of(context)!.serverMetricsLabel, style: Provider.of(context).biggerFont), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ + Text(AppLocalizations.of(context)!.serverTotalMessagesLabel), + ]), + Text(serverInfoState.totalMessages.toString()) + ]), + + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ + Text(AppLocalizations.of(context)!.serverConnectionsLabel), + ]), + Text(serverInfoState.connections.toString()) + ]), + + + ])), + // ***** Password ***** // use password toggle From 3b893d4f1564971f828274f486e28c8150ddba2c Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 14 Dec 2021 10:34:37 -0600 Subject: [PATCH 2/2] gate profile servers on groups or servers experiment --- lib/l10n/intl_fr.arb | 3 +-- lib/views/contactsview.dart | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 218346d3..5f4b6fc2 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -8,7 +8,6 @@ "serverConnectionsLabel": "Connexion", "manageKnownServersShort": "Serveurs", "manageKnownServersLong": "Gérer les serveurs connus", - "displayNameTooltip": "Veuillez entrer un nom d'usage s'il vous plaît", "manageKnownServersButton": "Gérer les serveurs connus", "importLocalServerSelectText": "Sélectionnez le serveur local", "importLocalServerLabel": "Importer un serveur hébergé localement", @@ -267,4 +266,4 @@ "newBulletinLabel": "Nouveau bulletin", "createGroupBtn": "Créer", "createGroupTitle": "Créer un groupe" -} \ No newline at end of file +} diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index a05ef4df..e6e13c19 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -114,7 +114,7 @@ class _ContactsViewState extends State { })); // Manage known Servers - if (Provider.of(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) { + if (Provider.of(context, listen: false).isExperimentEnabled(TapirGroupsExperiment) || Provider.of(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) { actions.add(IconButton( icon: Icon(CwtchIcons.dns_24px), tooltip: AppLocalizations.of(context)!.manageKnownServersButton,