use std::{cell::RefCell, collections::HashMap, rc::Rc};
use credo::{Credo, CredentialSource, SimpleCredentialSource, CredentialSourceHash};
use mofo::Mofo;
use caro::Remote;
#[cfg(feature = "js")]
use wasm_bindgen::prelude::*;
mod account;
mod conventions;
mod doc;
mod invitation;
mod managed_jmbl;
mod team;
pub use doc::{DocID, Doc};
pub use team::{TeamID, Team};
pub use managed_jmbl::ManagedJMBL;
pub use invitation::{Invitation, InvitationKind, InvitationToken};
struct JazzInner {
content: caro::Node,
credo: Credo,
docs: HashMap<(CredentialSourceHash, DocID), Doc>,
main_credential_source: Box<dyn CredentialSource>,
background: Mofo,
}
#[derive(Clone)]
pub struct Jazz(Rc<RefCell<JazzInner>>);
impl Jazz {
pub fn new(name: String, background: Mofo) -> Self {
let node = caro::Node::new(background.clone());
let credo = Credo::new_with_telepathy(name, node.clone(), background.clone());
Jazz(Rc::new(RefCell::new(JazzInner {
content: node,
credo,
docs: HashMap::new(),
main_credential_source: Box::new(SimpleCredentialSource::new()),
background,
})))
}
fn credo(&self) -> Credo {
self.0.borrow().credo.clone()
}
fn content(&self) -> caro::Node {
self.0.borrow().content.clone()
}
pub async fn add_remote(&self, remote: Remote) {
self.credo().add_remote(remote).await;
}
}