Merge pull request 'Pass complete args struct to create_history_stream' (#56) from create_history_stream_opts into main

Reviewed-on: #56
This commit is contained in:
glyph 2022-08-09 10:15:41 +00:00
commit 9981b64bb2
3 changed files with 19 additions and 10 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "golgi" name = "golgi"
version = "0.2.3" version = "0.2.4"
edition = "2021" edition = "2021"
authors = ["Max Fowler <max@mfowler.info>", "Andrew Reid <glyph@mycelial.technology>"] authors = ["Max Fowler <max@mfowler.info>", "Andrew Reid <glyph@mycelial.technology>"]
readme = "README.md" readme = "README.md"

View File

@ -4,7 +4,10 @@ use async_std::stream::StreamExt;
use futures::TryStreamExt; use futures::TryStreamExt;
use golgi::{ use golgi::{
api::get_subset::{SubsetQuery, SubsetQueryOptions}, api::{
get_subset::{SubsetQuery, SubsetQueryOptions},
history_stream::CreateHistoryStream,
},
messages::{SsbMessageContentType, SsbMessageKVT}, messages::{SsbMessageContentType, SsbMessageKVT},
sbot::Keystore, sbot::Keystore,
GolgiError, Sbot, GolgiError, Sbot,
@ -30,10 +33,11 @@ async fn run() -> Result<(), GolgiError> {
/* HISTORY STREAM EXAMPLE */ /* HISTORY STREAM EXAMPLE */
let history_stream_args = CreateHistoryStream::new(author.to_string());
// Create an ordered stream of all messages authored by the `author` // Create an ordered stream of all messages authored by the `author`
// identity. Messages are returned as KVTs (Key Value Timestamp). // 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(history_stream_args)
.await?; .await?;
// Pin the stream to the stack to allow polling of the `future`. // Pin the stream to the stack to allow polling of the `future`.
@ -61,7 +65,7 @@ async fn run() -> Result<(), GolgiError> {
// 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
.create_history_stream(author.to_string()) .create_history_stream(CreateHistoryStream::new(author.to_string()))
.await?; .await?;
// Collect the stream elements into a `Vec<SsbMessageKVT>` using // Collect the stream elements into a `Vec<SsbMessageKVT>` using
@ -78,7 +82,7 @@ async fn run() -> Result<(), GolgiError> {
// 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
.create_history_stream(author.to_string()) .create_history_stream(CreateHistoryStream::new(author.to_string()))
.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

View File

@ -5,7 +5,7 @@
//! - [`Sbot::create_history_stream`] //! - [`Sbot::create_history_stream`]
use async_std::stream::Stream; use async_std::stream::Stream;
use kuska_ssb::api::dto::CreateHistoryStreamIn; pub use kuska_ssb::api::dto::CreateHistoryStreamIn as CreateHistoryStream;
use crate::{error::GolgiError, messages::SsbMessageKVT, sbot::Sbot, utils}; use crate::{error::GolgiError, messages::SsbMessageKVT, sbot::Sbot, utils};
@ -17,14 +17,20 @@ impl Sbot {
/// ///
/// ```rust /// ```rust
/// use async_std::stream::StreamExt; /// use async_std::stream::StreamExt;
/// use golgi::{Sbot, GolgiError, sbot::Keystore}; /// use golgi::{
/// Sbot,
/// GolgiError,
/// sbot::Keystore,
/// api::history_stream::CreateHistoryStream
/// };
/// ///
/// async fn history() -> Result<(), GolgiError> { /// async fn history() -> Result<(), GolgiError> {
/// let mut sbot_client = Sbot::init(Keystore::Patchwork, None, None).await?; /// let mut sbot_client = Sbot::init(Keystore::Patchwork, None, None).await?;
/// ///
/// let ssb_id = "@zqshk7o2Rpd/OaZ/MxH6xXONgonP1jH+edK9+GZb/NY=.ed25519".to_string(); /// let ssb_id = "@zqshk7o2Rpd/OaZ/MxH6xXONgonP1jH+edK9+GZb/NY=.ed25519".to_string();
/// ///
/// let history_stream = sbot_client.create_history_stream(ssb_id).await?; /// let args = CreateHistoryStream::new(ssb_id);
/// let history_stream = sbot_client.create_history_stream(args).await?;
/// ///
/// history_stream.for_each(|msg| { /// history_stream.for_each(|msg| {
/// match msg { /// match msg {
@ -38,10 +44,9 @@ impl Sbot {
/// ``` /// ```
pub async fn create_history_stream( pub async fn create_history_stream(
&mut self, &mut self,
id: String, args: CreateHistoryStream,
) -> Result<impl Stream<Item = Result<SsbMessageKVT, GolgiError>>, GolgiError> { ) -> Result<impl Stream<Item = Result<SsbMessageKVT, GolgiError>>, GolgiError> {
let mut sbot_connection = self.get_sbot_connection().await?; let mut sbot_connection = self.get_sbot_connection().await?;
let args = CreateHistoryStreamIn::new(id).keys_values(true, true);
let req_id = sbot_connection let req_id = sbot_connection
.client .client
.create_history_stream_req_send(&args) .create_history_stream_req_send(&args)