LCOV - code coverage report
Current view: top level - lib/models - profileservers.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 33 0.0 %
Date: 2024-02-26 20:09:01 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:cwtch/models/remoteserver.dart';
       2             : import 'package:flutter/material.dart';
       3             : 
       4             : import 'contact.dart';
       5             : 
       6             : class ProfileServerListState extends ChangeNotifier {
       7             :   List<RemoteServerInfoState> _servers = [];
       8             : 
       9           0 :   void replace(Iterable<RemoteServerInfoState> newServers) {
      10           0 :     _servers.clear();
      11           0 :     _servers.addAll(newServers);
      12           0 :     resort();
      13           0 :     notifyListeners();
      14             :   }
      15             : 
      16           0 :   RemoteServerInfoState? getServer(String onion) {
      17           0 :     int idx = _servers.indexWhere((element) => element.onion == onion);
      18           0 :     return idx >= 0 ? _servers[idx] : null;
      19             :   }
      20             : 
      21           0 :   void updateServerState(String onion, String status) {
      22           0 :     int idx = _servers.indexWhere((element) => element.onion == onion);
      23           0 :     if (idx >= 0) {
      24           0 :       _servers[idx].status = status;
      25             :     } else {
      26           0 :       print("Tried to update server cache without a starting state...this is probably an error");
      27             :     }
      28           0 :     resort();
      29           0 :     notifyListeners();
      30             :   }
      31             : 
      32           0 :   void resort() {
      33           0 :     _servers.sort((RemoteServerInfoState a, RemoteServerInfoState b) {
      34             :       // return -1 = a first in list
      35             :       // return 1 = b first in list
      36             : 
      37             :       // online v syncing v offline
      38           0 :       if (a.status == "Synced" && b.status != "Synced") {
      39           0 :         return -1;
      40           0 :       } else if (a.status != "Synced" && b.status == "Synced") {
      41             :         return 1;
      42             :       }
      43           0 :       if (a.status == "Authenticated" && b.status != "Authenticated") {
      44           0 :         return -1;
      45           0 :       } else if (a.status != "Authenticated" && b.status == "Authenticated") {
      46             :         return 1;
      47             :       }
      48             : 
      49             :       // num of groups
      50           0 :       if (a.groups.length > b.groups.length) {
      51           0 :         return -1;
      52           0 :       } else if (b.groups.length > a.groups.length) {
      53             :         return 1;
      54             :       }
      55             : 
      56             :       return 0;
      57             :     });
      58             :   }
      59             : 
      60           0 :   void clearGroups() {
      61           0 :     _servers.map((server) => server.clearGroups());
      62             :   }
      63             : 
      64           0 :   void addGroup(ContactInfoState group) {
      65           0 :     int idx = _servers.indexWhere((element) => element.onion == group.server);
      66           0 :     if (idx >= 0) {
      67           0 :       _servers[idx].addGroup(group);
      68             :     }
      69             :   }
      70             : 
      71           0 :   List<RemoteServerInfoState> get servers => _servers.sublist(0); //todo: copy?? dont want caller able to bypass changenotifier
      72             : }

Generated by: LCOV version 1.14