diff --git a/src/api/about.rs b/src/api/about.rs index 831266b..0987691 100644 --- a/src/api/about.rs +++ b/src/api/about.rs @@ -10,6 +10,7 @@ //! - [`Sbot::get_name`] //! - [`Sbot::get_name_and_image`] //! - [`Sbot::get_profile_info`] +//! - [`Sbot::get_signifier`] use std::collections::HashMap; @@ -407,18 +408,7 @@ impl Sbot { /// } /// ``` pub async fn get_name(&mut self, ssb_id: &str) -> Result { - let mut sbot_connection = self.get_sbot_connection().await?; - let req_id = sbot_connection - .client - .names_get_signifier_req_send(ssb_id) - .await?; - - utils::get_async( - &mut sbot_connection.rpc_reader, - req_id, - utils::string_res_parse, - ) - .await + self.get_signifier(ssb_id).await } /// Get the latest `description` value for a peer. @@ -445,4 +435,39 @@ impl Sbot { pub async fn get_description(&mut self, ssb_id: &str) -> Result, GolgiError> { self.get_latest_about_message(ssb_id, "description").await } + + /// Get the latest `name` value (signifier) for a peer. The public key of + /// the peer will be returned if no `name` value is found. + /// + /// # Example + /// + /// ```rust + /// use golgi::{Sbot, GolgiError, sbot::Keystore}; + /// + /// async fn name_info() -> Result<(), GolgiError> { + /// let mut sbot_client = Sbot::init(Keystore::Patchwork, None, None).await?; + /// + /// let ssb_id = "@zqshk7o2Rpd/OaZ/MxH6xXONgonP1jH+edK9+GZb/NY=.ed25519"; + /// + /// let name = sbot_client.get_signifier(ssb_id).await?; + /// + /// println!("peer {} is named {}", ssb_id, name); + /// + /// Ok(()) + /// } + /// ``` + pub async fn get_signifier(&mut self, ssb_id: &str) -> Result { + let mut sbot_connection = self.get_sbot_connection().await?; + let req_id = sbot_connection + .client + .names_get_signifier_req_send(ssb_id) + .await?; + + utils::get_async( + &mut sbot_connection.rpc_reader, + req_id, + utils::string_res_parse, + ) + .await + } }