add subset stream example

This commit is contained in:
glyph 2022-02-16 14:16:57 +02:00
parent e3c70554c6
commit 8a37bfcb61
1 changed files with 34 additions and 0 deletions

View File

@ -4,6 +4,7 @@ use async_std::stream::StreamExt;
use futures::TryStreamExt;
use golgi::{
api::get_subset::{SubsetQuery, SubsetQueryOptions},
messages::{SsbMessageContentType, SsbMessageValue},
GolgiError, Sbot,
};
@ -25,6 +26,8 @@ async fn run() -> Result<(), GolgiError> {
let author = id.clone();
/* HISTORY STREAM EXAMPLE */
// Create an ordered stream of all messages authored by the `author`
// identity.
let history_stream = sbot_client
@ -110,6 +113,37 @@ async fn run() -> Result<(), GolgiError> {
println!("reached end of type stream");
/* SUBSET STREAM EXAMPLE */
// Compose a subset query for `post` message types.
let post_query = SubsetQuery::Type {
op: "type".to_string(),
string: "post".to_string(),
};
// Define the options for the query.
let post_query_opts = SubsetQueryOptions {
descending: Some(true),
keys: None,
page_limit: Some(5),
};
// Return 5 `post` type messages from any author in descending order.
let query_stream = sbot_client
.get_subset_stream(post_query, Some(post_query_opts))
.await?;
println!("looping through post query stream");
// Iterate over the stream and pretty-print each returned message
// value while ignoring any errors.
query_stream.for_each(|msg| match msg {
Ok(val) => println!("{:#?}", val),
Err(_) => (),
});
println!("reached end of post query stream");
Ok(())
}