golgi/src/api/get_subset.rs

37 lines
1.2 KiB
Rust
Raw Normal View History

2022-02-07 11:54:47 +00:00
use async_std::stream::Stream;
use crate::{
2022-02-08 08:02:17 +00:00
error::GolgiError, messages::SsbMessageValue, sbot::Sbot, utils, utils::get_source_stream,
2022-02-07 11:54:47 +00:00
};
2022-02-07 12:44:17 +00:00
pub use kuska_ssb::api::dto::content::{SubsetQuery, SubsetQueryOptions};
2022-02-07 11:54:47 +00:00
impl Sbot {
/// Call the `partialReplication getSubset` RPC method
/// and return a Stream of Result<SsbMessageValue, GolgiError>
///
/// # Arguments
///
/// * `query` - A `SubsetQuery` which specifies what filters to use.
/// * `option` - An Option<`SubsetQueryOptions`> which, if provided, adds additional
/// specifications to the query, such as specifying page limit and/or descending.
pub async fn get_subset_stream(
&mut self,
query: SubsetQuery,
options: Option<SubsetQueryOptions>,
) -> Result<impl Stream<Item = Result<SsbMessageValue, GolgiError>>, GolgiError> {
let mut sbot_connection = self.get_sbot_connection().await?;
let req_id = sbot_connection
.client
.getsubset_req_send(query, options)
.await?;
let get_subset_stream = get_source_stream(
sbot_connection.rpc_reader,
req_id,
utils::ssb_message_res_parse,
)
.await;
Ok(get_subset_stream)
}
}