Replace verbose get_description with more concise version
This commit is contained in:
parent
be19fcbfc4
commit
961f817a8b
30
src/sbot.rs
30
src/sbot.rs
|
@ -191,32 +191,6 @@ impl Sbot {
|
||||||
Ok(about_messages)
|
Ok(about_messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the latest description for a particular user from their about messages.
|
|
||||||
pub async fn get_description(&mut self, ssb_id: &str) -> Result<Option<String>, GolgiError> {
|
|
||||||
// vector of about messages with most recent at the front of the vector
|
|
||||||
let about_messages = self.get_about_messages(ssb_id).await?;
|
|
||||||
// iterate through the vector looking for an about message with a description
|
|
||||||
// the first one we find is th emost recnet
|
|
||||||
for msg in about_messages {
|
|
||||||
let about_message = msg.into_ssb_message_content()?;
|
|
||||||
match about_message {
|
|
||||||
SsbMessageContent::About{description, ..} => {
|
|
||||||
match description {
|
|
||||||
Some(description_text) => {
|
|
||||||
return Ok(Some(description_text))
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if no about message with a description was found, then return the empty string
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get value of latest about message with given key from given user
|
/// Get value of latest about message with given key from given user
|
||||||
pub async fn get_latest_about_message(&mut self, ssb_id: &str, key: &str) -> Result<Option<String>, GolgiError> {
|
pub async fn get_latest_about_message(&mut self, ssb_id: &str, key: &str) -> Result<Option<String>, GolgiError> {
|
||||||
// vector of about messages with most recent at the front of the vector
|
// vector of about messages with most recent at the front of the vector
|
||||||
|
@ -252,6 +226,10 @@ impl Sbot {
|
||||||
self.get_latest_about_message(ssb_id, "name").await
|
self.get_latest_about_message(ssb_id, "name").await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_description(&mut self, ssb_id: &str) -> Result<Option<String>, GolgiError> {
|
||||||
|
self.get_latest_about_message(ssb_id, "description").await
|
||||||
|
}
|
||||||
|
|
||||||
/// Call the `createHistoryStream` RPC method and return a vector
|
/// Call the `createHistoryStream` RPC method and return a vector
|
||||||
/// of SsbMessageValue.
|
/// of SsbMessageValue.
|
||||||
pub async fn create_history_stream(
|
pub async fn create_history_stream(
|
||||||
|
|
Loading…
Reference in New Issue