feat: Implement advertisement path tracking with location history and UI integration

This commit is contained in:
Janez T
2025-10-15 21:59:04 +02:00
parent 6be182e20a
commit aab79a56ea
7 changed files with 446 additions and 5 deletions

View File

@@ -128,15 +128,32 @@ class ContactsProvider with ChangeNotifier {
// Check if this is a new contact
final isNewContact = !_contacts.containsKey(contact.publicKeyHex);
// If it's a new contact, mark it as new
Contact updatedContact;
if (isNewContact) {
_contacts[contact.publicKeyHex] = contact.copyWith(isNew: true);
// New contact - add initial location to history if available
updatedContact = contact.copyWith(isNew: true);
if (contact.advertLocation != null) {
final timestamp = DateTime.fromMillisecondsSinceEpoch(contact.lastAdvert * 1000);
updatedContact = updatedContact.addAdvertLocation(contact.advertLocation!, timestamp);
}
} else {
// Keep existing isNew status when updating
// Existing contact - preserve history and isNew status
final existingContact = _contacts[contact.publicKeyHex]!;
_contacts[contact.publicKeyHex] = contact.copyWith(isNew: existingContact.isNew);
// Start with existing contact
updatedContact = contact.copyWith(
isNew: existingContact.isNew,
advertHistory: existingContact.advertHistory,
);
// Add new location to history if location has changed
if (contact.advertLocation != null) {
final timestamp = DateTime.fromMillisecondsSinceEpoch(contact.lastAdvert * 1000);
updatedContact = updatedContact.addAdvertLocation(contact.advertLocation!, timestamp);
}
}
_contacts[contact.publicKeyHex] = updatedContact;
_persistContacts();
notifyListeners();
}

View File

@@ -6,9 +6,13 @@ class MapProvider with ChangeNotifier {
double? _targetZoom;
bool _shouldAnimate = false;
// Track which contact paths are currently visible
final Set<String> _visibleContactPaths = {};
LatLng? get targetLocation => _targetLocation;
double? get targetZoom => _targetZoom;
bool get shouldAnimate => _shouldAnimate;
Set<String> get visibleContactPaths => Set.unmodifiable(_visibleContactPaths);
void navigateToLocation({
required LatLng location,
@@ -32,4 +36,32 @@ class MapProvider with ChangeNotifier {
_targetZoom = zoom;
notifyListeners();
}
/// Toggle path visibility for a contact
void toggleContactPath(String publicKeyHex) {
if (_visibleContactPaths.contains(publicKeyHex)) {
_visibleContactPaths.remove(publicKeyHex);
} else {
_visibleContactPaths.add(publicKeyHex);
}
notifyListeners();
}
/// Check if a contact's path is visible
bool isContactPathVisible(String publicKeyHex) {
return _visibleContactPaths.contains(publicKeyHex);
}
/// Hide all contact paths
void hideAllPaths() {
_visibleContactPaths.clear();
notifyListeners();
}
/// Show path for specific contact (hide all others)
void showOnlyPath(String publicKeyHex) {
_visibleContactPaths.clear();
_visibleContactPaths.add(publicKeyHex);
notifyListeners();
}
}