From 10adb6d26bd91ed4d848d15c874ce1f4651ebf3c Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 16 Feb 2023 11:23:05 +0100 Subject: [PATCH 1/2] chore(sdk): Use appropriate type to remove the need of a comment. By using `Default::default` for the parameter value, we don't know which type we are passing to the function. Hence the useful comment `room_info.ephemeral`. This patch changes this to `Ephemeral::default`, so that we now know what we pass without the need of a comment. --- crates/matrix-sdk-base/src/sliding_sync.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index 7bc4c9c2a..054913685 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -1,7 +1,10 @@ #[cfg(feature = "e2e-encryption")] use std::ops::Deref; -use ruma::api::client::sync::sync_events::{v3, v4}; +use ruma::api::client::sync::sync_events::{ + v3::{self, Ephemeral}, + v4, +}; #[cfg(feature = "e2e-encryption")] use ruma::UserId; use tracing::{debug, info, instrument}; @@ -207,7 +210,7 @@ impl BaseClient { timeline, v3::State::with_events(room_data.required_state.clone()), room_account_data.unwrap_or_default(), - Default::default(), // room_info.ephemeral, + Ephemeral::default(), notification_count, ), ); From 1c0288e42bcc686ab0b1cfb3f73d12f6a1cc2b16 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 16 Feb 2023 11:49:21 +0100 Subject: [PATCH 2/2] chore(sdk): Simplify code by removing a `map`. In the code `if let Some(global_data) = account_data.as_ref().map(|a| &a.global)`, the `map` is not purely necessary. This patch simplifies the code to remove the `map` and read the `global` field later on. --- crates/matrix-sdk-base/src/sliding_sync.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index 054913685..4a7dde386 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -90,8 +90,8 @@ impl BaseClient { let mut changes = StateChanges::default(); let mut ambiguity_cache = AmbiguityCache::new(store.inner.clone()); - if let Some(global_data) = account_data.as_ref().map(|a| &a.global) { - self.handle_account_data(global_data, &mut changes).await; + if let Some(global_data) = account_data.as_ref() { + self.handle_account_data(&global_data.global, &mut changes).await; } let push_rules = self.get_push_rules(&changes).await?; @@ -223,8 +223,8 @@ impl BaseClient { // because we want to have the push rules in place before we process // rooms and their events, but we want to create the rooms before we // process the `m.direct` account data event. - if let Some(global_data) = account_data.as_ref().map(|a| &a.global) { - self.handle_account_data(global_data, &mut changes).await; + if let Some(global_data) = account_data.as_ref() { + self.handle_account_data(&global_data.global, &mut changes).await; } // FIXME not yet supported by sliding sync.