golgi/src/api/history_stream.rs

34 lines
1.0 KiB
Rust
Raw Normal View History

2022-02-08 09:52:52 +00:00
//! Return a history stream.
//!
//! Implements the following methods:
//!
//! - [`Sbot::create_history_stream`]
2022-02-07 11:54:47 +00:00
use async_std::stream::Stream;
use kuska_ssb::api::dto::CreateHistoryStreamIn;
2022-02-08 08:02:17 +00:00
use crate::{error::GolgiError, messages::SsbMessageValue, sbot::Sbot, utils};
2022-02-07 11:54:47 +00:00
impl Sbot {
/// Call the `createHistoryStream` RPC method
/// and return a Stream of Result<SsbMessageValue, GolgiError>.
pub async fn create_history_stream(
&mut self,
id: String,
) -> Result<impl Stream<Item = Result<SsbMessageValue, GolgiError>>, GolgiError> {
let mut sbot_connection = self.get_sbot_connection().await?;
let args = CreateHistoryStreamIn::new(id);
let req_id = sbot_connection
.client
.create_history_stream_req_send(&args)
.await?;
2022-02-08 08:02:17 +00:00
let history_stream = utils::get_source_stream(
2022-02-07 11:54:47 +00:00
sbot_connection.rpc_reader,
req_id,
utils::ssb_message_res_parse,
)
.await;
Ok(history_stream)
}
}