add subset stream example
This commit is contained in:
parent
e3c70554c6
commit
8a37bfcb61
|
@ -4,6 +4,7 @@ use async_std::stream::StreamExt;
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
use golgi::{
|
use golgi::{
|
||||||
|
api::get_subset::{SubsetQuery, SubsetQueryOptions},
|
||||||
messages::{SsbMessageContentType, SsbMessageValue},
|
messages::{SsbMessageContentType, SsbMessageValue},
|
||||||
GolgiError, Sbot,
|
GolgiError, Sbot,
|
||||||
};
|
};
|
||||||
|
@ -25,6 +26,8 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
|
|
||||||
let author = id.clone();
|
let author = id.clone();
|
||||||
|
|
||||||
|
/* HISTORY STREAM EXAMPLE */
|
||||||
|
|
||||||
// Create an ordered stream of all messages authored by the `author`
|
// Create an ordered stream of all messages authored by the `author`
|
||||||
// identity.
|
// identity.
|
||||||
let history_stream = sbot_client
|
let history_stream = sbot_client
|
||||||
|
@ -110,6 +113,37 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
|
|
||||||
println!("reached end of type stream");
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue