golgi/src/api/get_subset.rs

42 lines
1.4 KiB
Rust
Raw Normal View History

2022-02-08 09:52:52 +00:00
//! Perform subset queries.
//!
//! Implements the following methods:
//!
//! - [`Sbot::get_subset_stream`]
2022-02-07 11:54:47 +00:00
use async_std::stream::Stream;
2022-02-08 09:52:52 +00:00
use crate::{error::GolgiError, messages::SsbMessageValue, sbot::Sbot, utils};
2022-02-07 11:54:47 +00:00
2022-02-08 09:52:52 +00:00
// re-export subset-related kuska types
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?;
2022-02-08 09:52:52 +00:00
let get_subset_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(get_subset_stream)
}
}