From 096f355915ef1ab0a5ba471042cd1da09ec5aa2b Mon Sep 17 00:00:00 2001 From: kaichaosun Date: Wed, 25 Mar 2026 16:18:59 +0800 Subject: [PATCH] refactor: use new styling for conversations crate without mod.rs --- core/conversations/src/api.rs | 38 ------------------- core/conversations/src/ffi/mod.rs | 1 - core/conversations/src/ffi/utils.rs | 8 ---- core/conversations/src/lib.rs | 1 - .../src/{storage/db.rs => storage.rs} | 7 ++-- core/conversations/src/storage/mod.rs | 7 ---- 6 files changed, 4 insertions(+), 58 deletions(-) delete mode 100644 core/conversations/src/ffi/mod.rs delete mode 100644 core/conversations/src/ffi/utils.rs rename core/conversations/src/{storage/db.rs => storage.rs} (97%) delete mode 100644 core/conversations/src/storage/mod.rs diff --git a/core/conversations/src/api.rs b/core/conversations/src/api.rs index 75319f9..bd1e300 100644 --- a/core/conversations/src/api.rs +++ b/core/conversations/src/api.rs @@ -13,12 +13,9 @@ use safer_ffi::{ prelude::{c_slice, repr_c}, }; -use storage::StorageConfig; - use crate::{ context::{Context, Introduction}, errors::ChatError, - ffi::utils::CResult, types::ContentData, }; @@ -57,41 +54,6 @@ pub fn create_context(name: repr_c::String) -> repr_c::Box { Box::new(ContextHandle(Context::new_with_name(&*name))).into() } -/// Creates a new libchat Context with file-based persistent storage. -/// -/// The identity will be loaded from storage if it exists, or created and saved if not. -/// -/// # Parameters -/// - name: Friendly name for the identity (used if creating new identity) -/// - db_path: Path to the SQLite database file -/// - db_secret: Secret key for encrypting the database -/// -/// # Returns -/// CResult with context handle on success, or error string on failure. -/// On success, the context handle must be freed with `destroy_context()` after usage. -/// On error, the error string must be freed with `destroy_string()` after usage. -#[ffi_export] -pub fn create_context_with_storage( - name: repr_c::String, - db_path: repr_c::String, - db_secret: repr_c::String, -) -> CResult, repr_c::String> { - let config = StorageConfig::Encrypted { - path: db_path.to_string(), - key: db_secret.to_string(), - }; - match Context::open(&*name, config) { - Ok(ctx) => CResult { - ok: Some(Box::new(ContextHandle(ctx)).into()), - err: None, - }, - Err(e) => CResult { - ok: None, - err: Some(e.to_string().into()), - }, - } -} - /// Returns the friendly name of the contexts installation. /// #[ffi_export] diff --git a/core/conversations/src/ffi/mod.rs b/core/conversations/src/ffi/mod.rs deleted file mode 100644 index b5614dd..0000000 --- a/core/conversations/src/ffi/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod utils; diff --git a/core/conversations/src/ffi/utils.rs b/core/conversations/src/ffi/utils.rs deleted file mode 100644 index 7989631..0000000 --- a/core/conversations/src/ffi/utils.rs +++ /dev/null @@ -1,8 +0,0 @@ -use safer_ffi::prelude::*; - -#[derive_ReprC] -#[repr(C)] -pub struct CResult { - pub ok: Option, - pub err: Option, -} diff --git a/core/conversations/src/lib.rs b/core/conversations/src/lib.rs index d81eb91..de0c023 100644 --- a/core/conversations/src/lib.rs +++ b/core/conversations/src/lib.rs @@ -3,7 +3,6 @@ mod context; mod conversation; mod crypto; mod errors; -mod ffi; mod identity; mod inbox; mod proto; diff --git a/core/conversations/src/storage/db.rs b/core/conversations/src/storage.rs similarity index 97% rename from core/conversations/src/storage/db.rs rename to core/conversations/src/storage.rs index c855416..6cc988c 100644 --- a/core/conversations/src/storage/db.rs +++ b/core/conversations/src/storage.rs @@ -1,11 +1,12 @@ //! Chat-specific storage implementation. +mod migrations; +pub(crate) mod types; + use storage::{RusqliteError, SqliteDb, StorageConfig, StorageError, params}; use zeroize::Zeroize; -use super::migrations; -use super::types::IdentityRecord; -use crate::identity::Identity; +use crate::{identity::Identity, storage::types::IdentityRecord}; /// Chat-specific storage operations. /// diff --git a/core/conversations/src/storage/mod.rs b/core/conversations/src/storage/mod.rs deleted file mode 100644 index 9364aeb..0000000 --- a/core/conversations/src/storage/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -//! Storage module for persisting chat state. - -mod db; -mod migrations; -pub(crate) mod types; - -pub(crate) use db::ChatStorage;