diff --git a/Cargo.lock b/Cargo.lock index d5c8689..5a1c753 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -364,6 +364,7 @@ name = "client" version = "0.1.0" dependencies = [ "chat-sqlite", + "components", "libchat", "tempfile", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 9fb2e90..3d6a969 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,12 +22,15 @@ default-members = [ "core/double-ratchets", "core/storage", "core/integration_tests_core", + "crates/client", + "crates/client-ffi", ] [workspace.dependencies] blake2 = "0.10" - crypto = { path = "core/crypto" } + crypto = { path = "core/crypto" } libchat = { path = "core/conversations" } + logoschat_components = {package="components", path ="extensions/components"} sqlite = { path = "core/sqlite"} storage = { path = "core/storage" } diff --git a/core/conversations/src/context.rs b/core/conversations/src/context.rs index fef0bf4..b9a79cd 100644 --- a/core/conversations/src/context.rs +++ b/core/conversations/src/context.rs @@ -78,7 +78,7 @@ where .map_err(ChatError::generic)?; Ok(Self { - identity: identity, + identity, ds, store, inbox, @@ -319,7 +319,6 @@ where } } - #[allow(unused)] // Temporary until GroupIntegration is completed fn load_group_convo( &mut self, convo_id: ConversationId, diff --git a/core/conversations/src/conversation/group_v1.rs b/core/conversations/src/conversation/group_v1.rs index b3e461f..e3e1fbd 100644 --- a/core/conversations/src/conversation/group_v1.rs +++ b/core/conversations/src/conversation/group_v1.rs @@ -172,9 +172,9 @@ where } fn subscribe(ds: &mut DS, convo_id: &str) -> Result<(), ChatError> { - ds.subscribe(&Self::delivery_address_from_id(&convo_id)) + ds.subscribe(&Self::delivery_address_from_id(convo_id)) .map_err(ChatError::generic)?; - ds.subscribe(&Self::ctrl_delivery_address_from_id(&convo_id)) + ds.subscribe(&Self::ctrl_delivery_address_from_id(convo_id)) .map_err(ChatError::generic)?; Ok(()) diff --git a/core/conversations/src/inbox_v2.rs b/core/conversations/src/inbox_v2.rs index 7413c22..c40ff6f 100644 --- a/core/conversations/src/inbox_v2.rs +++ b/core/conversations/src/inbox_v2.rs @@ -50,13 +50,13 @@ impl MlsContext for PqMlsContext { }; let envelope = EnvelopeV1 { - conversation_hint: ProtocolParams::conversation_id_for_account_id(&account_id), + conversation_hint: ProtocolParams::conversation_id_for_account_id(account_id), salt: 0, payload: frame.encode_to_vec().into(), }; let outbound_msg = AddressedEnvelope { - delivery_address: ProtocolParams::delivery_address_for_account_id(&account_id), + delivery_address: ProtocolParams::delivery_address_for_account_id(account_id), data: envelope.encode_to_vec(), }; diff --git a/crates/client-ffi/src/delivery.rs b/crates/client-ffi/src/delivery.rs index b58f7d2..a403c2d 100644 --- a/crates/client-ffi/src/delivery.rs +++ b/crates/client-ffi/src/delivery.rs @@ -14,6 +14,8 @@ pub type DeliverFn = Option< ) -> i32, >; +#[derive(Debug)] + pub struct CDelivery { pub callback: DeliverFn, } @@ -28,4 +30,8 @@ impl DeliveryService for CDelivery { let rc = unsafe { cb(addr.as_ptr(), addr.len(), data.as_ptr(), data.len()) }; if rc < 0 { Err(rc) } else { Ok(()) } } + + fn subscribe(&mut self, _delivery_address: &str) -> Result<(), Self::Error> { + todo!() + } } diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 5aa4d4c..7bec801 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -8,6 +8,7 @@ crate-type = ["rlib"] [dependencies] libchat = { workspace = true } +logoschat_components = { workspace = true} chat-sqlite = { path = "../../core/sqlite" } thiserror = "2" diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index a51b397..9148cad 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -1,22 +1,23 @@ use libchat::{ - AddressedEnvelope, ChatError, ChatStorage, ContentData, Context, ConversationIdOwned, RegistrationService - DeliveryService, Introduction, StorageConfig, + AddressedEnvelope, ChatError, ChatStorage, ContentData, Context, ConversationIdOwned, + DeliveryService, Introduction, RegistrationService, StorageConfig, }; +use logoschat_components::EphemeralRegistry; + use crate::errors::ClientError; -pub struct ChatClient { - ctx: Context, - delivery: D, +pub struct ChatClient { + ctx: Context, } -impl ChatClient { +impl ChatClient { /// Create an in-memory, ephemeral client. Identity is lost on drop. pub fn new(name: impl Into, delivery: D) -> Self { + let registry = EphemeralRegistry::new(); let store = ChatStorage::in_memory(); Self { - ctx: Context::new_with_name(name, store), - delivery, + ctx: Context::new_with_name(name, delivery, registry, store).unwrap(), } } @@ -30,8 +31,9 @@ impl ChatClient { delivery: D, ) -> Result> { let store = ChatStorage::new(config).map_err(ChatError::from)?; - let ctx = Context::new_from_store(name, store)?; - Ok(Self { ctx, delivery }) + let registry = EphemeralRegistry::new(); + let ctx = Context::new_from_store(name, delivery, registry, store)?; + Ok(Self { ctx }) } /// Returns the installation name (identity label) of this client. @@ -86,7 +88,8 @@ impl ChatClient { envelopes: Vec, ) -> Result<(), ClientError> { for env in envelopes { - self.delivery.publish(env).map_err(ClientError::Delivery)?; + let mut delivery = self.ctx.ds(); + delivery.publish(env).map_err(ClientError::Delivery)?; } Ok(()) } diff --git a/crates/client/src/delivery_in_process.rs b/crates/client/src/delivery_in_process.rs index 6cceb25..3feff06 100644 --- a/crates/client/src/delivery_in_process.rs +++ b/crates/client/src/delivery_in_process.rs @@ -10,7 +10,7 @@ type Message = Vec; /// Messages are stored in an append-only log per delivery address. Readers hold /// independent [`Cursor`]s and advance their position without consuming messages, /// so multiple consumers on the same address each see every message. -#[derive(Clone, Default)] +#[derive(Clone, Default, Debug)] pub struct MessageBus { log: Arc>>>, } @@ -80,7 +80,7 @@ impl Iterator for Cursor { /// clients can share one logical delivery service. Construct with a /// [`MessageBus`] and use [`cursor`](InProcessDelivery::cursor) / /// [`cursor_at_tail`](InProcessDelivery::cursor_at_tail) to read messages. -#[derive(Clone, Default)] +#[derive(Clone, Default, Debug)] pub struct InProcessDelivery(MessageBus); impl InProcessDelivery { @@ -108,4 +108,9 @@ impl DeliveryService for InProcessDelivery { self.0.push(envelope.delivery_address, envelope.data); Ok(()) } + + fn subscribe(&mut self, _delivery_address: &str) -> Result<(), Self::Error> { + // TODO: (P1) implement subscribe + Ok(()) + } } diff --git a/crates/client/src/errors.rs b/crates/client/src/errors.rs index ff7ac27..322104c 100644 --- a/crates/client/src/errors.rs +++ b/crates/client/src/errors.rs @@ -1,7 +1,7 @@ use libchat::ChatError; #[derive(Debug, thiserror::Error)] -pub enum ClientError { +pub enum ClientError { #[error(transparent)] Chat(#[from] ChatError), /// Crypto state advanced but at least one envelope failed delivery.