golgi/src/sbot/get_subset.rs

36 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-07 12:07:48 +00:00
error::GolgiError, messages::SsbMessageValue, sbot::sbot_connection::Sbot, utils,
utils::get_source_stream, 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)
}
}