mirror of
https://github.com/torlando-tech/pyxis.git
synced 2026-10-15 10:39:59 +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
200 lines
6.1 KiB
C++
200 lines
6.1 KiB
C++
// Copyright (c) 2024 microReticulum contributors
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#ifndef UI_LXMF_CHATSCREEN_H
|
|
#define UI_LXMF_CHATSCREEN_H
|
|
|
|
#ifdef ARDUINO
|
|
#include <Arduino.h>
|
|
#include <lvgl.h>
|
|
#include <vector>
|
|
#include <deque>
|
|
#include <map>
|
|
#include <functional>
|
|
#include <microReticulum/Bytes.h>
|
|
#include "LXMF/LXMessage.h"
|
|
#include "LXMF/MessageStore.h"
|
|
|
|
namespace UI {
|
|
namespace LXMF {
|
|
|
|
/**
|
|
* Chat Screen
|
|
*
|
|
* Shows messages in a conversation with:
|
|
* - Scrollable message list
|
|
* - Message bubbles (incoming/outgoing styled differently)
|
|
* - Delivery status indicators (✓ sent, ✓✓ delivered)
|
|
* - Message input area
|
|
* - Send button
|
|
*
|
|
* Layout:
|
|
* ┌─────────────────────────────────────┐
|
|
* │ ← Alice (a1b2c3d4...) │ 32px Header
|
|
* ├─────────────────────────────────────┤
|
|
* │ [Hey there!] │ Outgoing (right)
|
|
* │ [10:23 AM ✓] │
|
|
* │ [How are you doing?] │ Incoming (left)
|
|
* │ [10:25 AM] │ 156px scrollable
|
|
* │ [I'm good, thanks!] │
|
|
* │ [10:26 AM ✓✓] │
|
|
* ├─────────────────────────────────────┤
|
|
* │ [Type message... ] [Send] │ 52px Input area
|
|
* └─────────────────────────────────────┘
|
|
*/
|
|
class ChatScreen {
|
|
public:
|
|
/**
|
|
* Message item data
|
|
*/
|
|
struct MessageItem {
|
|
RNS::Bytes message_hash;
|
|
String content;
|
|
char timestamp_str[16]; // "12:34 PM" format - fixed buffer to avoid fragmentation
|
|
bool outgoing; // true if sent by us
|
|
bool delivered; // true if delivery confirmed
|
|
bool failed; // true if delivery failed
|
|
};
|
|
|
|
/**
|
|
* Callback types
|
|
*/
|
|
using BackCallback = std::function<void()>;
|
|
using SendMessageCallback = std::function<void(const String& content)>;
|
|
using CallCallback = std::function<void()>;
|
|
|
|
/**
|
|
* Create chat screen
|
|
* @param parent Parent LVGL object (usually lv_scr_act())
|
|
*/
|
|
ChatScreen(lv_obj_t* parent = nullptr);
|
|
|
|
/**
|
|
* Destructor
|
|
*/
|
|
~ChatScreen();
|
|
|
|
/**
|
|
* Load conversation with a specific peer
|
|
* @param peer_hash Peer destination hash
|
|
* @param store Message store to load from
|
|
*/
|
|
void load_conversation(const RNS::Bytes& peer_hash, ::LXMF::MessageStore& store);
|
|
|
|
/**
|
|
* Add a new message to the chat
|
|
* @param message LXMF message to add
|
|
* @param outgoing true if message is outgoing
|
|
*/
|
|
void add_message(const ::LXMF::LXMessage& message, bool outgoing);
|
|
|
|
/**
|
|
* Update delivery status of a message
|
|
* @param message_hash Hash of message to update
|
|
* @param delivered true if delivered, false if failed
|
|
*/
|
|
void update_message_status(const RNS::Bytes& message_hash, bool delivered);
|
|
|
|
/**
|
|
* Refresh message list (reload from store)
|
|
*/
|
|
void refresh();
|
|
|
|
/**
|
|
* Set callback for back button
|
|
* @param callback Function to call when back button is pressed
|
|
*/
|
|
void set_back_callback(BackCallback callback);
|
|
|
|
/**
|
|
* Set callback for sending messages
|
|
* @param callback Function to call when send button is pressed
|
|
*/
|
|
void set_send_message_callback(SendMessageCallback callback);
|
|
|
|
/**
|
|
* Set callback for voice call button
|
|
* @param callback Function to call when call button is pressed
|
|
*/
|
|
void set_call_callback(CallCallback callback);
|
|
|
|
/**
|
|
* Show the screen
|
|
*/
|
|
void show();
|
|
|
|
/**
|
|
* Hide the screen
|
|
*/
|
|
void hide();
|
|
|
|
/**
|
|
* Get the root LVGL object
|
|
* @return Root object
|
|
*/
|
|
lv_obj_t* get_object();
|
|
|
|
private:
|
|
lv_obj_t* _screen;
|
|
lv_obj_t* _header;
|
|
lv_obj_t* _message_list;
|
|
lv_obj_t* _input_area;
|
|
lv_obj_t* _text_area;
|
|
lv_obj_t* _btn_send;
|
|
lv_obj_t* _btn_back;
|
|
lv_obj_t* _btn_call;
|
|
|
|
RNS::Bytes _peer_hash;
|
|
::LXMF::MessageStore* _message_store;
|
|
std::deque<MessageItem> _messages;
|
|
|
|
// Map message hash to bubble row for targeted updates
|
|
std::map<RNS::Bytes, lv_obj_t*> _message_rows;
|
|
|
|
BackCallback _back_callback;
|
|
SendMessageCallback _send_message_callback;
|
|
CallCallback _call_callback;
|
|
|
|
// UI construction
|
|
void create_header();
|
|
void create_message_list();
|
|
void create_input_area();
|
|
void create_message_bubble(const MessageItem& item);
|
|
|
|
// Event handlers
|
|
static void on_back_clicked(lv_event_t* event);
|
|
static void on_call_clicked(lv_event_t* event);
|
|
static void on_send_clicked(lv_event_t* event);
|
|
static void on_message_long_pressed(lv_event_t* event);
|
|
static void on_copy_dialog_action(lv_event_t* event);
|
|
static void on_textarea_long_pressed(lv_event_t* event);
|
|
static void on_paste_dialog_action(lv_event_t* event);
|
|
|
|
// Copy/paste state
|
|
String _pending_copy_text;
|
|
|
|
// Pagination state for infinite scroll
|
|
std::vector<RNS::Bytes> _all_message_hashes; // All message hashes in conversation
|
|
size_t _display_start_idx; // Index into _all_message_hashes where display starts
|
|
static constexpr size_t MESSAGES_PER_PAGE = 20;
|
|
static constexpr size_t MAX_DISPLAYED_MESSAGES = 50; // Cap to prevent memory exhaustion
|
|
bool _loading_more; // Prevent concurrent loads
|
|
|
|
// Load more messages (for infinite scroll)
|
|
void load_more_messages();
|
|
static void on_scroll(lv_event_t* event);
|
|
|
|
// Utility
|
|
static void format_timestamp(double timestamp, char* buf, size_t buf_size);
|
|
static const char* get_delivery_indicator(bool outgoing, bool delivered, bool failed);
|
|
static String parse_display_name(const RNS::Bytes& app_data);
|
|
static void build_status_text(char* buf, size_t buf_size, const char* timestamp,
|
|
bool outgoing, bool delivered, bool failed);
|
|
};
|
|
|
|
} // namespace LXMF
|
|
} // namespace UI
|
|
|
|
#endif // ARDUINO
|
|
#endif // UI_LXMF_CHATSCREEN_H
|