mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-07-25 09:13:12 +00:00
feat: re-export ChatStorage and make storage_config fallible
Callers that build an encrypted store had to depend on `libchat` directly for `ChatStorage`, and `ChatClientBuilder::storage_config` panicked on a bad config, which aborts the process under `panic = "abort"`. - Re-export `ChatStorage` from logos-chat so callers can name the store type without a direct `libchat` dependency. - `storage_config` now returns `Result<_, ChatError>` instead of `.expect()`, so an unopenable database surfaces as an error. Updates the chat-cli callers.
This commit is contained in:
parent
0d38dd80b7
commit
443a26d7bb
@ -119,6 +119,7 @@ fn run<T: Transport>(transport: T, cli: &Cli) -> Result<()> {
|
|||||||
let (client, events) = ChatClientBuilder::new()
|
let (client, events) = ChatClientBuilder::new()
|
||||||
.transport(transport)
|
.transport(transport)
|
||||||
.storage_config(storage)
|
.storage_config(storage)
|
||||||
|
.map_err(|e| anyhow::anyhow!("{e:?}"))?
|
||||||
.registration(registry)
|
.registration(registry)
|
||||||
.build()
|
.build()
|
||||||
.map_err(|e| anyhow::anyhow!("{e:?}"))
|
.map_err(|e| anyhow::anyhow!("{e:?}"))
|
||||||
@ -129,6 +130,7 @@ fn run<T: Transport>(transport: T, cli: &Cli) -> Result<()> {
|
|||||||
let (client, events) = ChatClientBuilder::new()
|
let (client, events) = ChatClientBuilder::new()
|
||||||
.transport(transport)
|
.transport(transport)
|
||||||
.storage_config(storage)
|
.storage_config(storage)
|
||||||
|
.map_err(|e| anyhow::anyhow!("{e:?}"))?
|
||||||
.build()
|
.build()
|
||||||
.map_err(|e| anyhow::anyhow!("{e:?}"))
|
.map_err(|e| anyhow::anyhow!("{e:?}"))
|
||||||
.context("failed to open chat client")?;
|
.context("failed to open chat client")?;
|
||||||
@ -197,6 +199,7 @@ fn run_logos_delivery(cli: Cli) -> Result<()> {
|
|||||||
path: db_str,
|
path: db_str,
|
||||||
key: "chat-cli".to_string(),
|
key: "chat-cli".to_string(),
|
||||||
})
|
})
|
||||||
|
.map_err(|e| anyhow::anyhow!("{e:?}"))?
|
||||||
.transport(delivery)
|
.transport(delivery)
|
||||||
.build()
|
.build()
|
||||||
.map_err(|e| anyhow::anyhow!("{e:?}"))
|
.map_err(|e| anyhow::anyhow!("{e:?}"))
|
||||||
|
|||||||
@ -74,17 +74,18 @@ impl<I, T, R, S> ChatClientBuilder<I, T, R, S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn storage_config(self, config: StorageConfig) -> ChatClientBuilder<I, T, R, ChatStorage> {
|
pub fn storage_config(
|
||||||
let storage = ChatStorage::new(config)
|
self,
|
||||||
.map_err(ChatError::from)
|
config: StorageConfig,
|
||||||
.expect("Storage config file should be valid");
|
) -> Result<ChatClientBuilder<I, T, R, ChatStorage>, ChatError> {
|
||||||
|
let storage = ChatStorage::new(config).map_err(ChatError::from)?;
|
||||||
|
|
||||||
ChatClientBuilder {
|
Ok(ChatClientBuilder {
|
||||||
ident: self.ident,
|
ident: self.ident,
|
||||||
transport: self.transport,
|
transport: self.transport,
|
||||||
registration: self.registration,
|
registration: self.registration,
|
||||||
storage,
|
storage,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ pub use event::{Event, MessageSender};
|
|||||||
|
|
||||||
// Re-export types callers need to interact with ChatClient.
|
// Re-export types callers need to interact with ChatClient.
|
||||||
pub use libchat::{
|
pub use libchat::{
|
||||||
AddressedEnvelope, ChatStore, ConversationClass, ConversationId, DeliveryService,
|
AddressedEnvelope, ChatStorage, ChatStore, ConversationClass, ConversationId, DeliveryService,
|
||||||
IdentityProvider, RegistrationService, StorageConfig,
|
IdentityProvider, RegistrationService, StorageConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user