Skip to content

Commit

Permalink
Explicitly pass OpenMlsProvider to metadata functions (#972)
Browse files Browse the repository at this point in the history
Explicitly pass OpenMlsProvider to metadata functions

- allow caller to choose whether to use an existing connection or new one
  • Loading branch information
insipx authored Aug 19, 2024
1 parent 27b2b44 commit 74ff8be
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 123 deletions.
17 changes: 9 additions & 8 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,8 @@ impl FfiGroup {
self.created_at_ns,
);

let group_name = group.group_name()?;
let provider = group.mls_provider()?;
let group_name = group.group_name(&provider)?;

Ok(group_name)
}
Expand Down Expand Up @@ -1026,7 +1027,7 @@ impl FfiGroup {
self.created_at_ns,
);

let group_image_url_square = group.group_image_url_square()?;
let group_image_url_square = group.group_image_url_square(group.mls_provider()?)?;

Ok(group_image_url_square)
}
Expand Down Expand Up @@ -1055,7 +1056,7 @@ impl FfiGroup {
self.created_at_ns,
);

let group_description = group.group_description()?;
let group_description = group.group_description(group.mls_provider()?)?;

Ok(group_description)
}
Expand Down Expand Up @@ -1084,7 +1085,7 @@ impl FfiGroup {
self.created_at_ns,
);

let group_pinned_frame_url = group.group_pinned_frame_url()?;
let group_pinned_frame_url = group.group_pinned_frame_url(group.mls_provider()?)?;

Ok(group_pinned_frame_url)
}
Expand All @@ -1096,7 +1097,7 @@ impl FfiGroup {
self.created_at_ns,
);

let admin_list = group.admin_list()?;
let admin_list = group.admin_list(group.mls_provider()?)?;

Ok(admin_list)
}
Expand All @@ -1108,7 +1109,7 @@ impl FfiGroup {
self.created_at_ns,
);

let super_admin_list = group.super_admin_list()?;
let super_admin_list = group.super_admin_list(group.mls_provider()?)?;

Ok(super_admin_list)
}
Expand Down Expand Up @@ -1238,7 +1239,7 @@ impl FfiGroup {
self.created_at_ns,
);

Ok(group.is_active()?)
Ok(group.is_active(group.mls_provider()?)?)
}

pub fn added_by_inbox_id(&self) -> Result<String, GenericError> {
Expand All @@ -1258,7 +1259,7 @@ impl FfiGroup {
self.created_at_ns,
);

let metadata = group.metadata()?;
let metadata = group.metadata(group.mls_provider()?)?;
Ok(Arc::new(FfiGroupMetadata {
inner: Arc::new(metadata),
}))
Expand Down
90 changes: 43 additions & 47 deletions bindings_node/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
mls_client::RustXmtpClient,
permissions::NapiGroupPermissions,
streams::NapiStreamCloser,
ErrorWrapper,
};

use prost::Message;
Expand Down Expand Up @@ -100,7 +101,7 @@ impl NapiGroup {
&self.inner_client,
)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;
Ok(hex::encode(message_id.clone()))
}

Expand All @@ -116,7 +117,7 @@ impl NapiGroup {

let id = group
.send_message_optimistic(encoded_content.encode_to_vec().as_slice())
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(id)
}
Expand All @@ -132,7 +133,7 @@ impl NapiGroup {
group
.publish_messages(&self.inner_client)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;
Ok(())
}

Expand All @@ -147,7 +148,7 @@ impl NapiGroup {
group
.sync(&self.inner_client)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand Down Expand Up @@ -180,7 +181,7 @@ impl NapiGroup {
delivery_status,
opts.limit,
)
.map_err(|e| Error::from_reason(format!("{}", e)))?
.map_err(ErrorWrapper::from)?
.into_iter()
.map(|msg| msg.into())
.collect();
Expand All @@ -202,7 +203,7 @@ impl NapiGroup {
let message = group
.process_streamed_group_message(envelope_bytes, self.inner_client.clone())
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(message.into())
}
Expand All @@ -217,7 +218,7 @@ impl NapiGroup {

let members: Vec<NapiGroupMember> = group
.members()
.map_err(|e| Error::from_reason(format!("{}", e)))?
.map_err(ErrorWrapper::from)?
.into_iter()
.map(|member| NapiGroupMember {
inbox_id: member.inbox_id,
Expand Down Expand Up @@ -247,8 +248,8 @@ impl NapiGroup {
);

let admin_list = group
.admin_list()
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.admin_list(group.mls_provider().map_err(ErrorWrapper::from)?)
.map_err(ErrorWrapper::from)?;

Ok(admin_list)
}
Expand All @@ -262,25 +263,21 @@ impl NapiGroup {
);

let super_admin_list = group
.super_admin_list()
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.super_admin_list(group.mls_provider().map_err(ErrorWrapper::from)?)
.map_err(ErrorWrapper::from)?;

Ok(super_admin_list)
}

#[napi]
pub fn is_admin(&self, inbox_id: String) -> Result<bool> {
let admin_list = self
.admin_list()
.map_err(|e| Error::from_reason(format!("{}", e)))?;
let admin_list = self.admin_list().map_err(ErrorWrapper::from)?;
Ok(admin_list.contains(&inbox_id))
}

#[napi]
pub fn is_super_admin(&self, inbox_id: String) -> Result<bool> {
let super_admin_list = self
.super_admin_list()
.map_err(|e| Error::from_reason(format!("{}", e)))?;
let super_admin_list = self.super_admin_list().map_err(ErrorWrapper::from)?;
Ok(super_admin_list.contains(&inbox_id))
}

Expand All @@ -295,7 +292,7 @@ impl NapiGroup {
group
.add_members(&self.inner_client, account_addresses)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -310,7 +307,7 @@ impl NapiGroup {
group
.update_admin_list(&self.inner_client, UpdateAdminListType::Add, inbox_id)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -325,7 +322,7 @@ impl NapiGroup {
group
.update_admin_list(&self.inner_client, UpdateAdminListType::Remove, inbox_id)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -340,7 +337,7 @@ impl NapiGroup {
group
.update_admin_list(&self.inner_client, UpdateAdminListType::AddSuper, inbox_id)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -359,7 +356,7 @@ impl NapiGroup {
inbox_id,
)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -372,9 +369,7 @@ impl NapiGroup {
self.created_at_ns,
);

let permissions = group
.permissions()
.map_err(|e| Error::from_reason(format!("{}", e)))?;
let permissions = group.permissions().map_err(ErrorWrapper::from)?;

Ok(NapiGroupPermissions::new(permissions))
}
Expand All @@ -390,7 +385,7 @@ impl NapiGroup {
group
.add_members_by_inbox_id(&self.inner_client, inbox_ids)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -406,7 +401,7 @@ impl NapiGroup {
group
.remove_members(&self.inner_client, account_addresses)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -422,7 +417,7 @@ impl NapiGroup {
group
.remove_members_by_inbox_id(&self.inner_client, inbox_ids)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -438,7 +433,7 @@ impl NapiGroup {
group
.update_group_name(&self.inner_client, group_name)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -452,8 +447,8 @@ impl NapiGroup {
);

let group_name = group
.group_name()
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.group_name(group.mls_provider().map_err(ErrorWrapper::from)?)
.map_err(ErrorWrapper::from)?;

Ok(group_name)
}
Expand All @@ -469,7 +464,7 @@ impl NapiGroup {
group
.update_group_image_url_square(&self.inner_client, group_image_url_square)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -483,8 +478,8 @@ impl NapiGroup {
);

let group_image_url_square = group
.group_image_url_square()
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.group_image_url_square(group.mls_provider().map_err(ErrorWrapper::from)?)
.map_err(ErrorWrapper::from)?;

Ok(group_image_url_square)
}
Expand All @@ -500,7 +495,7 @@ impl NapiGroup {
group
.update_group_description(&self.inner_client, group_description)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -514,8 +509,8 @@ impl NapiGroup {
);

let group_description = group
.group_description()
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.group_description(group.mls_provider().map_err(ErrorWrapper::from)?)
.map_err(ErrorWrapper::from)?;

Ok(group_description)
}
Expand All @@ -531,7 +526,7 @@ impl NapiGroup {
group
.update_group_pinned_frame_url(&self.inner_client, pinned_frame_url)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.map_err(ErrorWrapper::from)?;

Ok(())
}
Expand All @@ -545,7 +540,7 @@ impl NapiGroup {
);

let group_pinned_frame_url = group
.group_pinned_frame_url()
.group_pinned_frame_url(group.mls_provider().map_err(ErrorWrapper::from)?)
.map_err(|e| Error::from_reason(format!("{}", e)))?;

Ok(group_pinned_frame_url)
Expand Down Expand Up @@ -580,9 +575,11 @@ impl NapiGroup {
self.created_at_ns,
);

group
.is_active()
.map_err(|e| Error::from_reason(format!("{}", e)))
Ok(
group
.is_active(group.mls_provider().map_err(ErrorWrapper::from)?)
.map_err(ErrorWrapper::from)?,
)
}

#[napi]
Expand All @@ -593,9 +590,7 @@ impl NapiGroup {
self.created_at_ns,
);

group
.added_by_inbox_id()
.map_err(|e| Error::from_reason(format!("{}", e)))
Ok(group.added_by_inbox_id().map_err(ErrorWrapper::from)?)
}

#[napi]
Expand All @@ -607,8 +602,9 @@ impl NapiGroup {
);

let metadata = group
.metadata()
.map_err(|e| Error::from_reason(format!("{}", e)))?;
.metadata(group.mls_provider().map_err(ErrorWrapper::from)?)
.map_err(ErrorWrapper::from)?;

Ok(NapiGroupMetadata { inner: metadata })
}
}
Loading

0 comments on commit 74ff8be

Please sign in to comment.