jazz-rs 0.7.0

A framework for CRDT based, end-to-end enrypted distributed apps
Documentation
// TODO-V1(design): #40 Teams with invitations and protected member identities
// TODO-V1(design): #41 Attachments for immutable files (with quality versions?)

// TODO-V1(design): #44 Identities take the form of emails username+scope@usegarden.com -> that server can act as an identity provider
// TODO(design): #45 Allow user to create arbitrary profiles/inboxes in the shape anon892347@usegarden.com

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,
    // TODO: also split by credential source used, assume main one when gettings docs by default
    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;
    }
}