Merge pull request 'support for server metrics' (#259) from serverMetrics into trunk
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #259 Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
commit
9a7ce2afc7
|
@ -79,6 +79,12 @@ class CwtchNotifier {
|
||||||
server.setRunning(data["Intent"] == "running");
|
server.setRunning(data["Intent"] == "running");
|
||||||
}
|
}
|
||||||
break;
|
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":
|
case "GroupCreated":
|
||||||
// Retrieve Server Status from Cache...
|
// Retrieve Server Status from Cache...
|
||||||
String status = "";
|
String status = "";
|
||||||
|
|
|
@ -266,4 +266,4 @@
|
||||||
"newBulletinLabel": "Nouveau bulletin",
|
"newBulletinLabel": "Nouveau bulletin",
|
||||||
"createGroupBtn": "Créer",
|
"createGroupBtn": "Créer",
|
||||||
"createGroupTitle": "Créer un groupe"
|
"createGroupTitle": "Créer un groupe"
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,34 @@ class ServerListState extends ChangeNotifier {
|
||||||
notifyListeners();
|
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) {
|
void delete(String onion) {
|
||||||
_servers.removeWhere((element) => element.onion == onion);
|
_servers.removeWhere((element) => element.onion == onion);
|
||||||
notifyListeners();
|
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<ServerInfoState> get servers => _servers.sublist(0); //todo: copy?? dont want caller able to bypass changenotifier
|
List<ServerInfoState> 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 running;
|
||||||
bool autoStart;
|
bool autoStart;
|
||||||
bool isEncrypted;
|
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});
|
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;
|
description = val;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setStats(int newTotalMessages, int newConnections) {
|
||||||
|
totalMessages = newTotalMessages;
|
||||||
|
connections = newConnections;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,20 +81,14 @@ class _AddEditServerViewState extends State<AddEditServerView> {
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: EdgeInsets.fromLTRB(30, 0, 30, 10),
|
margin: EdgeInsets.fromLTRB(30, 5, 30, 10),
|
||||||
padding: EdgeInsets.fromLTRB(20, 0, 20, 10),
|
padding: EdgeInsets.fromLTRB(20, 5, 20, 10),
|
||||||
child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
||||||
// Onion
|
// Onion
|
||||||
Visibility(
|
Visibility(
|
||||||
visible: serverInfoState.onion.isNotEmpty,
|
visible: serverInfoState.onion.isNotEmpty,
|
||||||
child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
|
child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||||
SizedBox(
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
CwtchLabel(label: AppLocalizations.of(context)!.serverAddress),
|
CwtchLabel(label: AppLocalizations.of(context)!.serverAddress),
|
||||||
SizedBox(
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
SelectableText(serverInfoState.onion)
|
SelectableText(serverInfoState.onion)
|
||||||
])),
|
])),
|
||||||
|
|
||||||
|
@ -156,6 +150,35 @@ class _AddEditServerViewState extends State<AddEditServerView> {
|
||||||
secondary: Icon(CwtchIcons.favorite_24dp, color: settings.current().mainTextColor()),
|
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<FlwtchState>(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 *****
|
// ***** Password *****
|
||||||
|
|
||||||
// use password toggle
|
// use password toggle
|
||||||
|
|
|
@ -114,7 +114,7 @@ class _ContactsViewState extends State<ContactsView> {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Manage known Servers
|
// Manage known Servers
|
||||||
if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) {
|
if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment) || Provider.of<Settings>(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) {
|
||||||
actions.add(IconButton(
|
actions.add(IconButton(
|
||||||
icon: Icon(CwtchIcons.dns_24px),
|
icon: Icon(CwtchIcons.dns_24px),
|
||||||
tooltip: AppLocalizations.of(context)!.manageKnownServersButton,
|
tooltip: AppLocalizations.of(context)!.manageKnownServersButton,
|
||||||
|
|
Loading…
Reference in New Issue