pub fn invite(&mut self, name: String, group: String) -> Result<(), String> {
        // First we need to get the key package for {id} from the DS.
        // We just take the first key package we get back from the server.
        let contact = match self.contacts.values().find(|c| c.username == name) {
            Some(v) => v,
            None => return Err(format!("No contact with name {} known.", name)),
        };
        let (_hash, key_package) = self
            .backend
            .get_client(&contact.id)
            .unwrap()
            .0
            .pop()
            .unwrap();

        // Build a proposal with this key package and do the MLS bits.
        let group_id = group.as_bytes();
        let mut groups = self.groups.borrow_mut();
        let group = match groups.get_mut(group_id) {
            Some(g) => g,
            None => return Err(format!("No group with name {} known.", group)),
        };
        let credentials = &self.identity.borrow().credential;
        // Framing parameters
        let framing_parameters = FramingParameters::new(&group.group_aad, WireFormat::MlsPlaintext);
        let add_proposal = group
            .mls_group
            .borrow()
            .create_add_proposal(framing_parameters, credentials, key_package, &self.crypto)
            .expect("Could not create proposal.");
        let proposals = vec![&add_proposal];
        let (commit, welcome_msg, _kpb) = group
            .mls_group
            .borrow()
            .create_commit(
                framing_parameters,
                credentials,
                Proposals {
                    proposals_by_reference: &proposals,
                    proposals_by_value: &[],
                },
                false,
                None,
                &self.crypto,
            )
            .expect("Error creating commit");
        let welcome_msg = welcome_msg.expect("Welcome message wasn't created by create_commit.");
        group
            .mls_group
            .borrow_mut()
            .apply_commit(&commit, &[&add_proposal], &[], None, &self.crypto)
            .expect("error applying commit");

        // Send Welcome to the client.
        log::trace!("Sending welcome");
        self.backend
            .send_welcome(&welcome_msg)
            .expect("Error sending unwrap message");

        // Send proposal to the group.
        log::trace!("Sending proposal");
        let group = groups.get_mut(group_id).unwrap(); // XXX: not cool.
        let group_recipients = self.recipients(group);
        // TODO: the outgoing messages should use `MlsMessage` instead.
        let msg = GroupMessage::new(
            DsMlsMessage::Plaintext(VerifiableMlsPlaintext::from_plaintext(add_proposal, None)),
            &group_recipients,
        );
        self.backend.send_msg(&msg)?;

        // Send commit to the group.
        log::trace!("Sending commit");
        let msg = GroupMessage::new(
            DsMlsMessage::Plaintext(VerifiableMlsPlaintext::from_plaintext(commit, None)),
            &group_recipients,
        );
        self.backend.send_msg(&msg)?;

        // Update the group state
        group.members.push(contact.id.clone());

        Ok(())
    }
/// Invite user with the given name to the group.
Invite user with the given name to the group.
Invite user with the given name to the group .
pub fn invite(&mut self, name: String, group: String) -> Result<(), String> {
        // First we need to get the key package for {id} from the DS.
        // We just take the first key package we get back from the server.
        let contact = match self.contacts.values().find(|c| c.username == name) {
            Some(v) => v,
            None => return Err(format!("No contact with name {} known.", name)),
        };
        let (_hash, key_package) = self
            .backend
            .get_client(&contact.id)
            .unwrap()
            .0
            .pop()
            .unwrap();
        // Build a proposal with this key package and do the MLS bits.
        let group_id = group.as_bytes();
        let mut groups = self.groups.borrow_mut();
        let group = match groups.get_mut(group_id) {
            Some(g) => g,
            None => return Err(format!("No group with name {} known.", group)),
        };
        let credentials = &self.identity.borrow().credential;
        // Framing parameters
        let framing_parameters = FramingParameters::new(&group.group_aad, WireFormat::MlsPlaintext);
        let add_proposal = group
            .mls_group
            .borrow()
            .create_add_proposal(framing_parameters, credentials, key_package, &self.crypto)
            .expect("Could not create proposal.");
        let proposals = vec![&add_proposal];
        let (commit, welcome_msg, _kpb) = group
            .mls_group
            .borrow()
            .create_commit(
                framing_parameters,
                credentials,
                Proposals {
                    proposals_by_reference: &proposals,
                    proposals_by_value: &[],
                },
                false,
                None,
                &self.crypto,
            )
            .expect("Error creating commit");
        let welcome_msg = welcome_msg.expect("Welcome message wasn't created by create_commit.");
        group
            .mls_group
            .borrow_mut()
            .apply_commit(&commit, &[&add_proposal], &[], None, &self.crypto)
            .expect("error applying commit");
        // Send Welcome to the client.
        log::trace!("Sending welcome");
        self.backend
            .send_welcome(&welcome_msg)
            .expect("Error sending unwrap message");
        // Send proposal to the group.
        log::trace!("Sending proposal");
        let group = groups.get_mut(group_id).unwrap(); // XXX: not cool.
        let group_recipients = self.recipients(group);
        // TODO: the outgoing messages should use `MlsMessage` instead.
        let msg = GroupMessage::new(
            DsMlsMessage::Plaintext(VerifiableMlsPlaintext::from_plaintext(add_proposal, None)),
            &group_recipients,
        );
        self.backend.send_msg(&msg)?;
        // Send commit to the group.
        log::trace!("Sending commit");
        let msg = GroupMessage::new(
            DsMlsMessage::Plaintext(VerifiableMlsPlaintext::from_plaintext(commit, None)),
            &group_recipients,
        );
        self.backend.send_msg(&msg)?;
        // Update the group state
        group.members.push(contact.id.clone());
        Ok(())
    }
pub fn invite ( & mut self , name : String , group : String ) -> Result < ( ) , String > { // First we need to get the key package for {id} from the DS. // We just take the first key package we get back from the server. let contact = match self . contacts . values ( ) . find ( | c | c . username == name ) { Some ( v ) => v , None => return Err ( format ! ( " " name ) ) , } ; let ( _hash , key_package ) = self . backend . get_client ( & contact . id ) . unwrap ( ) . 0 . pop ( ) . unwrap ( ) ; // Build a proposal with this key package and do the MLS bits. let group_id = group . as_bytes ( ) ; let mut groups = self . groups . borrow_mut ( ) ; let group = match groups . get_mut ( group_id ) { Some ( g ) => g , None => return Err ( format ! ( " " group ) ) , } ; let credentials = & self . identity . borrow ( ) . credential ; // Framing parameters let framing_parameters = FramingParameters :: new ( & group . group_aad , WireFormat :: MlsPlaintext ) ; let add_proposal = group . mls_group . borrow ( ) . create_add_proposal ( framing_parameters , credentials , key_package , & self . crypto ) . expect ( " " ) ; let proposals = vec ! [ add_proposal ] ; let ( commit , welcome_msg , _kpb ) = group . mls_group . borrow ( ) . create_commit ( framing_parameters , credentials , Proposals { proposals_by_reference : & proposals , proposals_by_value : & [ ] , } , false , None , & self . crypto , ) . expect ( " " ) ; let welcome_msg = welcome_msg . expect ( " " ) ; group . mls_group . borrow_mut ( ) . apply_commit ( & commit , & [ & add_proposal ] , & [ ] , None , & self . crypto ) . expect ( " " ) ; // Send Welcome to the client. log :: trace ! ( " " ) ; self . backend . send_welcome ( & welcome_msg ) . expect ( " " ) ; // Send proposal to the group. log :: trace ! ( " " ) ; let group = groups . get_mut ( group_id ) . unwrap ( ) ; // XXX: not cool. let group_recipients = self . recipients ( group ) ; // TODO: the outgoing messages should use `MlsMessage` instead. let msg = GroupMessage :: new ( DsMlsMessage :: Plaintext ( VerifiableMlsPlaintext :: from_plaintext ( add_proposal , None ) ) , & group_recipients , ) ; self . backend . send_msg ( & msg ) ? ; // Send commit to the group. log :: trace ! ( " " ) ; let msg = GroupMessage :: new ( DsMlsMessage :: Plaintext ( VerifiableMlsPlaintext :: from_plaintext ( commit , None ) ) , & group_recipients , ) ; self . backend . send_msg ( & msg ) ? ; // Update the group state group . members . push ( contact . id . clone ( ) ) ; Ok ( ( ) ) }
Invite user with the given name to the group.
Invite user with the given name to the group .
&mut self
name
String
group
String
&mut self
name
String
group
String