mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
Log contact data without revealing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../models/message_contact_location.dart';
|
||||
import '../services/cayenne_lpp_parser.dart';
|
||||
import '../services/contact_storage_service.dart';
|
||||
import '../utils/key_comparison.dart';
|
||||
@@ -214,6 +215,52 @@ class ContactsProvider with ChangeNotifier {
|
||||
List<Contact> get chatContactsWithLocation =>
|
||||
chatContacts.where((c) => c.displayLocation != null).toList();
|
||||
|
||||
MessageContactLocation? buildMessageContactLocationSnapshot(
|
||||
Contact contact, {
|
||||
DateTime? capturedAt,
|
||||
}) {
|
||||
final snapshotTime = capturedAt ?? DateTime.now();
|
||||
final telemetryGps = _getValidGpsOrNull(contact.telemetry?.gpsLocation);
|
||||
final telemetryTimestamp = contact.telemetry?.timestamp;
|
||||
|
||||
AdvertLocation? advertLocation;
|
||||
for (final point in contact.advertHistory) {
|
||||
if (!point.timestamp.isAfter(snapshotTime)) {
|
||||
advertLocation = point;
|
||||
break;
|
||||
}
|
||||
}
|
||||
advertLocation ??= contact.advertHistory.isNotEmpty
|
||||
? contact.advertHistory.first
|
||||
: null;
|
||||
|
||||
if (telemetryGps != null) {
|
||||
final shouldUseTelemetry =
|
||||
telemetryTimestamp == null ||
|
||||
advertLocation == null ||
|
||||
!telemetryTimestamp.isBefore(advertLocation.timestamp);
|
||||
if (shouldUseTelemetry) {
|
||||
return MessageContactLocation(
|
||||
location: telemetryGps,
|
||||
source: 'telemetry',
|
||||
capturedAt: snapshotTime,
|
||||
sourceTimestamp: telemetryTimestamp,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (advertLocation != null) {
|
||||
return MessageContactLocation(
|
||||
location: advertLocation.location,
|
||||
source: 'advert',
|
||||
capturedAt: snapshotTime,
|
||||
sourceTimestamp: advertLocation.timestamp,
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Sort contacts by last seen (most recent first)
|
||||
int _sortByLastSeen(Contact a, Contact b) {
|
||||
return b.lastSeenTime.compareTo(a.lastSeenTime);
|
||||
|
||||
Reference in New Issue
Block a user