Radix Relay
Hybrid mesh communications with Signal Protocol encryption
Loading...
Searching...
No Matches
presentation_handler.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <core/events.hpp>
5#include <fmt/core.h>
6#include <memory>
8#include <spdlog/spdlog.h>
9#include <variant>
10
11namespace radix_relay::core {
12
20{
21 // Type traits for standard_processor
23
25 {
26 std::shared_ptr<async::async_queue<events::display_filter_input_t>> display;
27 };
28
34 explicit presentation_handler(const out_queues_t &queues) : display_out_queue_(queues.display) {}
35
41 auto handle(const events::presentation_event_variant_t &event) const -> void
42 {
43 std::visit([this](const auto &evt) { this->handle(evt); }, event);
44 }
45
51 auto handle(const events::message_received &evt) const -> void
52 {
53 const auto &sender_display = evt.sender_alias.empty() ? evt.sender_rdx : evt.sender_alias;
55 evt.sender_rdx,
56 evt.timestamp,
57 "Message from {}: {}\n",
58 sender_display,
59 evt.content);
60 }
61
67 auto handle(const events::session_established &evt) const -> void
68 {
70 evt.peer_rdx,
72 "Encrypted session established with {}\n",
73 evt.peer_rdx);
74 }
75
81 static auto handle(const events::bundle_announcement_received &evt) -> void
82 {
83 spdlog::debug("Received bundle announcement from {}", evt.pubkey);
84 }
85
91 static auto handle(const events::bundle_announcement_removed &evt) -> void
92 {
93 spdlog::debug("Bundle announcement removed for {}", evt.pubkey);
94 }
95
101 auto handle(const events::message_sent &evt) const -> void
102 {
103 const auto timestamp = platform::current_timestamp_ms();
104 if (evt.accepted) {
105 emit(events::display_message::source::outgoing_message, evt.peer, timestamp, "Message sent to {}\n", evt.peer);
106 } else {
108 evt.peer,
109 timestamp,
110 "Failed to send message to {}\n",
111 evt.peer);
112 }
113 }
114
120 auto handle(const events::bundle_published &evt) const -> void
121 {
122 const auto timestamp = platform::current_timestamp_ms();
123 if (evt.accepted) {
125 std::nullopt,
126 timestamp,
127 "Identity bundle published (event: {})\n",
128 evt.event_id);
129 } else {
131 std::nullopt,
132 timestamp,
133 "Failed to publish identity bundle\n");
134 }
135 }
136
142 static auto handle(const events::subscription_established &evt) -> void
143 {
144 spdlog::debug("Subscription established: {}", evt.subscription_id);
145 }
146
152 auto handle(const events::identities_listed &evt) const -> void
153 {
154 const auto timestamp = platform::current_timestamp_ms();
155 if (evt.identities.empty()) {
156 emit(events::display_message::source::system, std::nullopt, timestamp, "No identities discovered yet\n");
157 } else {
158 emit(events::display_message::source::system, std::nullopt, timestamp, "Discovered identities:\n");
159 for (const auto &identity : evt.identities) {
161 std::nullopt,
162 timestamp,
163 " {} (nostr: {})\n",
164 identity.rdx_fingerprint,
165 identity.nostr_pubkey);
166 }
167 }
168 }
169
170private:
171 std::shared_ptr<async::async_queue<events::display_filter_input_t>> display_out_queue_;
172
173 template<typename... Args>
174 auto emit(events::display_message::source source_type,
175 std::optional<std::string> contact_rdx,
176 std::uint64_t timestamp,
177 fmt::format_string<Args...> format_string,
178 Args &&...args) const -> void
179 {
180 display_out_queue_->push(
181 events::display_message{ .message = fmt::format(format_string, std::forward<Args>(args)...),
182 .contact_rdx = std::move(contact_rdx),
183 .timestamp = timestamp,
184 .source_type = source_type });
185 }
186};
187
188}// namespace radix_relay::core
Thread-safe asynchronous queue for message passing between coroutines.
std::variant< message_received, session_established, bundle_announcement_received, bundle_announcement_removed, message_sent, bundle_published, subscription_established, identities_listed > presentation_event_variant_t
Variant type for presentation events.
Definition events.hpp:333
auto current_timestamp_ms() -> std::uint64_t
Gets current timestamp in milliseconds since Unix epoch.
Notification of received bundle announcement.
Definition events.hpp:158
Notification of removed bundle announcement.
Definition events.hpp:166
Notification of published bundle status.
Definition events.hpp:200
Request to display a message to the user.
Definition events.hpp:375
@ incoming_message
Received message from contact.
std::string message
Message content to display.
Definition events.hpp:385
Response containing discovered identities.
Definition events.hpp:186
Notification of received encrypted message.
Definition events.hpp:142
Notification of sent message status.
Definition events.hpp:192
Notification of successfully established session.
Definition events.hpp:152
Notification of established subscription.
Definition events.hpp:207
std::shared_ptr< async::async_queue< events::display_filter_input_t > > display
Handles presentation events and generates user-facing messages.
auto handle(const events::bundle_published &evt) const -> void
Handles a bundle published event.
auto handle(const events::presentation_event_variant_t &event) const -> void
Variant handler for standard_processor.
presentation_handler(const out_queues_t &queues)
Constructs a presentation handler.
auto handle(const events::identities_listed &evt) const -> void
Handles an identities listed event.
auto handle(const events::message_received &evt) const -> void
Handles a received encrypted message event.
static auto handle(const events::bundle_announcement_received &evt) -> void
Handles a bundle announcement received event.
static auto handle(const events::subscription_established &evt) -> void
Handles a subscription established event.
auto handle(const events::session_established &evt) const -> void
Handles a session established event.
auto handle(const events::message_sent &evt) const -> void
Handles a message sent event.
static auto handle(const events::bundle_announcement_removed &evt) -> void
Handles a bundle announcement removed event.