From d3589e293fb8d0403ca01dc4b61835511a516e45 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Sat, 23 May 2026 09:19:27 +0200 Subject: [PATCH] feat: sort DM contact list by message count (most messages first) Contacts with at least one message float to the top, ordered by total message count descending. Contacts with no messages keep their original relative order. Sorting is applied each time the message screen is opened (buildContactList), so the list always reflects the current session's activity. Co-Authored-By: Claude Sonnet 4.6 --- examples/companion_radio/ui-new/QuickMsgScreen.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples/companion_radio/ui-new/QuickMsgScreen.h b/examples/companion_radio/ui-new/QuickMsgScreen.h index 6febeba3..e0c5997f 100644 --- a/examples/companion_radio/ui-new/QuickMsgScreen.h +++ b/examples/companion_radio/ui-new/QuickMsgScreen.h @@ -266,6 +266,21 @@ class QuickMsgScreen : public UIScreen { if (!show_all && !(c.flags & 0x01)) continue; _sorted[_num_contacts++] = i; } + // Sort by message count descending; contacts with no messages keep original order. + int counts[MAX_CONTACTS]; + for (int i = 0; i < _num_contacts; i++) { + the_mesh.getContactByIdx(_sorted[i], c); + counts[i] = dmHistCountForContact(c.id.pub_key); + } + for (int i = 1; i < _num_contacts; i++) { + if (counts[i] == 0) continue; + uint16_t key = _sorted[i]; int kc = counts[i]; + int j = i; + while (j > 0 && counts[j-1] < kc) { + _sorted[j] = _sorted[j-1]; counts[j] = counts[j-1]; j--; + } + _sorted[j] = key; counts[j] = kc; + } } }