Merge pull request #676 from zjs81/fix/list-sorting-and-performance

Fix list ordering and long-list scrolling
This commit is contained in:
zjs81 authored and GitHub committed 2026-11-20 21:21:07 -07:00
commit ae967ec21f
35 files changed
+1357 -43

No files matched your search

+25
View File
@@ -62,6 +62,7 @@ import '../storage/channel_settings_store.dart';
import '../storage/channel_region_store.dart';
import '../storage/channel_storage_migration.dart';
import '../storage/channel_store.dart';
import '../storage/contact_added_at_store.dart';
import '../storage/contact_discovery_store.dart';
import '../storage/contact_settings_store.dart';
import '../storage/contact_store.dart';
@@ -526,6 +527,8 @@ class MeshCoreConnector extends ChangeNotifier {
final ChannelRegionStore _channelRegionStore = ChannelRegionStore();
final ContactSettingsStore _contactSettingsStore = ContactSettingsStore();
final ContactStore _contactStore = ContactStore();
final ContactAddedAtStore _contactAddedAtStore = ContactAddedAtStore();
final Map<String, DateTime> _contactAddedAt = {};
final ContactDiscoveryStore _discoveryContactStore = ContactDiscoveryStore();
final ChannelStore _channelStore = ChannelStore();
final UnreadStore _unreadStore = UnreadStore();
@@ -649,6 +652,11 @@ class MeshCoreConnector extends ChangeNotifier {
return radio.bleDisplayName;
}
/// Phone time a contact was first added from a card; the list orders by it
/// while the radio has no advert time for the contact.
DateTime? contactAddedAt(String contactPubKeyHex) =>
_contactAddedAt[contactPubKeyHex];
Contact? getContactByPubKeyHex(String contactPubKeyHex) {
return _contacts.cast<Contact?>().firstWhere(
(c) => c?.publicKeyHex == contactPubKeyHex,
@@ -2466,6 +2474,9 @@ class MeshCoreConnector extends ChangeNotifier {
_contacts
..clear()
..addAll(cached);
_contactAddedAt
..clear()
..addAll(_contactAddedAtStore.load());
for (final contact in cached) {
_ensureContactSmazSettingLoaded(contact.publicKeyHex);
_ensureContactCyr2LatSettingLoaded(contact.publicKeyHex);
@@ -5128,6 +5139,13 @@ class MeshCoreConnector extends ChangeNotifier {
pathHashByteWidth: pathHashByteWidth,
);
await sendFrame(frame, waitForGenericAck: true);
if (publicKey != null) {
final keyHex = pubKeyToHex(publicKey);
if (!_contactAddedAt.containsKey(keyHex)) {
_contactAddedAt[keyHex] = DateTime.now();
await _contactAddedAtStore.save(_contactAddedAt);
}
}
await refreshContacts();
}
@@ -6123,6 +6141,9 @@ class MeshCoreConnector extends ChangeNotifier {
_contactsStorageFull = false;
_contacts.removeWhere((c) => c.publicKeyHex == contact.publicKeyHex);
_knownContactKeys.remove(contact.publicKeyHex);
if (_contactAddedAt.remove(contact.publicKeyHex) != null) {
unawaited(_contactAddedAtStore.save(_contactAddedAt));
}
unawaited(updateKnownDiscovered());
unawaited(_persistContacts());
_conversations.remove(contact.publicKeyHex);
@@ -7811,6 +7832,9 @@ class MeshCoreConnector extends ChangeNotifier {
);
_contacts.removeWhere((c) => c.publicKeyHex == keyHex);
_knownContactKeys.remove(keyHex);
if (_contactAddedAt.remove(keyHex) != null) {
unawaited(_contactAddedAtStore.save(_contactAddedAt));
}
_contactsStorageFull = false;
unawaited(updateKnownDiscovered());
unawaited(_persistContacts());
@@ -9895,6 +9919,7 @@ class MeshCoreConnector extends ChangeNotifier {
_channelRegionStore.setPublicKeyHex = keyHex;
_contactSettingsStore.setPublicKeyHex = keyHex;
_contactStore.setPublicKeyHex = keyHex;
_contactAddedAtStore.setPublicKeyHex = keyHex;
_channelStore.setPublicKeyHex = keyHex;
_unreadStore.setPublicKeyHex = keyHex;
_discoveryContactStore.setPublicKeyHex = keyHex;