From 2163a4c56c022c618d2c70147d293eef611105be Mon Sep 17 00:00:00 2001 From: pelgraine <140762863+pelgraine@users.noreply.github.com> Date: Sun, 1 Mar 2026 08:01:47 +1100 Subject: [PATCH] sync new message message read or unread notification display better between device ui and ble app; keep in channel after message sent, moved sent toaster popup to in channel --- examples/companion_radio/AbstractUITask.h | 3 +++ examples/companion_radio/MyMesh.cpp | 14 +++++++++++++- examples/companion_radio/main.cpp | 4 ++-- .../companion_radio/ui-new/Repeateradminscreen.h | 6 +++--- examples/companion_radio/ui-new/UITask.cpp | 6 ++++++ examples/companion_radio/ui-new/UITask.h | 3 +++ 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/examples/companion_radio/AbstractUITask.h b/examples/companion_radio/AbstractUITask.h index dc01694..ca3edba 100644 --- a/examples/companion_radio/AbstractUITask.h +++ b/examples/companion_radio/AbstractUITask.h @@ -48,6 +48,9 @@ public: virtual void forceRefresh() {} virtual void addSentChannelMessage(uint8_t channel_idx, const char* sender, const char* text) {} + // Mark a channel as read when BLE companion app syncs a message + virtual void markChannelReadFromBLE(uint8_t channel_idx) {} + // Repeater admin callbacks (from MyMesh) virtual void onAdminLoginResult(bool success, uint8_t permissions, uint32_t server_time) {} virtual void onAdminCliResponse(const char* from_name, const char* text) {} diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 359bc7e..ca5282d 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -1410,7 +1410,19 @@ void MyMesh::handleCmdFrame(size_t len) { if ((out_len = getFromOfflineQueue(out_frame)) > 0) { _serial->writeFrame(out_frame, out_len); #ifdef DISPLAY_CLASS - if (_ui) _ui->msgRead(offline_queue_len); + if (_ui) { + _ui->msgRead(offline_queue_len); + + // Mark channel as read when BLE companion app syncs the message. + // Frame layout V3: [resp_code][snr][res1][res2][channel_idx][path_len]... + // Frame layout V1: [resp_code][channel_idx][path_len]... + bool is_v3_ch = (out_frame[0] == RESP_CODE_CHANNEL_MSG_RECV_V3); + bool is_old_ch = (out_frame[0] == RESP_CODE_CHANNEL_MSG_RECV); + if (is_v3_ch || is_old_ch) { + uint8_t ch_idx = is_v3_ch ? out_frame[4] : out_frame[1]; + _ui->markChannelReadFromBLE(ch_idx); + } + } #endif } else { out_frame[0] = RESP_CODE_NO_MORE_MESSAGES; diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index e5da075..7d729b3 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -1156,7 +1156,7 @@ void handleKeyboardInput() { if (wasDM) { ui_task.gotoContactsScreen(); } else { - ui_task.gotoHomeScreen(); + ui_task.gotoChannelScreen(); } return; } @@ -1176,7 +1176,7 @@ void handleKeyboardInput() { if (wasDM) { ui_task.gotoContactsScreen(); } else { - ui_task.gotoHomeScreen(); + ui_task.gotoChannelScreen(); } return; } diff --git a/examples/companion_radio/ui-new/Repeateradminscreen.h b/examples/companion_radio/ui-new/Repeateradminscreen.h index 184f500..b50fb34 100644 --- a/examples/companion_radio/ui-new/Repeateradminscreen.h +++ b/examples/companion_radio/ui-new/Repeateradminscreen.h @@ -5,7 +5,7 @@ #include // Forward declarations -class UITask; +#include "../AbstractUITask.h" class MyMesh; extern MyMesh the_mesh; @@ -165,7 +165,7 @@ public: }; private: - UITask* _task; + AbstractUITask* _task; mesh::RTCClock* _rtc; AdminState _state; @@ -421,7 +421,7 @@ private: } public: - RepeaterAdminScreen(UITask* task, mesh::RTCClock* rtc) + RepeaterAdminScreen(AbstractUITask* task, mesh::RTCClock* rtc) : _task(task), _rtc(rtc), _state(STATE_PASSWORD_ENTRY), _contactIdx(-1), _permissions(0), _serverTime(0), _pwdLen(0), _lastCharAt(0), diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 9d6f76b..8601c53 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -1486,6 +1486,12 @@ void UITask::addSentChannelMessage(uint8_t channel_idx, const char* sender, cons ((ChannelScreen *) channel_screen)->addMessage(channel_idx, 0, sender, formattedMsg); } +void UITask::markChannelReadFromBLE(uint8_t channel_idx) { + ((ChannelScreen *) channel_screen)->markChannelRead(channel_idx); + // Trigger a refresh so the home screen unread count updates in real-time + _next_refresh = millis() + 200; +} + void UITask::gotoRepeaterAdmin(int contactIdx) { // Lazy-initialize on first use (same pattern as audiobook player) if (repeater_admin == nullptr) { diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index b0ff41b..de45563 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -155,6 +155,9 @@ public: // Add a sent message to the channel screen history void addSentChannelMessage(uint8_t channel_idx, const char* sender, const char* text) override; + // Mark channel as read when BLE companion app syncs messages + void markChannelReadFromBLE(uint8_t channel_idx) override; + // Repeater admin callbacks void onAdminLoginResult(bool success, uint8_t permissions, uint32_t server_time) override; void onAdminCliResponse(const char* from_name, const char* text) override;