2025-12-27 15:32:32 -07:00
|
|
|
import '../models/contact.dart';
|
|
|
|
|
|
2026-03-14 17:59:48 -07:00
|
|
|
export 'contact_filter_types.dart';
|
2026-03-15 00:34:09 +01:00
|
|
|
|
2025-12-27 15:32:32 -07:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 23:08:46 -07:00
|
|
|
bool matchesDiscoveryContactQuery(Contact contact, String query) {
|
2026-02-28 19:14:22 -08:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-27 15:32:32 -07:00
|
|
|
String? _extractHexPrefix(String query) {
|
|
|
|
|
var cleaned = query;
|
2026-03-02 21:35:16 +01:00
|
|
|
if (cleaned.startsWith('<')) {
|
|
|
|
|
cleaned = cleaned.substring(1).replaceAll(">", "");
|
|
|
|
|
}
|
2026-03-02 21:42:44 +01:00
|
|
|
if (cleaned.startsWith('0x')) {
|
|
|
|
|
cleaned = cleaned.substring(2);
|
|
|
|
|
}
|
2025-12-27 15:32:32 -07:00
|
|
|
cleaned = cleaned.replaceAll(' ', '');
|
|
|
|
|
if (cleaned.length < 2) return null;
|
|
|
|
|
if (!RegExp(r'^[0-9a-f]+$').hasMatch(cleaned)) return null;
|
|
|
|
|
return cleaned;
|
|
|
|
|
}
|