Merge pull request #512 from ericszimmermann/ez_disable_discoveredContact_eviction_PR
Setting to enable eviction of discovered contacts
This commit is contained in:
26 files changed
+288
-20
No files matched your search
@@ -180,7 +180,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
// continuously from the whole mesh, so without a bound this list grows for
|
||||
// as long as the app stays connected. When full, the stalest node (oldest
|
||||
// lastSeen) is evicted to make room for a newly heard one.
|
||||
static const int _maxDiscoveredContacts = 500;
|
||||
static const int maxDiscoveredContacts = 500;
|
||||
|
||||
MeshCoreConnectionState _state = MeshCoreConnectionState.disconnected;
|
||||
BluetoothDevice? _device;
|
||||
@@ -1356,11 +1356,11 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
|
||||
Future<void> _loadDiscoveredContactCache() async {
|
||||
final cached = await _discoveryContactStore.loadContacts();
|
||||
// Trim a previously-saved oversized list down to the freshest entries so a
|
||||
// device that grew unbounded before the cap existed recovers on load.
|
||||
if (cached.length > _maxDiscoveredContacts) {
|
||||
cached.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
cached.removeRange(_maxDiscoveredContacts, cached.length);
|
||||
// When eviction is enabled, trim a previously-saved oversized list down to
|
||||
// the freshest entries so a device that grew unbounded before the cap
|
||||
// existed recovers on load.
|
||||
if (_evictDiscoveredContactsEnabled &&
|
||||
_trimDiscoveredContactsToLimit(cached)) {
|
||||
unawaited(_discoveryContactStore.saveContacts(cached));
|
||||
}
|
||||
_discoveredContacts
|
||||
@@ -1368,6 +1368,22 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
..addAll(cached);
|
||||
}
|
||||
|
||||
bool get _evictDiscoveredContactsEnabled =>
|
||||
_appSettingsService?.settings.evictDiscoveredContactsEnabled ?? true;
|
||||
|
||||
bool _trimDiscoveredContactsToLimit(List<Contact> contacts) {
|
||||
if (contacts.length <= maxDiscoveredContacts) return false;
|
||||
contacts.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
contacts.removeRange(maxDiscoveredContacts, contacts.length);
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> trimDiscoveredContactsToLimit() async {
|
||||
if (!_trimDiscoveredContactsToLimit(_discoveredContacts)) return;
|
||||
await _persistDiscoveredContacts();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadChannelSettings({int? maxChannels}) async {
|
||||
_channelSmazEnabled.clear();
|
||||
_channelCyr2LatEnabled.clear();
|
||||
@@ -8182,8 +8198,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
flags: 0,
|
||||
);
|
||||
|
||||
if (_discoveredContacts.length >= _maxDiscoveredContacts) {
|
||||
_evictStalestDiscoveredContact();
|
||||
if (_evictDiscoveredContactsEnabled) {
|
||||
while (_discoveredContacts.length >= maxDiscoveredContacts) {
|
||||
_evictStalestDiscoveredContact();
|
||||
}
|
||||
}
|
||||
_discoveredContacts.add(disContact);
|
||||
|
||||
|
||||
+10
-1
@@ -2130,6 +2130,7 @@
|
||||
"contactsSettings_autoAddUsersTitle": "Automatische Hinzufügung von Benutzern",
|
||||
"settings_contactSettingsSubtitle": "Einstellungen für das Hinzufügen von Kontakten",
|
||||
"contactsSettings_autoAddSensorsTitle": "Automatisch Sensoren hinzufügen",
|
||||
"contactsSettings_autoAddSensorsSubtitle": "Ermöglichen Sie dem Begleiter, automatisch entdeckte Sensoren hinzuzufügen",
|
||||
"contactsSettings_autoAddUsersSubtitle": "Ermöglichen Sie dem Begleiter, automatisch entdeckte Benutzer hinzuzufügen",
|
||||
"contactsSettings_autoAddRoomServersTitle": "Automatisch Raumservers hinzufügen",
|
||||
"contactsSettings_autoAddRoomServersSubtitle": "Ermöglichen Sie dem Begleiter, entdeckte Raumserver automatisch hinzuzufügen",
|
||||
@@ -2143,8 +2144,16 @@
|
||||
"discoveredContacts_Title": "Entdeckte Kontakte",
|
||||
"discoveredContacts_copyContact": "Kontakt in die Zwischenablage kopieren",
|
||||
"contactsSettings_overwriteOldestTitle": "Überschreiben des Ältesten",
|
||||
"contactsSettings_autoAddSensorsSubtitle": "Ermöglichen Sie dem Begleiter, automatisch entdeckte Sensoren hinzuzufügen",
|
||||
"contactsSettings_overwriteOldestSubtitle": "Wenn die Kontaktliste voll ist, wird der älteste nicht favorisierte Kontakt ersetzt.",
|
||||
"contactsSettings_evictDiscoveredContactsTitle": "Liste entdeckter Kontakte kürzen",
|
||||
"contactsSettings_evictDiscoveredContactsSubtitle": "Wenn aktiviert, wird die Liste der entdeckten Kontakte auf {limit} Kontakte begrenzt.",
|
||||
"@contactsSettings_evictDiscoveredContactsSubtitle": {
|
||||
"placeholders": {
|
||||
"limit": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"common_deleteAll": "Alles löschen",
|
||||
"discoveredContacts_deleteContactAllContent": "Sind Sie sicher, dass Sie alle gefundenen Kontakte löschen möchten?",
|
||||
"discoveredContacts_deleteContactAll": "Alle entdeckten Kontakte löschen",
|
||||
|
||||
@@ -2648,6 +2648,15 @@
|
||||
"contactsSettings_autoAddSensorsSubtitle": "Allow the companion to automatically add discovered sensors.",
|
||||
"contactsSettings_overwriteOldestTitle": "Overwrite Oldest",
|
||||
"contactsSettings_overwriteOldestSubtitle": "When the contact list is full, the oldest non-favorited contact will be replaced.",
|
||||
"contactsSettings_evictDiscoveredContactsTitle": "Evict discovered contacts",
|
||||
"contactsSettings_evictDiscoveredContactsSubtitle": "When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of {limit} entries.",
|
||||
"@contactsSettings_evictDiscoveredContactsSubtitle": {
|
||||
"placeholders": {
|
||||
"limit": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"discoveredContacts_Title": "Discovered Contacts",
|
||||
"discoveredContacts_noMatching": "No matching contacts",
|
||||
"discoveredContacts_searchHint": "Search discovered contacts",
|
||||
|
||||
@@ -8206,6 +8206,18 @@ abstract class AppLocalizations {
|
||||
/// **'When the contact list is full, the oldest non-favorited contact will be replaced.'**
|
||||
String get contactsSettings_overwriteOldestSubtitle;
|
||||
|
||||
/// No description provided for @contactsSettings_evictDiscoveredContactsTitle.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Evict discovered contacts'**
|
||||
String get contactsSettings_evictDiscoveredContactsTitle;
|
||||
|
||||
/// No description provided for @contactsSettings_evictDiscoveredContactsSubtitle.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of {limit} entries.'**
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit);
|
||||
|
||||
/// No description provided for @discoveredContacts_Title.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
|
||||
@@ -4789,6 +4789,15 @@ class AppLocalizationsBg extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Когато списъкът с контакти е пълен, най-старият неключов контакт ще бъде заменен.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Открити контакти';
|
||||
|
||||
|
||||
@@ -4801,6 +4801,15 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Wenn die Kontaktliste voll ist, wird der älteste nicht favorisierte Kontakt ersetzt.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Liste entdeckter Kontakte kürzen';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'Wenn aktiviert, wird die Liste der entdeckten Kontakte auf $limit Kontakte begrenzt.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Entdeckte Kontakte';
|
||||
|
||||
|
||||
@@ -4720,6 +4720,15 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'When the contact list is full, the oldest non-favorited contact will be replaced.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Discovered Contacts';
|
||||
|
||||
|
||||
@@ -4792,6 +4792,15 @@ class AppLocalizationsEs extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Cuando la lista de contactos esté llena, se reemplazará el contacto no favorito más antiguo.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Contactos descubiertos';
|
||||
|
||||
|
||||
@@ -4814,6 +4814,15 @@ class AppLocalizationsFr extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Lorsque la liste de contacts est pleine, le contact le plus ancien non favori sera remplacé.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Contacts découverts';
|
||||
|
||||
|
||||
@@ -4788,6 +4788,15 @@ class AppLocalizationsHu extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Amikor a névjegylista megtelik, a legrégebbi, nem kedvenc névjegy lecserélődik.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Felfedezett kapcsolatok';
|
||||
|
||||
|
||||
@@ -4798,6 +4798,15 @@ class AppLocalizationsIt extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Quando l\'elenco dei contatti è pieno, il contatto più vecchio non tra i preferiti verrà sostituito.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Contatti scoperti';
|
||||
|
||||
|
||||
@@ -4554,6 +4554,15 @@ class AppLocalizationsJa extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'連絡先リストが満杯になった場合、最も古いかつ「お気に入り」ではない連絡先が削除されます。';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => '連絡先が見つかった';
|
||||
|
||||
|
||||
@@ -4564,6 +4564,15 @@ class AppLocalizationsKo extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'연락처 목록이 가득 차면, 가장 오래된 (선호하지 않은) 연락처가 대체됩니다.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => '연락처 찾기';
|
||||
|
||||
|
||||
@@ -4766,6 +4766,15 @@ class AppLocalizationsNl extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Wanneer de contactenlijst vol is, wordt de oudste niet-favoriete contactpersoon vervangen.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Ontdekte contacten';
|
||||
|
||||
|
||||
@@ -4821,6 +4821,15 @@ class AppLocalizationsPl extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Gdy lista kontaktów jest pełna, najstarszy nieulubiony kontakt zostanie zastąpiony.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Odkryte Kontakty';
|
||||
|
||||
|
||||
@@ -4793,6 +4793,15 @@ class AppLocalizationsPt extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Quando a lista de contatos estiver cheia, o contato mais antigo não favoritado será substituído.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Contatos Descobertos';
|
||||
|
||||
|
||||
@@ -4805,6 +4805,15 @@ class AppLocalizationsRu extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Когда список контактов заполнен, будет заменен самый старый контакт, который не находится в избранном.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Обнаруженные контакты';
|
||||
|
||||
|
||||
@@ -4775,6 +4775,15 @@ class AppLocalizationsSk extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Keď je zoznam kontaktov plný, bude nahradený najstarší neoznačený kontakt.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Objavené kontakty';
|
||||
|
||||
|
||||
@@ -4775,6 +4775,15 @@ class AppLocalizationsSl extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Ko je seznam stikov poln, bo najstarejši nestarševski stik zamenjan.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Odkriti stiki';
|
||||
|
||||
|
||||
@@ -4750,6 +4750,15 @@ class AppLocalizationsSv extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'När kontaktlistan är full ersätts den äldsta icke-favoriterade kontakten.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Upptäckta kontakter';
|
||||
|
||||
|
||||
@@ -4804,6 +4804,15 @@ class AppLocalizationsUk extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'Коли список контактів заповнений, найстарший контакт без позначки улюбленого буде замінений.';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => 'Виявлені контакти';
|
||||
|
||||
|
||||
@@ -4439,6 +4439,15 @@ class AppLocalizationsZh extends AppLocalizations {
|
||||
String get contactsSettings_overwriteOldestSubtitle =>
|
||||
'当联系人列表已满时,将替换最老的非收藏联系人。';
|
||||
|
||||
@override
|
||||
String get contactsSettings_evictDiscoveredContactsTitle =>
|
||||
'Evict discovered contacts';
|
||||
|
||||
@override
|
||||
String contactsSettings_evictDiscoveredContactsSubtitle(int limit) {
|
||||
return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get discoveredContacts_Title => '已发现的联系人';
|
||||
|
||||
|
||||
@@ -120,6 +120,7 @@ class AppSettings {
|
||||
final UnitSystem unitSystem;
|
||||
final Set<String> mutedChannels;
|
||||
final bool mapShowDiscoveryContacts;
|
||||
final bool evictDiscoveredContactsEnabled;
|
||||
final String tcpServerAddress;
|
||||
final int tcpServerPort;
|
||||
final bool jumpToOldestUnread;
|
||||
@@ -226,6 +227,7 @@ class AppSettings {
|
||||
this.unitSystem = UnitSystem.metric,
|
||||
Set<String>? mutedChannels,
|
||||
this.mapShowDiscoveryContacts = true,
|
||||
this.evictDiscoveredContactsEnabled = true,
|
||||
this.tcpServerAddress = '',
|
||||
this.tcpServerPort = 0,
|
||||
this.jumpToOldestUnread = false,
|
||||
@@ -305,6 +307,7 @@ class AppSettings {
|
||||
'unit_system': unitSystem.value,
|
||||
'muted_channels': mutedChannels.toList(),
|
||||
'map_show_discovery_contacts': mapShowDiscoveryContacts,
|
||||
'evict_discovered_contacts_enabled': evictDiscoveredContactsEnabled,
|
||||
'tcp_server_address': tcpServerAddress,
|
||||
'tcp_server_port': tcpServerPort,
|
||||
'jump_to_oldest_unread': jumpToOldestUnread,
|
||||
@@ -407,6 +410,8 @@ class AppSettings {
|
||||
{},
|
||||
mapShowDiscoveryContacts:
|
||||
json['map_show_discovery_contacts'] as bool? ?? true,
|
||||
evictDiscoveredContactsEnabled:
|
||||
json['evict_discovered_contacts_enabled'] as bool? ?? true,
|
||||
tcpServerAddress: json['tcp_server_address'] as String? ?? '',
|
||||
tcpServerPort: json['tcp_server_port'] as int? ?? 0,
|
||||
jumpToOldestUnread: json['jump_to_oldest_unread'] as bool? ?? false,
|
||||
@@ -524,6 +529,7 @@ class AppSettings {
|
||||
UnitSystem? unitSystem,
|
||||
Set<String>? mutedChannels,
|
||||
bool? mapShowDiscoveryContacts,
|
||||
bool? evictDiscoveredContactsEnabled,
|
||||
String? tcpServerAddress,
|
||||
int? tcpServerPort,
|
||||
bool? jumpToOldestUnread,
|
||||
@@ -604,6 +610,8 @@ class AppSettings {
|
||||
mutedChannels: mutedChannels ?? this.mutedChannels,
|
||||
mapShowDiscoveryContacts:
|
||||
mapShowDiscoveryContacts ?? this.mapShowDiscoveryContacts,
|
||||
evictDiscoveredContactsEnabled:
|
||||
evictDiscoveredContactsEnabled ?? this.evictDiscoveredContactsEnabled,
|
||||
tcpServerAddress: tcpServerAddress ?? this.tcpServerAddress,
|
||||
tcpServerPort: tcpServerPort ?? this.tcpServerPort,
|
||||
jumpToOldestUnread: jumpToOldestUnread ?? this.jumpToOldestUnread,
|
||||
|
||||
@@ -1231,6 +1231,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
bool autoAddRoomServer = false;
|
||||
bool autoAddSensor = false;
|
||||
bool overwriteOldest = false;
|
||||
final appSettingsService = context.read<AppSettingsService>();
|
||||
bool evictDiscoveredContactsEnabled =
|
||||
appSettingsService.settings.evictDiscoveredContactsEnabled;
|
||||
bool saving = false;
|
||||
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
autoAddChat = connector.autoAddUsers ?? false;
|
||||
@@ -1292,6 +1296,20 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
setDialogState(() => overwriteOldest = value);
|
||||
},
|
||||
),
|
||||
const Divider(height: 4),
|
||||
FeatureToggleRow(
|
||||
title: l10n.contactsSettings_evictDiscoveredContactsTitle,
|
||||
subtitle: l10n
|
||||
.contactsSettings_evictDiscoveredContactsSubtitle(
|
||||
MeshCoreConnector.maxDiscoveredContacts,
|
||||
),
|
||||
value: evictDiscoveredContactsEnabled,
|
||||
onChanged: (value) {
|
||||
setDialogState(
|
||||
() => evictDiscoveredContactsEnabled = value,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1301,17 +1319,38 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
_sendSettings(
|
||||
connector,
|
||||
autoAddChat,
|
||||
autoAddRepeater,
|
||||
autoAddRoomServer,
|
||||
autoAddSensor,
|
||||
overwriteOldest,
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onPressed: saving
|
||||
? null
|
||||
: () async {
|
||||
setDialogState(() => saving = true);
|
||||
_sendSettings(
|
||||
connector,
|
||||
autoAddChat,
|
||||
autoAddRepeater,
|
||||
autoAddRoomServer,
|
||||
autoAddSensor,
|
||||
overwriteOldest,
|
||||
);
|
||||
try {
|
||||
await appSettingsService
|
||||
.setEvictDiscoveredContactsEnabled(
|
||||
evictDiscoveredContactsEnabled,
|
||||
);
|
||||
if (evictDiscoveredContactsEnabled) {
|
||||
await connector.trimDiscoveredContactsToLimit();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_error(e.toString())),
|
||||
);
|
||||
setDialogState(() => saving = false);
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -240,6 +240,12 @@ class AppSettingsService extends ChangeNotifier {
|
||||
await updateSettings(_settings.copyWith(mapShowDiscoveryContacts: value));
|
||||
}
|
||||
|
||||
Future<void> setEvictDiscoveredContactsEnabled(bool value) async {
|
||||
await updateSettings(
|
||||
_settings.copyWith(evictDiscoveredContactsEnabled: value),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> setBatteryChemistryForDevice(
|
||||
String deviceId,
|
||||
String chemistry,
|
||||
|
||||
@@ -405,6 +405,7 @@ void main() {
|
||||
expect(settings.routeWeightSuccessIncrement, equals(0.5));
|
||||
expect(settings.routeWeightFailureDecrement, equals(0.2));
|
||||
expect(settings.maxMessageRetries, equals(5));
|
||||
expect(settings.evictDiscoveredContactsEnabled, isTrue);
|
||||
});
|
||||
|
||||
test('toJson includes all new fields', () {
|
||||
@@ -415,11 +416,13 @@ void main() {
|
||||
expect(json.containsKey('route_weight_success_increment'), isTrue);
|
||||
expect(json.containsKey('route_weight_failure_decrement'), isTrue);
|
||||
expect(json.containsKey('max_message_retries'), isTrue);
|
||||
expect(json.containsKey('evict_discovered_contacts_enabled'), isTrue);
|
||||
expect(json['max_route_weight'], equals(5.0));
|
||||
expect(json['initial_route_weight'], equals(3.0));
|
||||
expect(json['route_weight_success_increment'], equals(0.5));
|
||||
expect(json['route_weight_failure_decrement'], equals(0.2));
|
||||
expect(json['max_message_retries'], equals(5));
|
||||
expect(json['evict_discovered_contacts_enabled'], isTrue);
|
||||
});
|
||||
|
||||
test('fromJson reads all new fields', () {
|
||||
@@ -429,6 +432,7 @@ void main() {
|
||||
'route_weight_success_increment': 1.0,
|
||||
'route_weight_failure_decrement': 1.5,
|
||||
'max_message_retries': 8,
|
||||
'evict_discovered_contacts_enabled': false,
|
||||
};
|
||||
final settings = AppSettings.fromJson(json);
|
||||
expect(settings.maxRouteWeight, equals(10.0));
|
||||
@@ -436,6 +440,7 @@ void main() {
|
||||
expect(settings.routeWeightSuccessIncrement, equals(1.0));
|
||||
expect(settings.routeWeightFailureDecrement, equals(1.5));
|
||||
expect(settings.maxMessageRetries, equals(8));
|
||||
expect(settings.evictDiscoveredContactsEnabled, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
|
||||
Reference in new issue
Block a user