mirror of
https://github.com/torlando-tech/pyxis.git
synced 2026-08-05 10:20:07 +00:00
Repins microReticulum + microLXMF onto the upstream-0.4.1 graft and adapts pyxis to the new src/microReticulum/ layout and 0.4.x APIs. The far-diverged 0.3.0 fork's Resource/Transport/Identity work is subsumed by upstream's reimplementation; only the still-needed fixes ride on the pinned branches (PKCS7/HMAC/X25519 crypto -- proven byte-identical to python RNS 1.3.1 -- Packet link-proof callback, Identity short-sig guard, and the bz2 layer + decompress-on-receive in Resource::assemble()). Consumer-side changes: - platformio.ini: pin microReticulum @2f21fee (pyxis-fixes-on-0.4.1) and microLXMF @33760d0 (chore/microreticulum-0.4.1-layout); bump microStore ceea8f5 -> c5fb69d (0.4.x requires the new BasicFileStore::init API); -std=gnu++11 -> gnu++17 (upstream requires C++17). - Namespace all microReticulum includes (angle + quote) to <microReticulum/...> for the relocated layout; shim-local Utilities/Stream.h|Print.h preserved. - Interface::send_outgoing now returns bool: update TCP/BLE/SX1262/Auto overrides with correct success/failure returns. - SDArchiveFileSystem::init(bool reformatOnFail=true) to match new microStore. - Static Transport::get_path_table() -> path_table(); instance getter unchanged. - Remove duplicate shim Cryptography/BZ2 (microReticulum provides it now; keep lib/libbz2 as the ESP32 bzlib provider). - patch_littlefs_paths.py: normalize microStore's LittleFS adapter paths to a leading "/" -- ESP32 Arduino LittleFS rejects "./"-prefixed paths, which silently broke the path store (no peer paths learned, all messaging blocked). Validated on T-Deck Plus: builds (RAM 27.5% / Flash 77.7%), boots stable (no WDT/panic), and a full on-device LXMF e2e (DIRECT + OPPORTUNISTIC + bz2-compressed-Resource receive) passes 5/5. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWZuYkHBRqNb6BZHV8sTG5
267 lines
8.7 KiB
C++
267 lines
8.7 KiB
C++
// Copyright (c) 2024 microReticulum contributors
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#ifndef UI_LXMF_CONVERSATIONLISTSCREEN_H
|
|
#define UI_LXMF_CONVERSATIONLISTSCREEN_H
|
|
|
|
#ifdef ARDUINO
|
|
#include <Arduino.h>
|
|
#include <lvgl.h>
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <microReticulum/Bytes.h>
|
|
#include "LXMF/MessageStore.h"
|
|
#include <microReticulum/Interface.h>
|
|
|
|
// TinyGPS++ pulled in for TinyGPSCustom (the in-view-satellites parser
|
|
// hook; declared as a member below). The forward decl on TinyGPSPlus
|
|
// stays since the field is a pointer.
|
|
#include <TinyGPS++.h>
|
|
|
|
class TinyGPSPlus; // Forward declaration
|
|
|
|
namespace UI {
|
|
namespace LXMF {
|
|
|
|
/**
|
|
* Conversation List Screen
|
|
*
|
|
* Shows a scrollable list of all LXMF conversations with:
|
|
* - Peer name/hash (truncated)
|
|
* - Last message preview
|
|
* - Timestamp
|
|
* - Unread count indicator
|
|
* - Navigation buttons (New message, Settings)
|
|
*
|
|
* Layout:
|
|
* ┌─────────────────────────────────────┐
|
|
* │ LXMF Messages [New] [☰] │ 32px header
|
|
* ├─────────────────────────────────────┤
|
|
* │ ┌─ Alice (a1b2c3...) │
|
|
* │ │ Hey, how are you? │
|
|
* │ │ 2 hours ago [2] │ Unread count
|
|
* │ └─ │
|
|
* │ ┌─ Bob (d4e5f6...) │ 176px scrollable
|
|
* │ │ See you tomorrow! │
|
|
* │ │ Yesterday │
|
|
* │ └─ │
|
|
* ├─────────────────────────────────────┤
|
|
* │ [💬] [👤] [📡] [⚙️] │ 32px bottom nav
|
|
* └─────────────────────────────────────┘
|
|
*/
|
|
class ConversationListScreen {
|
|
public:
|
|
/**
|
|
* Conversation item data
|
|
*/
|
|
struct ConversationItem {
|
|
RNS::Bytes peer_hash;
|
|
String peer_name; // Or truncated hash if no name
|
|
String last_message; // Preview of last message
|
|
String timestamp_str; // Human-readable time
|
|
uint32_t timestamp; // Unix timestamp
|
|
uint16_t unread_count;
|
|
};
|
|
|
|
/**
|
|
* Callback types
|
|
*/
|
|
using ConversationSelectedCallback = std::function<void(const RNS::Bytes& peer_hash)>;
|
|
using ComposeCallback = std::function<void()>;
|
|
using SyncCallback = std::function<void()>;
|
|
using SettingsCallback = std::function<void()>;
|
|
using AnnouncesCallback = std::function<void()>;
|
|
using StatusCallback = std::function<void()>;
|
|
|
|
/**
|
|
* Create conversation list screen
|
|
* @param parent Parent LVGL object (usually lv_scr_act())
|
|
*/
|
|
ConversationListScreen(lv_obj_t* parent = nullptr);
|
|
|
|
/**
|
|
* Destructor
|
|
*/
|
|
~ConversationListScreen();
|
|
|
|
/**
|
|
* Load conversations from message store
|
|
* @param store Message store to load from
|
|
*/
|
|
void load_conversations(::LXMF::MessageStore& store);
|
|
|
|
/**
|
|
* Refresh conversation list (reload from store)
|
|
*/
|
|
void refresh();
|
|
|
|
// Flush display-name write-throughs deferred by refresh(). MUST be called
|
|
// OUTSIDE the LVGL lock (UIManager::update() calls it before taking the
|
|
// lock) — set_display_name() hits microStore/LittleFS.
|
|
void flush_pending_name_writes();
|
|
|
|
/**
|
|
* Update unread count for a specific conversation
|
|
* @param peer_hash Peer hash
|
|
* @param unread_count New unread count
|
|
*/
|
|
void update_unread_count(const RNS::Bytes& peer_hash, uint16_t unread_count);
|
|
|
|
/**
|
|
* Set callback for conversation selection
|
|
* @param callback Function to call when conversation is selected
|
|
*/
|
|
void set_conversation_selected_callback(ConversationSelectedCallback callback);
|
|
|
|
/**
|
|
* Set callback for compose (envelope icon in bottom nav)
|
|
* @param callback Function to call when compose is requested
|
|
*/
|
|
void set_compose_callback(ComposeCallback callback);
|
|
|
|
/**
|
|
* Set callback for sync button
|
|
* @param callback Function to call when sync button is pressed
|
|
*/
|
|
void set_sync_callback(SyncCallback callback);
|
|
|
|
/**
|
|
* Set callback for settings button
|
|
* @param callback Function to call when settings button is pressed
|
|
*/
|
|
void set_settings_callback(SettingsCallback callback);
|
|
|
|
/**
|
|
* Set callback for announces button
|
|
* @param callback Function to call when announces button is pressed
|
|
*/
|
|
void set_announces_callback(AnnouncesCallback callback);
|
|
|
|
/**
|
|
* Set callback for status button
|
|
* @param callback Function to call when status button is pressed
|
|
*/
|
|
void set_status_callback(StatusCallback callback);
|
|
|
|
/**
|
|
* Show the screen
|
|
*/
|
|
void show();
|
|
|
|
/**
|
|
* Hide the screen
|
|
*/
|
|
void hide();
|
|
|
|
/**
|
|
* Get the root LVGL object
|
|
* @return Root object
|
|
*/
|
|
lv_obj_t* get_object();
|
|
|
|
/**
|
|
* Update status indicators (WiFi RSSI, LoRa RSSI, and battery)
|
|
* Call periodically from main loop
|
|
*/
|
|
void update_status();
|
|
|
|
/**
|
|
* Set LoRa interface for RSSI display
|
|
* @param iface LoRa interface implementation
|
|
*/
|
|
void set_lora_interface(RNS::Interface* iface) { _lora_interface = iface; }
|
|
|
|
/**
|
|
* Set BLE interface for connection count display
|
|
* @param iface BLE interface implementation
|
|
*/
|
|
void set_ble_interface(RNS::Interface* iface) { _ble_interface = iface; }
|
|
|
|
/**
|
|
* Set GPS for satellite count display
|
|
*
|
|
* Also binds a custom $GPGSV field-3 ("satellites in view") parser
|
|
* to the same TinyGPSPlus instance so the top bar can show
|
|
* "in-view but not yet locked" status (yellow "?N") before the
|
|
* fix has any locked satellites.
|
|
*
|
|
* @param gps TinyGPSPlus instance
|
|
*/
|
|
void set_gps(TinyGPSPlus* gps) {
|
|
_gps = gps;
|
|
if (gps) {
|
|
// GSV sentence: $GPGSV,<total_sentences>,<sentence_num>,
|
|
// <total_in_view>,<sat1_id>,...
|
|
// Field 3 is the count of satellites visible to the receiver.
|
|
_gps_in_view.begin(*gps, "GPGSV", 3);
|
|
}
|
|
}
|
|
|
|
private:
|
|
lv_obj_t* _screen;
|
|
lv_obj_t* _header;
|
|
lv_obj_t* _list;
|
|
lv_obj_t* _bottom_nav;
|
|
lv_obj_t* _btn_new;
|
|
lv_obj_t* _btn_settings;
|
|
lv_obj_t* _label_wifi;
|
|
lv_obj_t* _label_lora;
|
|
lv_obj_t* _label_gps;
|
|
lv_obj_t* _label_ble;
|
|
lv_obj_t* _battery_container;
|
|
lv_obj_t* _label_battery_icon;
|
|
lv_obj_t* _label_battery_pct;
|
|
|
|
RNS::Interface* _lora_interface;
|
|
RNS::Interface* _ble_interface;
|
|
TinyGPSPlus* _gps;
|
|
TinyGPSCustom _gps_in_view; // $GPGSV field 3 — satellites in view
|
|
|
|
::LXMF::MessageStore* _message_store;
|
|
std::vector<ConversationItem> _conversations;
|
|
std::vector<lv_obj_t*> _conversation_containers; // For focus group management
|
|
std::vector<RNS::Bytes> _peer_hash_pool; // Object pool to avoid per-item allocations
|
|
RNS::Bytes _pending_delete_hash; // Hash of conversation pending deletion
|
|
bool _has_unresolved_names = false; // True if any conversation shows hash instead of name
|
|
// Display-name write-throughs deferred out of refresh() (which runs under
|
|
// the LVGL lock). set_display_name() hits microStore/LittleFS; doing it
|
|
// under the lock stalls the render task on a cold-boot announce burst.
|
|
// Drained by UIManager::update() before it takes the lock.
|
|
std::vector<std::pair<RNS::Bytes, std::string>> _pending_name_writes;
|
|
|
|
ConversationSelectedCallback _conversation_selected_callback;
|
|
ComposeCallback _compose_callback;
|
|
SyncCallback _sync_callback;
|
|
SettingsCallback _settings_callback;
|
|
AnnouncesCallback _announces_callback;
|
|
StatusCallback _status_callback;
|
|
|
|
// UI construction
|
|
void create_header();
|
|
void create_list();
|
|
void create_bottom_nav();
|
|
void create_conversation_item(const ConversationItem& item);
|
|
|
|
// Event handlers
|
|
static void on_conversation_clicked(lv_event_t* event);
|
|
static void on_conversation_long_pressed(lv_event_t* event);
|
|
static void on_delete_confirmed(lv_event_t* event);
|
|
static void on_sync_clicked(lv_event_t* event);
|
|
static void on_settings_clicked(lv_event_t* event);
|
|
static void on_bottom_nav_clicked(lv_event_t* event);
|
|
static void msgbox_close_cb(lv_event_t* event);
|
|
|
|
// Utility
|
|
static String format_timestamp(uint32_t timestamp);
|
|
static String truncate_hash(const RNS::Bytes& hash);
|
|
static String parse_display_name(const RNS::Bytes& app_data);
|
|
};
|
|
|
|
} // namespace LXMF
|
|
} // namespace UI
|
|
|
|
#endif // ARDUINO
|
|
#endif // UI_LXMF_CONVERSATIONLISTSCREEN_H
|