mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
Refactor contact search functionality to use DiscoveryContact model and simplify query matching
This commit is contained in:
parent
75610695c2
commit
92d8e7cd0b
2 changed files with 18 additions and 27 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
|
|
@ -212,17 +213,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
|||
) {
|
||||
var filtered = contacts.where((contact) {
|
||||
if (searchQuery.isEmpty) return true;
|
||||
return matchesContactQuery(
|
||||
Contact(
|
||||
publicKey: contact.publicKey,
|
||||
name: contact.name,
|
||||
type: contact.type,
|
||||
pathLength: contact.pathLength,
|
||||
path: contact.path,
|
||||
lastSeen: contact.lastSeen,
|
||||
),
|
||||
searchQuery,
|
||||
);
|
||||
return matchesDiscoveryContactQuery(contact, searchQuery);
|
||||
}).toList();
|
||||
|
||||
// Filter out own node from the list
|
||||
|
|
@ -237,22 +228,6 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
|||
filtered = filtered.where(_matchesTypeFilter).toList();
|
||||
}
|
||||
|
||||
if (showUnreadOnly) {
|
||||
filtered = filtered.where((contact) {
|
||||
return connector.getUnreadCountForContact(
|
||||
Contact(
|
||||
publicKey: contact.publicKey,
|
||||
name: contact.name,
|
||||
type: contact.type,
|
||||
pathLength: contact.pathLength,
|
||||
path: contact.path,
|
||||
lastSeen: contact.lastSeen,
|
||||
),
|
||||
) >
|
||||
0;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
switch (sortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
filtered.sort(
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import 'package:meshcore_open/models/discovery_contact.dart';
|
||||
|
||||
import '../models/contact.dart';
|
||||
|
||||
bool matchesContactQuery(Contact contact, String query) {
|
||||
|
|
@ -14,6 +16,20 @@ bool matchesContactQuery(Contact contact, String query) {
|
|||
return contact.publicKeyHex.toLowerCase().startsWith(hexPrefix);
|
||||
}
|
||||
|
||||
bool matchesDiscoveryContactQuery(DiscoveryContact 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('0x')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue