mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-05-17 23:49:27 +00:00
Warning fixups
This commit is contained in:
parent
da7e06e495
commit
94a2904c0e
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -364,6 +364,7 @@ name = "client"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chat-sqlite",
|
"chat-sqlite",
|
||||||
|
"components",
|
||||||
"libchat",
|
"libchat",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|||||||
@ -22,12 +22,15 @@ default-members = [
|
|||||||
"core/double-ratchets",
|
"core/double-ratchets",
|
||||||
"core/storage",
|
"core/storage",
|
||||||
"core/integration_tests_core",
|
"core/integration_tests_core",
|
||||||
|
"crates/client",
|
||||||
|
"crates/client-ffi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
blake2 = "0.10"
|
blake2 = "0.10"
|
||||||
crypto = { path = "core/crypto" }
|
crypto = { path = "core/crypto" }
|
||||||
libchat = { path = "core/conversations" }
|
libchat = { path = "core/conversations" }
|
||||||
|
logoschat_components = {package="components", path ="extensions/components"}
|
||||||
sqlite = { path = "core/sqlite"}
|
sqlite = { path = "core/sqlite"}
|
||||||
storage = { path = "core/storage" }
|
storage = { path = "core/storage" }
|
||||||
|
|
||||||
|
|||||||
@ -78,7 +78,7 @@ where
|
|||||||
.map_err(ChatError::generic)?;
|
.map_err(ChatError::generic)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
identity: identity,
|
identity,
|
||||||
ds,
|
ds,
|
||||||
store,
|
store,
|
||||||
inbox,
|
inbox,
|
||||||
@ -319,7 +319,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)] // Temporary until GroupIntegration is completed
|
|
||||||
fn load_group_convo(
|
fn load_group_convo(
|
||||||
&mut self,
|
&mut self,
|
||||||
convo_id: ConversationId,
|
convo_id: ConversationId,
|
||||||
|
|||||||
@ -172,9 +172,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn subscribe(ds: &mut DS, convo_id: &str) -> Result<(), ChatError> {
|
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)?;
|
.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)?;
|
.map_err(ChatError::generic)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@ -50,13 +50,13 @@ impl MlsContext for PqMlsContext {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let envelope = EnvelopeV1 {
|
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,
|
salt: 0,
|
||||||
payload: frame.encode_to_vec().into(),
|
payload: frame.encode_to_vec().into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let outbound_msg = AddressedEnvelope {
|
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(),
|
data: envelope.encode_to_vec(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,8 @@ pub type DeliverFn = Option<
|
|||||||
) -> i32,
|
) -> i32,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
|
||||||
pub struct CDelivery {
|
pub struct CDelivery {
|
||||||
pub callback: DeliverFn,
|
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()) };
|
let rc = unsafe { cb(addr.as_ptr(), addr.len(), data.as_ptr(), data.len()) };
|
||||||
if rc < 0 { Err(rc) } else { Ok(()) }
|
if rc < 0 { Err(rc) } else { Ok(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn subscribe(&mut self, _delivery_address: &str) -> Result<(), Self::Error> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ crate-type = ["rlib"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libchat = { workspace = true }
|
libchat = { workspace = true }
|
||||||
|
logoschat_components = { workspace = true}
|
||||||
chat-sqlite = { path = "../../core/sqlite" }
|
chat-sqlite = { path = "../../core/sqlite" }
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
|
|
||||||
|
|||||||
@ -1,22 +1,23 @@
|
|||||||
use libchat::{
|
use libchat::{
|
||||||
AddressedEnvelope, ChatError, ChatStorage, ContentData, Context, ConversationIdOwned, RegistrationService
|
AddressedEnvelope, ChatError, ChatStorage, ContentData, Context, ConversationIdOwned,
|
||||||
DeliveryService, Introduction, StorageConfig,
|
DeliveryService, Introduction, RegistrationService, StorageConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use logoschat_components::EphemeralRegistry;
|
||||||
|
|
||||||
use crate::errors::ClientError;
|
use crate::errors::ClientError;
|
||||||
|
|
||||||
pub struct ChatClient<D: DeliveryService> {
|
pub struct ChatClient<D: DeliveryService + 'static> {
|
||||||
ctx: Context<D, EphemeralChatStorage>,
|
ctx: Context<D, EphemeralRegistry, ChatStorage>,
|
||||||
delivery: D,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DeliveryService, RS: RegistrationService, > ChatClient<D> {
|
impl<D: DeliveryService> ChatClient<D> {
|
||||||
/// Create an in-memory, ephemeral client. Identity is lost on drop.
|
/// Create an in-memory, ephemeral client. Identity is lost on drop.
|
||||||
pub fn new(name: impl Into<String>, delivery: D) -> Self {
|
pub fn new(name: impl Into<String>, delivery: D) -> Self {
|
||||||
|
let registry = EphemeralRegistry::new();
|
||||||
let store = ChatStorage::in_memory();
|
let store = ChatStorage::in_memory();
|
||||||
Self {
|
Self {
|
||||||
ctx: Context::new_with_name(name, store),
|
ctx: Context::new_with_name(name, delivery, registry, store).unwrap(),
|
||||||
delivery,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,8 +31,9 @@ impl<D: DeliveryService, RS: RegistrationService, > ChatClient<D> {
|
|||||||
delivery: D,
|
delivery: D,
|
||||||
) -> Result<Self, ClientError<D::Error>> {
|
) -> Result<Self, ClientError<D::Error>> {
|
||||||
let store = ChatStorage::new(config).map_err(ChatError::from)?;
|
let store = ChatStorage::new(config).map_err(ChatError::from)?;
|
||||||
let ctx = Context::new_from_store(name, store)?;
|
let registry = EphemeralRegistry::new();
|
||||||
Ok(Self { ctx, delivery })
|
let ctx = Context::new_from_store(name, delivery, registry, store)?;
|
||||||
|
Ok(Self { ctx })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the installation name (identity label) of this client.
|
/// Returns the installation name (identity label) of this client.
|
||||||
@ -86,7 +88,8 @@ impl<D: DeliveryService, RS: RegistrationService, > ChatClient<D> {
|
|||||||
envelopes: Vec<AddressedEnvelope>,
|
envelopes: Vec<AddressedEnvelope>,
|
||||||
) -> Result<(), ClientError<D::Error>> {
|
) -> Result<(), ClientError<D::Error>> {
|
||||||
for env in envelopes {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ type Message = Vec<u8>;
|
|||||||
/// Messages are stored in an append-only log per delivery address. Readers hold
|
/// Messages are stored in an append-only log per delivery address. Readers hold
|
||||||
/// independent [`Cursor`]s and advance their position without consuming messages,
|
/// independent [`Cursor`]s and advance their position without consuming messages,
|
||||||
/// so multiple consumers on the same address each see every message.
|
/// so multiple consumers on the same address each see every message.
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default, Debug)]
|
||||||
pub struct MessageBus {
|
pub struct MessageBus {
|
||||||
log: Arc<RwLock<HashMap<String, Vec<Message>>>>,
|
log: Arc<RwLock<HashMap<String, Vec<Message>>>>,
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ impl Iterator for Cursor {
|
|||||||
/// clients can share one logical delivery service. Construct with a
|
/// clients can share one logical delivery service. Construct with a
|
||||||
/// [`MessageBus`] and use [`cursor`](InProcessDelivery::cursor) /
|
/// [`MessageBus`] and use [`cursor`](InProcessDelivery::cursor) /
|
||||||
/// [`cursor_at_tail`](InProcessDelivery::cursor_at_tail) to read messages.
|
/// [`cursor_at_tail`](InProcessDelivery::cursor_at_tail) to read messages.
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default, Debug)]
|
||||||
pub struct InProcessDelivery(MessageBus);
|
pub struct InProcessDelivery(MessageBus);
|
||||||
|
|
||||||
impl InProcessDelivery {
|
impl InProcessDelivery {
|
||||||
@ -108,4 +108,9 @@ impl DeliveryService for InProcessDelivery {
|
|||||||
self.0.push(envelope.delivery_address, envelope.data);
|
self.0.push(envelope.delivery_address, envelope.data);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn subscribe(&mut self, _delivery_address: &str) -> Result<(), Self::Error> {
|
||||||
|
// TODO: (P1) implement subscribe
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use libchat::ChatError;
|
use libchat::ChatError;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum ClientError<D: std::fmt::Debug> {
|
pub enum ClientError<D: std::fmt::Display> {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Chat(#[from] ChatError),
|
Chat(#[from] ChatError),
|
||||||
/// Crypto state advanced but at least one envelope failed delivery.
|
/// Crypto state advanced but at least one envelope failed delivery.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user