diff --git a/bindings/matrix-sdk-ffi/src/sliding_sync.rs b/bindings/matrix-sdk-ffi/src/sliding_sync.rs index 6f149a7fd..0130fff32 100644 --- a/bindings/matrix-sdk-ffi/src/sliding_sync.rs +++ b/bindings/matrix-sdk-ffi/src/sliding_sync.rs @@ -110,11 +110,6 @@ pub enum SlidingSyncError { BadResponse { msg: String, }, - /// Called `.build()` on a builder type, but the given required field was - /// missing. - BuildMissingField { - msg: String, - }, /// A `SlidingSyncListRequestGenerator` has been used without having been /// initialized. It happens when a response is handled before a request has /// been sent. It usually happens when testing. @@ -144,7 +139,6 @@ impl From for SlidingSyncError { match value { E::BadResponse(msg) => Self::BadResponse { msg }, - E::BuildMissingField(msg) => Self::BuildMissingField { msg: msg.to_owned() }, E::RequestGeneratorHasNotBeenInitialized(msg) => { Self::RequestGeneratorHasNotBeenInitialized { msg } } diff --git a/crates/matrix-sdk/src/sliding_sync/builder.rs b/crates/matrix-sdk/src/sliding_sync/builder.rs index b263d5e48..f10aabf53 100644 --- a/crates/matrix-sdk/src/sliding_sync/builder.rs +++ b/crates/matrix-sdk/src/sliding_sync/builder.rs @@ -16,7 +16,7 @@ use ruma::{ use url::Url; use super::{ - cache::restore_sliding_sync_state, Error, SlidingSync, SlidingSyncInner, SlidingSyncList, + cache::restore_sliding_sync_state, SlidingSync, SlidingSyncInner, SlidingSyncList, SlidingSyncPositionMarkers, SlidingSyncRoom, }; use crate::{Client, Result}; @@ -29,7 +29,7 @@ use crate::{Client, Result}; pub struct SlidingSyncBuilder { storage_key: Option, homeserver: Option, - client: Option, + client: Client, lists: BTreeMap, bump_event_types: Vec, extensions: Option, @@ -37,11 +37,11 @@ pub struct SlidingSyncBuilder { } impl SlidingSyncBuilder { - pub(super) fn new() -> Self { + pub(super) fn new(client: Client) -> Self { Self { storage_key: None, homeserver: None, - client: None, + client, lists: BTreeMap::new(), bump_event_types: Vec::new(), extensions: None, @@ -61,12 +61,6 @@ impl SlidingSyncBuilder { self } - /// Set the client this sliding sync will be using. - pub fn client(mut self, value: Client) -> Self { - self.client = Some(value); - self - } - /// Add the given list to the lists. /// /// Replace any list with the name. @@ -207,7 +201,7 @@ impl SlidingSyncBuilder { /// If `self.storage_key` is `Some(_)`, load the cached data from cold /// storage. pub async fn build(mut self) -> Result { - let client = self.client.ok_or(Error::BuildMissingField("client"))?; + let client = self.client; let mut delta_token = None; let mut rooms_found: BTreeMap = BTreeMap::new(); diff --git a/crates/matrix-sdk/src/sliding_sync/client.rs b/crates/matrix-sdk/src/sliding_sync/client.rs index 68bb3ce63..be496f0f0 100644 --- a/crates/matrix-sdk/src/sliding_sync/client.rs +++ b/crates/matrix-sdk/src/sliding_sync/client.rs @@ -8,7 +8,7 @@ use crate::{Client, Result}; impl Client { /// Create a [`SlidingSyncBuilder`] tied to this client. pub async fn sliding_sync(&self) -> SlidingSyncBuilder { - SlidingSync::builder().client(self.clone()) + SlidingSync::builder(self.clone()) } #[instrument(skip(self, response))] diff --git a/crates/matrix-sdk/src/sliding_sync/error.rs b/crates/matrix-sdk/src/sliding_sync/error.rs index bacea352f..41baaef19 100644 --- a/crates/matrix-sdk/src/sliding_sync/error.rs +++ b/crates/matrix-sdk/src/sliding_sync/error.rs @@ -12,10 +12,6 @@ pub enum Error { /// `sync`-restart might be required. #[error("The sliding sync response could not be handled: {0}")] BadResponse(String), - /// Called `.build()` on a builder type, but the given required field was - /// missing. - #[error("Required field missing: `{0}`")] - BuildMissingField(&'static str), /// A `SlidingSyncListRequestGenerator` has been used without having been /// initialized. It happens when a response is handled before a request has /// been sent. It usually happens when testing. diff --git a/crates/matrix-sdk/src/sliding_sync/mod.rs b/crates/matrix-sdk/src/sliding_sync/mod.rs index 583f43993..115e134e4 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -125,8 +125,8 @@ impl SlidingSync { } /// Create a new [`SlidingSyncBuilder`]. - pub fn builder() -> SlidingSyncBuilder { - SlidingSyncBuilder::new() + pub fn builder(client: Client) -> SlidingSyncBuilder { + SlidingSyncBuilder::new(client) } /// Subscribe to a given room.