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::display_message>> filtered;
33 };
34
40 explicit display_filter(const out_queues_t &queues) : filtered_queue_(queues.filtered) {}
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 { active_chat_rdx_ = evt.rdx_fingerprint; }
58
64 auto handle(const events::exit_chat_mode & /*evt*/) const -> void { active_chat_rdx_.reset(); }
65
71 auto handle(const events::display_message &msg) const -> void
72 {
73 // System messages and command feedback always pass through
74 if (msg.source_type == events::display_message::source::system
76 filtered_queue_->push(msg);
77 return;
78 }
79
80 // Not in chat mode: pass everything through
81 if (not active_chat_rdx_.has_value()) {
82 filtered_queue_->push(msg);
83 return;
84 }
85
86 // In chat mode: only pass messages associated with active contact
87 if (msg.contact_rdx.has_value() and msg.contact_rdx.value() == active_chat_rdx_.value()) {
88 filtered_queue_->push(msg);
89 }
90 // Messages not matching active contact are discarded (already stored in history)
91 }
92
93private:
94 std::shared_ptr<async::async_queue<events::display_message>> filtered_queue_;
95
96 // Chat context state (only accessed by this processor's thread, no mutex needed)
97 mutable std::optional<std::string> active_chat_rdx_;
98};
99
100}// 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:403
std::shared_ptr< async::async_queue< events::display_message > > filtered
Filters display messages based on active chat context.
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::exit_chat_mode &) const -> void
Handles exiting chat mode.
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:375
Enter chat mode with specified contact.
Definition events.hpp:393
Exit chat mode, return to showing all messages.
Definition events.hpp:399