use std::{fmt, time::Duration};
use ruma::api::client::sync::sync_events;
const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
#[derive(Clone)]
pub struct SyncSettings<'a> {
pub(crate) filter: Option<sync_events::v3::Filter<'a>>,
pub(crate) timeout: Option<Duration>,
pub(crate) token: Option<String>,
pub(crate) full_state: bool,
}
impl<'a> Default for SyncSettings<'a> {
fn default() -> Self {
Self::new()
}
}
impl<'a> fmt::Debug for SyncSettings<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = f.debug_struct("SyncSettings");
macro_rules! opt_field {
($field:ident) => {
if let Some(value) = &self.$field {
s.field(stringify!($field), value);
}
};
}
opt_field!(filter);
opt_field!(timeout);
s.field("full_state", &self.full_state).finish()
}
}
impl<'a> SyncSettings<'a> {
#[must_use]
pub fn new() -> Self {
Self { filter: None, timeout: Some(DEFAULT_SYNC_TIMEOUT), token: None, full_state: false }
}
#[must_use]
pub fn token(mut self, token: impl Into<String>) -> Self {
self.token = Some(token.into());
self
}
#[must_use]
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = Some(timeout);
self
}
#[must_use]
pub fn filter(mut self, filter: sync_events::v3::Filter<'a>) -> Self {
self.filter = Some(filter);
self
}
#[must_use]
pub fn full_state(mut self, full_state: bool) -> Self {
self.full_state = full_state;
self
}
}