Skip to content
Open
22 changes: 12 additions & 10 deletions src/graphics/niche/InkHUD/Applets/User/Heard/HeardApplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,28 @@ void InkHUD::HeardApplet::handleParsed(CardInfo c)
void InkHUD::HeardApplet::populateFromNodeDB()
{
// Fill a collection with pointers to each node in db
std::vector<meshtastic_NodeInfoLite *> ordered;
for (auto mn = nodeDB->meshNodes->begin(); mn != nodeDB->meshNodes->end(); ++mn) {
// Only copy if valid, and not our own node
if (mn->num != 0 && mn->num != nodeDB->getNodeNum())
ordered.push_back(&*mn);
std::vector<const meshtastic_NodeInfoLite *> ordered;
uint32_t readIndex = 0;
const meshtastic_NodeInfoLite *node;
while ((node = nodeDB->readNextMeshNode(readIndex)) != nullptr) {
if (node->num != 0 && node->num != nodeDB->getNodeNum())
ordered.push_back(node);
}

// Sort the collection by age
std::sort(ordered.begin(), ordered.end(), [](meshtastic_NodeInfoLite *top, meshtastic_NodeInfoLite *bottom) -> bool {
return (top->last_heard > bottom->last_heard);
});
std::sort(ordered.begin(), ordered.end(),
[](const meshtastic_NodeInfoLite *top, const meshtastic_NodeInfoLite *bottom) -> bool {
return (top->last_heard > bottom->last_heard);
});

// Keep the most recent entries only
// Just enough to fill the screen
if (ordered.size() > maxCards())
ordered.resize(maxCards());

// Create card info for these (stale) node observations
meshtastic_NodeInfoLite *ourNode = nodeDB->getMeshNode(nodeDB->getNodeNum());
for (meshtastic_NodeInfoLite *node : ordered) {
const meshtastic_NodeInfoLite *ourNode = nodeDB->getMeshNode(nodeDB->getNodeNum());
for (const meshtastic_NodeInfoLite *node : ordered) {
CardInfo c;
c.nodeNum = node->num;

Expand Down
Loading