refactor: use new styling for conversations crate without mod.rs (#72)

* refactor: use new styling for conversations crate without mod.rs

* refactor: remove put crate for identity types
This commit is contained in:
kaichao 2026-03-27 10:23:33 +08:00 committed by GitHub
parent 9a94f9a6d6
commit 8cddd9ddcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 4 additions and 58 deletions

View File

@ -13,12 +13,9 @@ use safer_ffi::{
prelude::{c_slice, repr_c}, prelude::{c_slice, repr_c},
}; };
use storage::StorageConfig;
use crate::{ use crate::{
context::{Context, Introduction}, context::{Context, Introduction},
errors::ChatError, errors::ChatError,
ffi::utils::CResult,
types::ContentData, types::ContentData,
}; };
@ -57,41 +54,6 @@ pub fn create_context(name: repr_c::String) -> repr_c::Box<ContextHandle> {
Box::new(ContextHandle(Context::new_with_name(&*name))).into() 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::Box<ContextHandle>, 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. /// Returns the friendly name of the contexts installation.
/// ///
#[ffi_export] #[ffi_export]

View File

@ -1 +0,0 @@
pub mod utils;

View File

@ -1,8 +0,0 @@
use safer_ffi::prelude::*;
#[derive_ReprC]
#[repr(C)]
pub struct CResult<T: ReprC, Err: ReprC> {
pub ok: Option<T>,
pub err: Option<Err>,
}

View File

@ -3,7 +3,6 @@ mod context;
mod conversation; mod conversation;
mod crypto; mod crypto;
mod errors; mod errors;
mod ffi;
mod identity; mod identity;
mod inbox; mod inbox;
mod proto; mod proto;

View File

@ -1,11 +1,12 @@
//! Chat-specific storage implementation. //! Chat-specific storage implementation.
mod migrations;
mod types;
use storage::{RusqliteError, SqliteDb, StorageConfig, StorageError, params}; use storage::{RusqliteError, SqliteDb, StorageConfig, StorageError, params};
use zeroize::Zeroize; use zeroize::Zeroize;
use super::migrations; use crate::{identity::Identity, storage::types::IdentityRecord};
use super::types::IdentityRecord;
use crate::identity::Identity;
/// Chat-specific storage operations. /// Chat-specific storage operations.
/// ///

View File

@ -1,7 +0,0 @@
//! Storage module for persisting chat state.
mod db;
mod migrations;
pub(crate) mod types;
pub(crate) use db::ChatStorage;