mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-12 17:00:28 +00:00
Allow overriding contact name
This commit is contained in:
@@ -58,6 +58,7 @@ class _RetainedRoute {
|
||||
/// Contacts Provider - manages contact list and telemetry
|
||||
class ContactsProvider with ChangeNotifier {
|
||||
static const double _firstHopFallbackOffsetMeters = 100.0;
|
||||
static const String autoGroupIdPrefix = 'auto_group_';
|
||||
final Map<String, Contact> _contacts = {};
|
||||
final List<SavedContactGroup> _savedContactGroups = <SavedContactGroup>[];
|
||||
final Map<String, PendingAdvert> _pendingAdverts = {};
|
||||
@@ -248,6 +249,8 @@ class ContactsProvider with ChangeNotifier {
|
||||
String sectionKey,
|
||||
String query, {
|
||||
String? label,
|
||||
List<String>? matchPrefixes,
|
||||
bool isAutoGroup = false,
|
||||
}) async {
|
||||
final normalizedQuery = _normalizeGroupQuery(query);
|
||||
if (normalizedQuery.isEmpty ||
|
||||
@@ -262,6 +265,8 @@ class ContactsProvider with ChangeNotifier {
|
||||
label: (label ?? query).trim(),
|
||||
query: query.trim(),
|
||||
createdAt: DateTime.now(),
|
||||
matchPrefixes: matchPrefixes,
|
||||
isAutoGroup: isAutoGroup,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -299,6 +304,18 @@ class ContactsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> replaceAutoGroupsForSection(
|
||||
String sectionKey,
|
||||
List<SavedContactGroup> groups,
|
||||
) async {
|
||||
_savedContactGroups.removeWhere(
|
||||
(group) => group.sectionKey == sectionKey && group.isAutoGroup,
|
||||
);
|
||||
_savedContactGroups.addAll(groups);
|
||||
await _persistSavedGroups();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _persistSavedGroups() async {
|
||||
try {
|
||||
await _storageService.saveContactGroups(_savedContactGroups);
|
||||
@@ -486,6 +503,7 @@ class ContactsProvider with ChangeNotifier {
|
||||
if (existingContact == null) {
|
||||
var newContact = incomingContact.copyWith(
|
||||
isNew: true,
|
||||
nameOverride: existingContact?.nameOverride,
|
||||
telemetry: mergedTelemetry,
|
||||
outPathLen:
|
||||
retainedRoute?.signedEncodedPathLen ?? incomingContact.outPathLen,
|
||||
@@ -514,6 +532,7 @@ class ContactsProvider with ChangeNotifier {
|
||||
|
||||
var updatedContact = incomingContact.copyWith(
|
||||
isNew: false,
|
||||
nameOverride: existingContact.nameOverride,
|
||||
advertHistory: existingContact.advertHistory,
|
||||
telemetry: mergedTelemetry,
|
||||
outPathLen:
|
||||
@@ -1023,6 +1042,26 @@ class ContactsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setContactNameOverride(String publicKeyHex, String? overrideName) {
|
||||
final contact = _contacts[publicKeyHex];
|
||||
if (contact == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final normalizedOverride = overrideName?.trim();
|
||||
final nextOverride =
|
||||
(normalizedOverride == null || normalizedOverride.isEmpty)
|
||||
? null
|
||||
: normalizedOverride;
|
||||
if (contact.nameOverride == nextOverride) {
|
||||
return;
|
||||
}
|
||||
|
||||
_contacts[publicKeyHex] = contact.copyWith(nameOverride: nextOverride);
|
||||
_persistContacts();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Add or refresh a pending advert entry from PUSH_CODE_ADVERT (0x80).
|
||||
/// Excludes self key and existing contacts.
|
||||
void addPendingAdvert(Uint8List publicKey, {Uint8List? devicePublicKey}) {
|
||||
|
||||
Reference in New Issue
Block a user