pub fn new(data: &Database, parent: Post, access_hash: &str, content: String, children_rights: CanPost) -> (Post, Option<Post>) {
        if content.len() > 50000 {
            return (parent, None)
        }
        let rights = &parent.children_rights;
        if matches!(rights, CanPost::All) || matches!(rights, CanPost::Itself) && &parent.access_hash == access_hash {
            let id = new_uuid();
            let mut handles: Vec<JoinHandle<()>> = vec![];
            data.at(&["created_post_ids", &access_hash.replace(|c:char| !c.is_ascii_alphanumeric(), "_")]).ok().map(|node| {
                handles.push(node.push_async(&format!("{{\"post_id\":\"{}\"}}", id), |_| ()))
            });
            data.at(&["children", &parent.id]).ok().map(|node| {
                let b = Some(format!("{{\"{}\":0}}", id));
                b.map(|body| handles.push(node.update_async(body, |_| ())));
            });
            atomic_update(data, &["children_length", &parent.id], 0i64, |v| v+1);
            for handle in handles { handle.join().unwrap(); }
            let parent_id = parent.id.clone();
            (
                parent,
                Some(Post {
                    id,
                    access_hash: access_hash.to_string(),
                    human_readable_url: "".to_string(),
                    content,
                    reward: 0i64,
                    parent_id,
                    children_rights,
                    gave_reward: 0i8,
                    reverse_date_created: -timestamp(),
                })
            )
        } else {
            (parent, None)
        }
    }
/// Adds a new child-post to a parent-post.
/// Also pushes to a user's created posts (no way to atomize this with firebase_rs).
/// `access_hash` must be `crate::posts_api::access_token_hash(user)`.
/// Returns (parent, Option<child>).
Adds a new child-post to a parent-post.
Also pushes to a user's created posts (no way to atomize this with firebase_rs).
Adds a new child - post to a parent - post . Also pushes to a user ' s created posts ( no way to atomize this with firebase_rs ) .
pub fn new(data: &Database, parent: Post, access_hash: &str, content: String, children_rights: CanPost) -> (Post, Option<Post>) {
        if content.len() > 50000 {
            return (parent, None)
        }
        let rights = &parent.children_rights;
        if matches!(rights, CanPost::All) || matches!(rights, CanPost::Itself) && &parent.access_hash == access_hash {
            let id = new_uuid();
            let mut handles: Vec<JoinHandle<()>> = vec![];
            data.at(&["created_post_ids", &access_hash.replace(|c:char| !c.is_ascii_alphanumeric(), "_")]).ok().map(|node| {
                handles.push(node.push_async(&format!("{{\"post_id\":\"{}\"}}", id), |_| ()))
            });
            data.at(&["children", &parent.id]).ok().map(|node| {
                let b = Some(format!("{{\"{}\":0}}", id));
                b.map(|body| handles.push(node.update_async(body, |_| ())));
            });
            atomic_update(data, &["children_length", &parent.id], 0i64, |v| v+1);
            for handle in handles { handle.join().unwrap(); }
            let parent_id = parent.id.clone();
            (
                parent,
                Some(Post {
                    id,
                    access_hash: access_hash.to_string(),
                    human_readable_url: "".to_string(),
                    content,
                    reward: 0i64,
                    parent_id,
                    children_rights,
                    gave_reward: 0i8,
                    reverse_date_created: -timestamp(),
                })
            )
        } else {
            (parent, None)
        }
    }
pub fn new ( data : & Database , parent : Post , access_hash : & str , content : String , children_rights : CanPost ) -> ( Post , Option < Post > ) { if content . len ( ) > 50000 { return ( parent , None ) } let rights = & parent . children_rights ; if matches ! ( rights CanPost All ) || matches ! ( rights CanPost Itself ) && & parent . access_hash == access_hash { let id = new_uuid ( ) ; let mut handles : Vec < JoinHandle < ( ) > > = vec ! [ ] ; data . at ( & [ " " , & access_hash . replace ( | c : char | ! c . is_ascii_alphanumeric ( ) , " " ) ] ) . ok ( ) . map ( | node | { handles . push ( node . push_async ( & format ! ( " \" \" \" \" " id ) , | _ | ( ) ) ) } ) ; data . at ( & [ " " , & parent . id ] ) . ok ( ) . map ( | node | { let b = Some ( format ! ( " \" \" " id ) ) ; b . map ( | body | handles . push ( node . update_async ( body , | _ | ( ) ) ) ) ; } ) ; atomic_update ( data , & [ " " , & parent . id ] , 0i64 , | v | v + 1 ) ; for handle in handles { handle . join ( ) . unwrap ( ) ; } let parent_id = parent . id . clone ( ) ; ( parent , Some ( Post { id , access_hash : access_hash . to_string ( ) , human_readable_url : " " . to_string ( ) , content , reward : 0i64 , parent_id , children_rights , gave_reward : 0i8 , reverse_date_created : - timestamp ( ) , } ) ) } else { ( parent , None ) } }
Adds a new child-post to a parent-post.
Adds a new child - post to a parent - post .
data
&Database
parent
Post
access_hash
&str
content
String
children_rights
CanPost
data
&Database
parent
Post
access_hash
&str
content
String
children_rights
CanPost