From 05e25404035f668f0215a89a16dba82a697d3c85 Mon Sep 17 00:00:00 2001 From: glyph Date: Mon, 8 Aug 2022 08:10:13 +0100 Subject: [PATCH] add get_signifier method and call it from get_name --- src/api/about.rs | 49 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) 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 + } }