Skip to content

Commit

Permalink
Create group with initial members (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas authored Aug 29, 2024
1 parent e6e8cab commit b300474
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
16 changes: 8 additions & 8 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,14 +714,14 @@ impl FfiConversations {
_ => None,
};

let convo = self
.inner_client
.create_group(group_permissions, metadata_options)?;
if !account_addresses.is_empty() {
convo
.add_members(&self.inner_client, account_addresses)
.await?;
}
let convo = if account_addresses.is_empty() {
self.inner_client
.create_group(group_permissions, metadata_options)?
} else {
self.inner_client
.create_group_with_members(account_addresses, group_permissions, metadata_options)
.await?
};

let out = Arc::new(FfiGroup {
inner_client: self.inner_client.clone(),
Expand Down
23 changes: 23 additions & 0 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,29 @@ where
Ok(group)
}

pub async fn create_group_with_members(
&self,
account_addresses: Vec<String>,
permissions_policy_set: Option<PolicySet>,
opts: GroupMetadataOptions,
) -> Result<MlsGroup, ClientError> {
log::info!("creating group");

let group = MlsGroup::create_and_insert(
self.context.clone(),
GroupMembershipState::Allowed,
permissions_policy_set.unwrap_or_default(),
opts,
)?;

group.add_members(self, account_addresses).await?;

// notify any streams of the new group
let _ = self.local_events.send(LocalEvents::NewGroup(group.clone()));

Ok(group)
}

pub(crate) fn create_sync_group(&self) -> Result<MlsGroup, ClientError> {
log::info!("creating sync group");
let sync_group = MlsGroup::create_and_insert_sync_group(self.context.clone())?;
Expand Down

0 comments on commit b300474

Please sign in to comment.