mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
- Move ContactSortOption/ContactTypeFilter enums to dedicated contact_filter_types.dart (re-exported from contact_search.dart) - Migrate ContactsFilterMenu and DiscoveryContactsFilterMenu to use sealed class action types with SortFilterMenu<T> generics, replacing int action constants and switch statements - Guard _closeDropdownAndRun with ModalRoute.isCurrent check to prevent accidental dismissal of parent routes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45 lines
1.3 KiB
Dart
45 lines
1.3 KiB
Dart
import '../models/contact.dart';
|
|
|
|
export 'contact_filter_types.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;
|
|
}
|