Mandate a Client when creating a SlidingSyncBuilder
Signed-off-by: Benjamin Bouvier <public@benj.me>
This commit is contained in:
@@ -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<matrix_sdk::sliding_sync::Error> 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 }
|
||||
}
|
||||
|
||||
@@ -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<String>,
|
||||
homeserver: Option<Url>,
|
||||
client: Option<Client>,
|
||||
client: Client,
|
||||
lists: BTreeMap<String, SlidingSyncList>,
|
||||
bump_event_types: Vec<TimelineEventType>,
|
||||
extensions: Option<ExtensionsConfig>,
|
||||
@@ -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<SlidingSync> {
|
||||
let client = self.client.ok_or(Error::BuildMissingField("client"))?;
|
||||
let client = self.client;
|
||||
|
||||
let mut delta_token = None;
|
||||
let mut rooms_found: BTreeMap<OwnedRoomId, SlidingSyncRoom> = BTreeMap::new();
|
||||
|
||||
@@ -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))]
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user