diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index b64cb0fe1..0495fa7aa 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1455,6 +1455,26 @@ void NodeDB::updateTelemetry(uint32_t nodeId, const meshtastic_Telemetry &t, RxS notifyObservers(true); // Force an update whether or not our node counts have changed } +/** + * Update the node database with a new contact + */ +void NodeDB::addFromContact(meshtastic_SharedContact contact) +{ + meshtastic_NodeInfoLite *info = getOrCreateMeshNode(contact.node_num); + if (!info) { + return; + } + info->num = contact.node_num; + info->last_heard = getValidTime(RTCQualityNTP); + info->has_user = true; + info->user = TypeConversions::ConvertToUserLite(contact.user); + info->is_favorite = true; + updateGUIforNode = info; + powerFSM.trigger(EVENT_NODEDB_UPDATED); + notifyObservers(true); // Force an update whether or not our node counts have changed + saveNodeDatabaseToDisk(); +} + /** Update user info and channel for this node based on received user data */ bool NodeDB::updateUser(uint32_t nodeId, meshtastic_User &p, uint8_t channelIndex) diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 291c3804b..4dbda6a9f 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -110,6 +110,8 @@ class NodeDB /// we updateGUI and updateGUIforNode if we think our this change is big enough for a redraw void updateFrom(const meshtastic_MeshPacket &p); + void addFromContact(const meshtastic_SharedContact); + /** Update position info for this node based on received position data */ void updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSource src = RX_SRC_RADIO); diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 0e1e1555b..cbf82ae73 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -286,6 +286,11 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta nodeDB->removeNodeByNum(r->remove_by_nodenum); break; } + case meshtastic_AdminMessage_add_contact_tag: { + LOG_INFO("Client received add_contact command"); + nodeDB->addFromContact(r->add_contact); + break; + } case meshtastic_AdminMessage_set_favorite_node_tag: { LOG_INFO("Client received set_favorite_node command"); meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(r->set_favorite_node);