mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-06 08:46:40 +10:00
Enhance contact handling logic in MeshCoreConnector to support conditional addition based on auto-add settings (#268)
This commit is contained in:
@@ -1926,7 +1926,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
case pushCodeNewAdvert:
|
case pushCodeNewAdvert:
|
||||||
debugPrint('Got New CONTACT');
|
debugPrint('Got New CONTACT');
|
||||||
// It's the same format as respCodeContact, so we can reuse the handler
|
// It's the same format as respCodeContact, so we can reuse the handler
|
||||||
_handleContact(frame);
|
_handleContact(frame, isContact: false);
|
||||||
break;
|
break;
|
||||||
case respCodeContact:
|
case respCodeContact:
|
||||||
debugPrint('Got CONTACT');
|
debugPrint('Got CONTACT');
|
||||||
@@ -2217,7 +2217,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleContact(Uint8List frame) {
|
void _handleContact(Uint8List frame, {bool isContact = true}) {
|
||||||
final contact = Contact.fromFrame(frame);
|
final contact = Contact.fromFrame(frame);
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
if (contact.type == advTypeRepeater) {
|
if (contact.type == advTypeRepeater) {
|
||||||
@@ -2256,11 +2256,23 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
tag: 'Connector',
|
tag: 'Connector',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
_contacts.add(contact);
|
if ((_autoAddUsers && contact.type == advTypeChat) ||
|
||||||
appLogger.info(
|
(_autoAddRepeaters && contact.type == advTypeRepeater) ||
|
||||||
'Added new contact ${contact.name}: pathLen=${contact.pathLength}',
|
(_autoAddRoomServers && contact.type == advTypeRoom) ||
|
||||||
tag: 'Connector',
|
(_autoAddSensors && contact.type == advTypeSensor) ||
|
||||||
);
|
isContact) {
|
||||||
|
_contacts.add(contact);
|
||||||
|
appLogger.info(
|
||||||
|
'Added new contact ${contact.name}: pathLen=${contact.pathLength}',
|
||||||
|
tag: 'Connector',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
appLogger.info(
|
||||||
|
"Discovered contact ${contact.name} (type ${contact.typeLabel}) not added due to auto-add settings",
|
||||||
|
tag: 'Connector',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_knownContactKeys.add(contact.publicKeyHex);
|
_knownContactKeys.add(contact.publicKeyHex);
|
||||||
_loadMessagesForContact(contact.publicKeyHex);
|
_loadMessagesForContact(contact.publicKeyHex);
|
||||||
|
|||||||
Reference in New Issue
Block a user