mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-06-28 12:09:30 +00:00
- Core returns `InboundResult` — a typed struct with an optional `NewConversation` and a `FrameOutcome` of decrypted messages. - Client surfaces app-facing events via `Vec<Event>`, translated from `InboundResult` at the boundary. - MLS group welcomes now produce a `ConversationStarted` event with no initial content, fixing the silent-group-join case where the inbox layer dropped the observation. - C FFI exposes an `EventList` opaque type with indexed accessors and an `Invalid` sentinel for OOB / non-applicable reads. - Symmetric `Inbox` / `InboxV2` handlers: both return `Result<InboundResult, _>` and own the persistence + ephemeral-key cleanup for the conversations they create. - Updated and simplified `docs/adr/0001-client-event-system.md`.
42 lines
1.4 KiB
Rust
42 lines
1.4 KiB
Rust
use logos_chat::{ChatClient, ConversationIdOwned, Event, InProcessDelivery};
|
|
use std::sync::Arc;
|
|
|
|
fn main() {
|
|
let delivery = InProcessDelivery::new(Default::default());
|
|
let mut cursor = delivery.cursor_at_tail("delivery_address");
|
|
|
|
let mut saro = ChatClient::new("saro", delivery.clone());
|
|
let mut raya = ChatClient::new("raya", delivery);
|
|
|
|
let raya_bundle = raya.create_intro_bundle().unwrap();
|
|
saro.create_conversation(&raya_bundle, b"hello raya")
|
|
.unwrap();
|
|
|
|
let raw = cursor.next().unwrap();
|
|
let events = raya.receive(&raw).unwrap();
|
|
let raya_convo_id: ConversationIdOwned = events
|
|
.iter()
|
|
.find_map(|e| match e {
|
|
Event::ConversationStarted { convo_id, .. } => Some(Arc::clone(convo_id)),
|
|
_ => None,
|
|
})
|
|
.expect("expected ConversationStarted");
|
|
for event in &events {
|
|
if let Event::MessageReceived { content, .. } = event {
|
|
println!("Raya received: {:?}", std::str::from_utf8(content).unwrap());
|
|
}
|
|
}
|
|
|
|
raya.send_message(&raya_convo_id, b"hi saro").unwrap();
|
|
|
|
let raw = cursor.next().unwrap();
|
|
let events = saro.receive(&raw).unwrap();
|
|
for event in &events {
|
|
if let Event::MessageReceived { content, .. } = event {
|
|
println!("Saro received: {:?}", std::str::from_utf8(content).unwrap());
|
|
}
|
|
}
|
|
|
|
println!("Message exchange complete.");
|
|
}
|