Client::sync(): expose sync filter

master
Black Hat 2020-07-16 03:49:46 -07:00
parent 2d955027e1
commit 0542e3d83d
1 changed files with 20 additions and 15 deletions

View File

@ -1220,9 +1220,13 @@ impl Client {
/// ///
/// * `sync_settings` - Settings for the sync call. /// * `sync_settings` - Settings for the sync call.
#[instrument] #[instrument]
pub async fn sync(&self, sync_settings: SyncSettings) -> Result<sync_events::Response> { pub async fn sync(
&self,
sync_settings: SyncSettings,
filter: Option<sync_events::Filter>,
) -> Result<sync_events::Response> {
let request = sync_events::Request { let request = sync_events::Request {
filter: None, filter,
since: sync_settings.token, since: sync_settings.token,
full_state: sync_settings.full_state, full_state: sync_settings.full_state,
set_presence: sync_events::SetPresence::Online, set_presence: sync_events::SetPresence::Online,
@ -1297,6 +1301,7 @@ impl Client {
pub async fn sync_forever<C>( pub async fn sync_forever<C>(
&self, &self,
sync_settings: SyncSettings, sync_settings: SyncSettings,
filter: Option<sync_events::Filter>,
callback: impl Fn(sync_events::Response) -> C, callback: impl Fn(sync_events::Response) -> C,
) where ) where
C: Future<Output = ()>, C: Future<Output = ()>,
@ -1309,7 +1314,7 @@ impl Client {
} }
loop { loop {
let response = self.sync(sync_settings.clone()).await; let response = self.sync(sync_settings.clone(), None).await;
let response = match response { let response = match response {
Ok(r) => r, Ok(r) => r,
@ -1561,7 +1566,7 @@ mod test {
let room = client.get_joined_room(&room_id).await; let room = client.get_joined_room(&room_id).await;
assert!(room.is_none()); assert!(room.is_none());
client.sync(SyncSettings::default()).await.unwrap(); client.sync(SyncSettings::default(), None).await.unwrap();
let room = client.get_left_room(&room_id).await; let room = client.get_left_room(&room_id).await;
assert!(room.is_none()); assert!(room.is_none());
@ -1576,7 +1581,7 @@ mod test {
joined_client.restore_login(session).await.unwrap(); joined_client.restore_login(session).await.unwrap();
// joined room reloaded from state store // joined room reloaded from state store
joined_client.sync(SyncSettings::default()).await.unwrap(); joined_client.sync(SyncSettings::default(), None).await.unwrap();
let room = joined_client.get_joined_room(&room_id).await; let room = joined_client.get_joined_room(&room_id).await;
assert!(room.is_some()); assert!(room.is_some());
@ -1588,7 +1593,7 @@ mod test {
.with_body(test_json::LEAVE_SYNC_EVENT.to_string()) .with_body(test_json::LEAVE_SYNC_EVENT.to_string())
.create(); .create();
joined_client.sync(SyncSettings::default()).await.unwrap(); joined_client.sync(SyncSettings::default(), None).await.unwrap();
let room = joined_client.get_joined_room(&room_id).await; let room = joined_client.get_joined_room(&room_id).await;
assert!(room.is_none()); assert!(room.is_none());
@ -1620,7 +1625,7 @@ mod test {
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
let _response = client.sync(sync_settings).await.unwrap(); let _response = client.sync(sync_settings, None).await.unwrap();
// let bc = &client.base_client; // let bc = &client.base_client;
// let ignored_users = bc.ignored_users.read().await; // let ignored_users = bc.ignored_users.read().await;
@ -2243,7 +2248,7 @@ mod test {
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
let _response = client.sync(sync_settings).await.unwrap(); let _response = client.sync(sync_settings, None).await.unwrap();
let rooms_lock = &client.base_client.joined_rooms(); let rooms_lock = &client.base_client.joined_rooms();
let rooms = rooms_lock.read().await; let rooms = rooms_lock.read().await;
@ -2279,7 +2284,7 @@ mod test {
client.restore_login(session).await.unwrap(); client.restore_login(session).await.unwrap();
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
let _response = client.sync(sync_settings).await.unwrap(); let _response = client.sync(sync_settings, None).await.unwrap();
let mut room_names = vec![]; let mut room_names = vec![];
for room in client.joined_rooms().read().await.values() { for room in client.joined_rooms().read().await.values() {
@ -2311,7 +2316,7 @@ mod test {
.with_body(test_json::INVITE_SYNC.to_string()) .with_body(test_json::INVITE_SYNC.to_string())
.create(); .create();
let _response = client.sync(SyncSettings::default()).await.unwrap(); let _response = client.sync(SyncSettings::default(), None).await.unwrap();
assert!(client.joined_rooms().read().await.is_empty()); assert!(client.joined_rooms().read().await.is_empty());
assert!(client.left_rooms().read().await.is_empty()); assert!(client.left_rooms().read().await.is_empty());
@ -2345,7 +2350,7 @@ mod test {
.with_body(test_json::LEAVE_SYNC.to_string()) .with_body(test_json::LEAVE_SYNC.to_string())
.create(); .create();
let _response = client.sync(SyncSettings::default()).await.unwrap(); let _response = client.sync(SyncSettings::default(), None).await.unwrap();
assert!(client.joined_rooms().read().await.is_empty()); assert!(client.joined_rooms().read().await.is_empty());
assert!(!client.left_rooms().read().await.is_empty()); assert!(!client.left_rooms().read().await.is_empty());
@ -2389,14 +2394,14 @@ mod test {
let sync_settings = SyncSettings::new().timeout(std::time::Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(std::time::Duration::from_millis(3000));
// gather state to save to the db, the first time through loading will be skipped // gather state to save to the db, the first time through loading will be skipped
let _ = client.sync(sync_settings.clone()).await.unwrap(); let _ = client.sync(sync_settings.clone(), None).await.unwrap();
// now syncing the client will update from the state store // now syncing the client will update from the state store
let config = let config =
ClientConfig::default().state_store(Box::new(JsonStore::open(dir.path()).unwrap())); ClientConfig::default().state_store(Box::new(JsonStore::open(dir.path()).unwrap()));
let client = Client::new_with_config(homeserver, config).unwrap(); let client = Client::new_with_config(homeserver, config).unwrap();
client.restore_login(session.clone()).await.unwrap(); client.restore_login(session.clone()).await.unwrap();
client.sync(sync_settings).await.unwrap(); client.sync(sync_settings, None).await.unwrap();
let base_client = &client.base_client; let base_client = &client.base_client;
@ -2457,7 +2462,7 @@ mod test {
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
let response = client.sync(sync_settings).await.unwrap(); let response = client.sync(sync_settings, None).await.unwrap();
assert_ne!(response.next_batch, ""); assert_ne!(response.next_batch, "");
@ -2487,7 +2492,7 @@ mod test {
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
let _response = client.sync(sync_settings).await.unwrap(); let _response = client.sync(sync_settings, None).await.unwrap();
let mut names = vec![]; let mut names = vec![];
for r in client.joined_rooms().read().await.values() { for r in client.joined_rooms().read().await.values() {