1mod client;
8mod ffi;
9mod model;
10
11use std::{path::Path, path::PathBuf, sync::Arc, sync::mpsc};
12
13pub use client::{ChatDeleteMode, ChatFeature, SimplexCommand as Command};
14pub use ffi::SimplexError as Error;
15pub use model::{
16 Attachment, AttachmentKind, ChatDeletionSettings, ChatFeatures, ChatRef, ChatSummary, Message,
17 MessageReaction, Profile, ServerEntry, ServerProtocol, SimplexEvent as Event, User,
18};
19
20pub struct Client {
22 api: Arc<ffi::SimplexApi>,
23}
24
25#[derive(Clone, Debug, Eq, PartialEq)]
27pub struct Config {
28 pub data_directory: PathBuf,
29 pub download_directory: PathBuf,
30}
31
32impl Config {
33 pub fn new(data_directory: impl Into<PathBuf>, download_directory: impl Into<PathBuf>) -> Self {
34 Self {
35 data_directory: data_directory.into(),
36 download_directory: download_directory.into(),
37 }
38 }
39}
40
41impl Client {
42 pub fn load(path: impl AsRef<Path>) -> Result<Self, Error> {
44 let api = unsafe { ffi::SimplexApi::load(path) }?;
47 Ok(Self { api })
48 }
49
50 pub fn start(self, config: Config) -> Session {
52 let (event_sender, events) = mpsc::channel();
53 let commands = client::spawn(self.api, config, event_sender);
54 Session { commands, events }
55 }
56}
57
58pub struct Session {
60 commands: mpsc::Sender<Command>,
61 events: mpsc::Receiver<Event>,
62}
63
64impl Session {
65 pub fn into_parts(self) -> (mpsc::Sender<Command>, mpsc::Receiver<Event>) {
66 (self.commands, self.events)
67 }
68}