Skip to content

Commit

Permalink
Pass in account_address during group creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieobject committed Apr 8, 2024
1 parent 2ee485c commit 2502163
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 7 additions & 3 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,13 @@ where
) -> Result<MlsGroup<ApiClient>, ClientError> {
log::info!("creating group");

// EM: Consider setting host id here as self?
let group = MlsGroup::create_and_insert(self, GroupMembershipState::Allowed, permissions)
.map_err(|e| ClientError::Generic(format!("group create error {}", e)))?;
let group = MlsGroup::create_and_insert(
self,
GroupMembershipState::Allowed,
permissions,
Some(self.account_address(),
))
.map_err(|e| ClientError::Generic(format!("group create error {}", e)))?;

Ok(group)
}
Expand Down
9 changes: 3 additions & 6 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ where
}

// Create a new group and save it to the DB
// EM: Consider passing in added_by_id here.....
#[allow(clippy::unwrap_or_default)]
pub fn create_and_insert(
client: &'c Client<ApiClient>,
membership_state: GroupMembershipState,
permissions: Option<PreconfiguredPolicies>,
added_by_address: Option<String>,
) -> Result<Self, GroupError> {
let conn = client.store.conn()?;
let provider = XmtpOpenMlsProvider::new(&conn);
Expand All @@ -210,11 +210,9 @@ where
mls_group.save(provider.key_store())?;

let group_id = mls_group.group_id().to_vec();
// EM: Pass in now added by address
let stored_group = StoredGroup::new(group_id.clone(), now_ns(), membership_state, None);
let stored_group = StoredGroup::new(group_id.clone(), now_ns(), membership_state, added_by_address.clone());
stored_group.store(provider.conn())?;
// EM: Consider passing in added_by_address here.....
Ok(Self::new(client, group_id, stored_group.created_at_ns, None))
Ok(Self::new(client, group_id, stored_group.created_at_ns, added_by_address))
}

// Create a group from a decrypted and decoded welcome message
Expand All @@ -232,7 +230,6 @@ where
mls_group.save(provider.key_store())?;

let group_id = mls_group.group_id().to_vec();
// EM: Store new added_by_address here
let to_store = StoredGroup::new(group_id, now_ns(), GroupMembershipState::Pending, added_by_address.clone());
let stored_group = provider.conn().insert_or_ignore_group(to_store)?;

Expand Down

0 comments on commit 2502163

Please sign in to comment.