mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-03-26 22:23:14 +00:00
refactor: use new styling for conversations crate without mod.rs
This commit is contained in:
parent
9a94f9a6d6
commit
096f355915
@ -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<ContextHandle> {
|
||||
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.
|
||||
///
|
||||
#[ffi_export]
|
||||
|
||||
@ -1 +0,0 @@
|
||||
pub mod utils;
|
||||
@ -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>,
|
||||
}
|
||||
@ -3,7 +3,6 @@ mod context;
|
||||
mod conversation;
|
||||
mod crypto;
|
||||
mod errors;
|
||||
mod ffi;
|
||||
mod identity;
|
||||
mod inbox;
|
||||
mod proto;
|
||||
|
||||
@ -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.
|
||||
///
|
||||
@ -1,7 +0,0 @@
|
||||
//! Storage module for persisting chat state.
|
||||
|
||||
mod db;
|
||||
mod migrations;
|
||||
pub(crate) mod types;
|
||||
|
||||
pub(crate) use db::ChatStorage;
|
||||
Loading…
x
Reference in New Issue
Block a user