golgi/examples/ssb-stream-example.rs

98 lines
2.7 KiB
Rust

use std::process;
use golgi::error::GolgiError;
use golgi::sbot::Sbot;
use async_std::stream::StreamExt;
use futures::pin_mut;
async fn run() -> Result<(), GolgiError> {
let mut sbot_client = Sbot::init(None, None).await?;
let id = sbot_client.whoami().await?;
println!("{}", id);
//
// let name = SsbMessageContent::About {
// about: id,
// name: Some("golgi".to_string()),
// title: None,
// branch: None,
// image: None,
// description: None,
// location: None,
// start_datetime: None,
// };
//
// let name_msg_ref = sbot_client.publish(name).await?;
// println!("{}", name_msg_ref);
//
// let post = SsbMessageContent::Post {
// text: "golgi go womp womp".to_string(),
// mentions: None,
// };
//
// let post_msg_ref = sbot_client.publish(post).await?;
// println!("{}", post_msg_ref);
//
// let post_msg_ref = sbot_client.publish_description("this is a description").await?;
// println!("description: {}", post_msg_ref);
let author = "@L/z54cbc8V1kL1/MiBhpEKuN3QJkSoZYNaukny3ghIs=.ed25519";
// let query = SubsetQuery::Author{
// op: "author".to_string(),
// feed: author
// };
//
// let kvts = sbot_client.get_subset(query).await?;
//
// for kvt in kvts {
// println!("kvt: {:?}", kvt);
// }
// let about_messages = sbot_client.get_about_messages(author).await?;
// for msg in about_messages {
// println!("msg: {:?}", msg);
// }
//
// sbot_client.publish_name("this is my new name").await?;
// let name = sbot_client.get_name(author).await?;
// println!("name: {:?}", name);
//
// // sbot_client.publish_description("this is test description 99").await?;
//
// let description = sbot_client.get_description(author).await?;
// println!("desc: {:?}", description);
//
// let description2 = sbot_client.get_latest_about_message(author, "description").await?;
// println!("desc2: {:?}", description2);
let mut history_stream = sbot_client.create_history_stream(author.to_string()).await?;
pin_mut!(history_stream); // needed for iteration
while let Some(res) = history_stream.next().await {
match res {
Ok(value) => {
println!("value: {:?}", value);
},
Err(err) => {
println!("err: {:?}", err);
}
}
}
println!("exit loop");
Ok(())
}
#[async_std::main]
async fn main() {
if let Err(e) = run().await {
eprintln!("Application error: {}", e);
process::exit(1);
}
}