Refactor contact handling and other improvments (#317)

* Refactor contact filtering and improve localization strings; enhance path trace handling

* Add localization for new CLI commands and update existing strings

* Enhance contact handling and UI updates across multiple screens
add unfiltered contact access and improve last seen resolution

* Add polling interval configuration and improve contact handling

* Reorder command constants for better organization and clarity

* Refactor contact handling by removing unnecessary mapping and improving clarity across multiple screens

* Moved RadioStatsIconButton in chat screen for improved UI consistency

* Added indicators to AppBar for channels

* Ignore contacts with self public key in contact handling

* Simplify path removal logic and clean up unused imports in path management dialog

* Enhance path hop resolution by adding distance checks to improve candidate selection accuracy

* Remove unnecessary reset of radio stats poll reference count in polling interval setter
This commit is contained in:
Winston Lowe
2026-03-26 22:28:01 -07:00
committed by Enot (ded) Skelly
parent 89a14c2719
commit 4879b136f8
51 changed files with 488 additions and 109 deletions
+41 -4
View File
@@ -196,6 +196,7 @@ class MeshCoreConnector extends ChangeNotifier {
static const int _contactMsgBackoffFallbackMs = 5000;
static const int _contactMsgBackoffMinMs = 500;
static const int _contactMsgBackoffMaxMs = 15000;
int _pollingInterval = 30;
bool _batteryRequested = false;
bool _awaitingSelfInfo = false;
bool _hasReceivedDeviceInfo = false;
@@ -326,8 +327,14 @@ class MeshCoreConnector extends ChangeNotifier {
List<Contact> get allContacts => List.unmodifiable([
..._contacts,
..._discoveredContacts.where((c) => !c.isActive),
..._discoveredContacts.where(
(c) => !c.isActive && c.publicKeyHex != selfPublicKeyHex,
),
]);
List<Contact> get allContactsUnfiltered =>
List.unmodifiable([..._contacts, ..._discoveredContacts]);
List<Contact> get discoveredContacts {
return List.unmodifiable(_discoveredContacts);
}
@@ -2368,9 +2375,18 @@ class MeshCoreConnector extends ChangeNotifier {
_batteryPollTimer = null;
}
void setPollingInterval(int i) {
_pollingInterval = i.clamp(1, 60);
if (isConnected) {
_startRadioStatsPolling();
}
}
void _startRadioStatsPolling() {
_radioStatsPollTimer?.cancel();
_radioStatsPollTimer = Timer.periodic(const Duration(seconds: 1), (_) {
_radioStatsPollTimer = Timer.periodic(Duration(seconds: _pollingInterval), (
_,
) {
if (!isConnected) {
_stopRadioStatsPolling();
return;
@@ -2495,6 +2511,18 @@ class MeshCoreConnector extends ChangeNotifier {
});
}
Contact getFromDiscovered(Contact contact) {
final tmp = _discoveredContacts.firstWhere(
(c) => c.publicKeyHex == contact.publicKeyHex,
orElse: () => contact,
);
return contact.copyWith(
rawPacket: tmp.rawPacket,
latitude: tmp.latitude,
longitude: tmp.longitude,
);
}
Future<void> getContacts({int? since, bool preserveExisting = false}) async {
if (!isConnected) return;
@@ -3885,8 +3913,17 @@ class MeshCoreConnector extends ChangeNotifier {
}
void _handleContact(Uint8List frame, {bool isContact = true}) {
final contact = Contact.fromFrame(frame);
if (contact != null) {
final contactTmp = Contact.fromFrame(frame);
if (contactTmp != null) {
if (listEquals(contactTmp.publicKey, _selfPublicKey)) {
appLogger.info(
'Ignoring contact with self public key: ${contactTmp.name}',
tag: 'Connector',
);
removeContact(contactTmp);
return;
}
final contact = getFromDiscovered(contactTmp);
_handleDiscovery(contact, frame, noNotify: true, addActive: true);
if (contact.type == advTypeRepeater) {
+2 -2
View File
@@ -202,15 +202,15 @@ const int cmdGetChannel = 31;
const int cmdSetChannel = 32;
const int cmdSendTracePath = 36;
const int cmdSetOtherParams = 38;
const int cmdSendAnonReq = 57;
const int cmdSendTelemetryReq = 39;
const int cmdGetCustomVar = 40;
const int cmdSetCustomVar = 41;
const int cmdSendBinaryReq = 50;
const int cmdGetStats = 56;
const int cmdSendAnonReq = 57;
const int cmdSetAutoAddConfig = 58;
const int cmdGetAutoAddConfig = 59;
const int cmdSetPathHashMode = 61;
const int cmdGetStats = 56;
// Text message types
const int txtTypePlain = 0;