-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 1:1 groups to node bindings (#1199)
* Add inner client accessor on client * Move inbox id methods into separate mod * Move consent state methods into mod * Move inbox state method into mod * Add sort direction to NapiListMessagesOptions * Add dm_peer_inbox_id to NapiGroup * Update NapiListConversationsOptions * Add create_dm to NapiConversations * Add list_groups and list_dms * Update conversation streaming methods * Add error logging during tests * Add signatures mod * Add tests * Clippy updates * Remove .only on some tests * Update bindings_node/src/conversations.rs Co-authored-by: Andrew Plaza <github.tech@liquidthink.net> --------- Co-authored-by: Andrew Plaza <github.tech@liquidthink.net>
- Loading branch information
Showing
11 changed files
with
711 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::ErrorWrapper; | ||
use napi::bindgen_prelude::Result; | ||
use napi_derive::napi; | ||
use xmtp_api_grpc::grpc_api_helper::Client as TonicApiClient; | ||
use xmtp_id::associations::generate_inbox_id as xmtp_id_generate_inbox_id; | ||
use xmtp_mls::api::ApiClientWrapper; | ||
use xmtp_mls::retry::Retry; | ||
|
||
#[napi] | ||
pub async fn get_inbox_id_for_address( | ||
host: String, | ||
is_secure: bool, | ||
account_address: String, | ||
) -> Result<Option<String>> { | ||
let account_address = account_address.to_lowercase(); | ||
let api_client = ApiClientWrapper::new( | ||
TonicApiClient::create(host.clone(), is_secure) | ||
.await | ||
.map_err(ErrorWrapper::from)?, | ||
Retry::default(), | ||
); | ||
|
||
let results = api_client | ||
.get_inbox_ids(vec![account_address.clone()]) | ||
.await | ||
.map_err(ErrorWrapper::from)?; | ||
|
||
Ok(results.get(&account_address).cloned()) | ||
} | ||
|
||
#[napi] | ||
pub fn generate_inbox_id(account_address: String) -> String { | ||
let account_address = account_address.to_lowercase(); | ||
// ensure that the nonce is always 1 for now since this will only be used for the | ||
// create_client function above, which also has a hard-coded nonce of 1 | ||
xmtp_id_generate_inbox_id(&account_address, &1) | ||
} |
Oops, something went wrong.