Enhance contact handling logic in MeshCoreConnector.#268
Conversation
…ional addition based on auto-add settings
There was a problem hiding this comment.
Pull request overview
This PR adjusts MeshCoreConnector’s contact ingestion so that “new advert” frames don’t automatically become full contacts unless auto-add settings allow it, aiming to keep contacts/discovery state consistent between the app and the companion device.
Changes:
- Route
pushCodeNewAdvertthrough_handleContact(..., isContact: false)to distinguish adverts from actual device contacts. - Extend
_handleContactwith anisContactflag and gate adding new entries to_contactsbased on auto-add settings (orisContact).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "Discovered contact ${contact.name} (type ${contact.typeLabel}) not added due to auto-add settings", | ||
| tag: 'Connector', | ||
| ); | ||
| return; |
There was a problem hiding this comment.
If isContact is false and auto-add for this type is disabled, the handler logs and returns here, but does not add the advert to _discoveredContacts (or persist/notify it). As a result, pushCodeNewAdvert frames are effectively dropped and the discovery list still won’t show the contact. Consider routing this case into the discovery flow (e.g., _handleDiscovery(contact, <rawPacket>)) instead of returning silently.
| return; | |
| _handleDiscovery(contact, rawPacket); |
| if ((_autoAddUsers && contact.type == advTypeChat) || | ||
| (_autoAddRepeaters && contact.type == advTypeRepeater) || | ||
| (_autoAddRoomServers && contact.type == advTypeRoom) || | ||
| (_autoAddSensors && contact.type == advTypeSensor) || | ||
| isContact) { |
There was a problem hiding this comment.
The auto-add predicate is now duplicated (here and in _handlePayloadAdvertReceived). Consider extracting it into a single helper (e.g., _shouldAutoAdd(type) / _shouldAutoAddContact(Contact)) to avoid the two sites drifting over time when new advert types/flags are added.
Enhance contact handling logic in MeshCoreConnector to support conditional addition based on auto-add settings.
Fixes a problem where all contacts got added to the contacts list in the app, but not on the companion.
This also added it to the known contacts, and made the discovery list not show the contact.