Radix Relay
Hybrid mesh communications with Signal Protocol encryption
Loading...
Searching...
No Matches
display_filter.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <core/events.hpp>
5#include <memory>
6#include <optional>
7#include <string>
8#include <variant>
9
10namespace radix_relay::core {
11
26{
27 // Type traits for standard_processor
29
31 {
32 std::shared_ptr<async::async_queue<events::ui_event_t>> ui;
33 };
34
40 explicit display_filter(const out_queues_t &queues) : ui_queue_(queues.ui) {}
41
47 auto handle(const events::display_filter_input_t &input) const -> void
48 {
49 std::visit([this](const auto &evt) { this->handle(evt); }, input);
50 }
51
57 auto handle(const events::enter_chat_mode &evt) const -> void
58 {
59 active_chat_rdx_ = evt.rdx_fingerprint;
60 ui_queue_->push(evt);
61 }
62
68 auto handle(const events::exit_chat_mode &evt) const -> void
69 {
70 active_chat_rdx_.reset();
71 ui_queue_->push(evt);
72 }
73
79 auto handle(const events::display_message &msg) const -> void
80 {
81 // System messages and command feedback always pass through
82 if (msg.source_type == events::display_message::source::system
84 ui_queue_->push(msg);
85 return;
86 }
87
88 // Not in chat mode: pass everything through
89 if (not active_chat_rdx_.has_value()) {
90 ui_queue_->push(msg);
91 return;
92 }
93
94 // In chat mode: only pass messages associated with active contact
95 if (msg.contact_rdx.has_value() and msg.contact_rdx.value() == active_chat_rdx_.value()) { ui_queue_->push(msg); }
96 // Messages not matching active contact are discarded (already stored in history)
97 }
98
99private:
100 std::shared_ptr<async::async_queue<events::ui_event_t>> ui_queue_;
101
102 // Chat context state (only accessed by this processor's thread, no mutex needed)
103 mutable std::optional<std::string> active_chat_rdx_;
104};
105
106}// namespace radix_relay::core
std::variant< display_message, enter_chat_mode, exit_chat_mode > display_filter_input_t
Display filter input: either a display message or control event.
Definition events.hpp:410
std::shared_ptr< async::async_queue< events::ui_event_t > > ui
Filters display messages based on active chat context.
auto handle(const events::exit_chat_mode &evt) const -> void
Handles exiting chat mode.
auto handle(const events::display_message &msg) const -> void
Handles a display message, filtering based on chat context.
auto handle(const events::display_filter_input_t &input) const -> void
Variant handler for standard_processor.
display_filter(const out_queues_t &queues)
Constructs a display filter with the given output queue.
auto handle(const events::enter_chat_mode &evt) const -> void
Handles entering chat mode.
Request to display a message to the user.
Definition events.hpp:381
Enter chat mode with specified contact.
Definition events.hpp:399
Exit chat mode, return to showing all messages.
Definition events.hpp:406