meshcore-open/lib/utils/contact_search.dart
Winston Lowe 81758adc61
Dev discovery (#291)
* Refactor contact handling: replace DiscoveryContact with Contact, update related methods and settings

* Enhance contact handling: include latitude, longitude, and last modified timestamp in contact updates; refactor path handling to accommodate discovered contacts across multiple screens

* Enhance SNRIndicator: include discovered contacts in name resolution for repeaters

* Refactor path handling: replace addReturnPath with buildPath to improve path construction logic and handle target contact types

* Update lib/screens/map_screen.dart

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add localization for "Show Discovery Contacts" in multiple languages and refactor location plausibility check in map screen

* Enhance contact management: update discovered contacts' active status and improve contact handling with flags and raw packet data

* Refactor ChannelsScreen: pass ChannelMessageStore to buildExpandedContent and ensure messages are cleared after channel creation

* Update MapScreen: adjust label zoom threshold and refactor guessed marker building to include labels

* Refactor ChannelsScreen: change channelMessageStore to a private getter and update its usage in buildExpandedContent calls

* Enhance location plausibility check: add latitude and longitude bounds to ensure valid coordinates

* Update lib/connector/meshcore_connector.dart

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor MeshCoreConnector and related stores: update discovered contacts handling, migrate legacy keys, and set public key in community store

* Refactor MeshCoreConnector and ChannelsScreen: update discovered contacts handling and set public key in community store; enhance location plausibility check in MapScreen

* Update CMD_ADD_UPDATE_CONTACT frame format to include optional latitude and longitude fields

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-12 23:08:46 -07:00

43 lines
1.2 KiB
Dart

import '../models/contact.dart';
bool matchesContactQuery(Contact contact, String query) {
final normalizedQuery = query.trim().toLowerCase();
if (normalizedQuery.isEmpty) return true;
if (contact.name.toLowerCase().contains(normalizedQuery)) {
return true;
}
final hexPrefix = _extractHexPrefix(normalizedQuery);
if (hexPrefix == null) return false;
return contact.publicKeyHex.toLowerCase().startsWith(hexPrefix);
}
bool matchesDiscoveryContactQuery(Contact contact, String query) {
final normalizedQuery = query.trim().toLowerCase();
if (normalizedQuery.isEmpty) return true;
if (contact.name.toLowerCase().contains(normalizedQuery)) {
return true;
}
final hexPrefix = _extractHexPrefix(normalizedQuery);
if (hexPrefix == null) return false;
return contact.publicKeyHex.toLowerCase().startsWith(hexPrefix);
}
String? _extractHexPrefix(String query) {
var cleaned = query;
if (cleaned.startsWith('<')) {
cleaned = cleaned.substring(1).replaceAll(">", "");
}
if (cleaned.startsWith('0x')) {
cleaned = cleaned.substring(2);
}
cleaned = cleaned.replaceAll(' ', '');
if (cleaned.length < 2) return null;
if (!RegExp(r'^[0-9a-f]+$').hasMatch(cleaned)) return null;
return cleaned;
}