fix(companion): pack and history files from the card checked, contact loops skip the reserved slots, small UI fixes

- L2 vector packs: a damaged count can't wrap the index size, and an
  entry pointing past the file is refused.
- L2 map share-target list: sized for 40 long channel names and 16
  favourites (it could overflow), off the stack.
- L2 SD history: a file with an unreadable header is set aside as .bad
  instead of written over; Delete message history takes those too.
- Contact lookups by key or hash start after the reserved anon slots (an
  empty one matched a 00 hop hash with a blank name); MessagesScreen uses
  contactctl::hopName().
- Nearby keeps its selection by public key: deleting a contact shifts
  the table.
- ui-new Live Share target cycle holds every channel and favourite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-10-12 18:31:35 +02:00
co-authored by Claude Opus 5.5
parent 4eee794a17
commit 57db27512d
10 changed files with 51 additions and 41 deletions
@@ -90,7 +90,9 @@ inline uint8_t hopCount(uint8_t path_len_packed) {
inline void hopName(uint8_t path_len_packed, const uint8_t* path, int i, char* out, size_t n) {
uint8_t hash_size = (path_len_packed >> 6) + 1;
const uint8_t* hash = &path[i * hash_size];
for (int idx = 0; ; idx++) {
// From MAX_ANON_CONTACTS: the reserved slots before it are empty or anon
// requesters, and an empty one matched a 00 hash with a blank name.
for (int idx = MAX_ANON_CONTACTS; ; idx++) {
ContactInfo c;
if (!the_mesh.getContactByIdx(idx, c)) break;
if (c.id.isHashMatch(hash, hash_size)) { snprintf(out, n, "%s", c.name); return; }
@@ -173,10 +173,12 @@ public:
void refreshModel() { if (_source == SRC_SCAN) refreshScan(); else refreshStored(); }
// Index of the row for raw contact index `contact_idx`, or of the non-contact
// live row named `name` -- how a screen keeps its selection across a rebuild.
int findContact(int contact_idx) const {
for (int i = 0; i < _count; i++) if (_entries[i].contact_idx == contact_idx) return i;
// Index of the contact row with this public key, or of the non-contact live
// row named `name` -- how a screen keeps its selection across a rebuild. By
// key, not by contact index: deleting a contact shifts the table down.
int findContact(const uint8_t* pub_key) const {
for (int i = 0; i < _count; i++)
if (_entries[i].contact_idx >= 0 && memcmp(_entries[i].pub_key, pub_key, PUB_KEY_SIZE) == 0) return i;
return -1;
}
int findLiveByName(const char* name) const {