replace SsbMessageValue with SsbMessageKVT in stream examples
This commit is contained in:
parent
1c44f0e56a
commit
15acebbbfa
|
@ -5,7 +5,7 @@ use futures::TryStreamExt;
|
||||||
|
|
||||||
use golgi::{
|
use golgi::{
|
||||||
api::get_subset::{SubsetQuery, SubsetQueryOptions},
|
api::get_subset::{SubsetQuery, SubsetQueryOptions},
|
||||||
messages::{SsbMessageContentType, SsbMessageValue},
|
messages::{SsbMessageContentType, SsbMessageKVT},
|
||||||
sbot::Keystore,
|
sbot::Keystore,
|
||||||
GolgiError, Sbot,
|
GolgiError, Sbot,
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,7 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
/* HISTORY STREAM EXAMPLE */
|
/* 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. Messages are returned as KVTs (Key Value Timestamp).
|
||||||
let history_stream = sbot_client
|
let history_stream = sbot_client
|
||||||
.create_history_stream(author.to_string())
|
.create_history_stream(author.to_string())
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -42,12 +42,12 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
println!("looping through stream");
|
println!("looping through stream");
|
||||||
|
|
||||||
// Iterate through each element in the stream and match on the `Result`.
|
// Iterate through each element in the stream and match on the `Result`.
|
||||||
// In this case, each element has type `Result<SsbMessageValue, GolgiError>`.
|
// In this case, each element has type `Result<SsbMessageKVT, GolgiError>`.
|
||||||
while let Some(res) = history_stream.next().await {
|
while let Some(res) = history_stream.next().await {
|
||||||
match res {
|
match res {
|
||||||
Ok(value) => {
|
Ok(kvt) => {
|
||||||
// Print the `SsbMessageValue` of this element to `stdout`.
|
// Print the `SsbMessageKVT` of this element to `stdout`.
|
||||||
println!("value: {:?}", value);
|
println!("kvt: {:?}", kvt);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Print the `GolgiError` of this element to `stderr`.
|
// Print the `GolgiError` of this element to `stderr`.
|
||||||
|
@ -64,12 +64,12 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
.create_history_stream(author.to_string())
|
.create_history_stream(author.to_string())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Collect the stream elements into a `Vec<SsbMessageValue>` using
|
// Collect the stream elements into a `Vec<SsbMessageKVT>` using
|
||||||
// `try_collect`. A `GolgiError` will be returned from the `run`
|
// `try_collect`. A `GolgiError` will be returned from the `run`
|
||||||
// function if any element contains an error.
|
// function if any element contains an error.
|
||||||
let results: Vec<SsbMessageValue> = history_stream.try_collect().await?;
|
let results: Vec<SsbMessageKVT> = history_stream.try_collect().await?;
|
||||||
|
|
||||||
// Loop through the `SsbMessageValue` elements, printing each one
|
// Loop through the `SsbMessageKVT` elements, printing each one
|
||||||
// to `stdout`.
|
// to `stdout`.
|
||||||
for x in results {
|
for x in results {
|
||||||
println!("x: {:?}", x);
|
println!("x: {:?}", x);
|
||||||
|
@ -82,13 +82,14 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Iterate through the elements in the stream and use `map` to convert
|
// Iterate through the elements in the stream and use `map` to convert
|
||||||
// each `SsbMessageValue` element into a tuple of
|
// each `SsbMessageKVT` element into a tuple of
|
||||||
// `(String, SsbMessageContentType)`. This is an example of stream
|
// `(String, SsbMessageContentType)`. This is an example of stream
|
||||||
// conversion.
|
// conversion.
|
||||||
let type_stream = history_stream.map(|msg| match msg {
|
let type_stream = history_stream.map(|msg| match msg {
|
||||||
Ok(val) => {
|
Ok(kvt) => {
|
||||||
let message_type = val.get_message_type()?;
|
let message_type = kvt.value.get_message_type()?;
|
||||||
let tuple: (String, SsbMessageContentType) = (val.signature, message_type);
|
// Return the message key and type.
|
||||||
|
let tuple: (String, SsbMessageContentType) = (kvt.key, message_type);
|
||||||
Ok(tuple)
|
Ok(tuple)
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
|
|
Loading…
Reference in New Issue