Skip to content

Commit 86ee02a

Browse files
committed
Merge branch 'main' into johannes/send-queue-media-progress
2 parents 19f0c1a + 10668f2 commit 86ee02a

File tree

23 files changed

+1760
-347
lines changed

23 files changed

+1760
-347
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ reqwest = { version = "0.12.12", default-features = false }
5959
rmp-serde = "1.3.0"
6060
# Be careful to use commits from the https://github.com/ruma/ruma/tree/ruma-0.12
6161
# branch until a proper release with breaking changes happens.
62-
ruma = { git = "https://github.com/ruma/ruma", rev = "a8fd1b0322649bf59e2a5cfc73ab4fe46b21edd7", features = [
62+
ruma = { git = "https://github.com/ruma/ruma", rev = "b4941a991919685345646a230b05b985338ec3f8", features = [
6363
"client-api-c",
6464
"compat-upload-signatures",
6565
"compat-user-id",
@@ -74,8 +74,9 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "a8fd1b0322649bf59e2a5cfc73
7474
"unstable-msc4140",
7575
"unstable-msc4171",
7676
"unstable-msc4278",
77+
"unstable-msc4286",
7778
] }
78-
ruma-common = { git = "https://github.com/ruma/ruma", rev = "a8fd1b0322649bf59e2a5cfc73ab4fe46b21edd7" }
79+
ruma-common = { git = "https://github.com/ruma/ruma", rev = "b4941a991919685345646a230b05b985338ec3f8" }
7980
sentry = "0.36.0"
8081
sentry-tracing = "0.36.0"
8182
serde = "1.0.217"

bindings/matrix-sdk-ffi/src/client.rs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
collections::HashMap,
33
fmt::Debug,
4+
path::PathBuf,
45
sync::{Arc, OnceLock, RwLock},
56
time::Duration,
67
};
@@ -38,6 +39,7 @@ use matrix_sdk::{
3839
sliding_sync::Version as SdkSlidingSyncVersion,
3940
store::RoomLoadSettings as SdkRoomLoadSettings,
4041
AuthApi, AuthSession, Client as MatrixClient, SessionChange, SessionTokens,
42+
STATE_STORE_DATABASE_NAME,
4143
};
4244
use matrix_sdk_ui::{
4345
notification_client::{
@@ -223,13 +225,18 @@ pub struct Client {
223225
pub(crate) utd_hook_manager: OnceLock<Arc<UtdHookManager>>,
224226
session_verification_controller:
225227
Arc<tokio::sync::RwLock<Option<SessionVerificationController>>>,
228+
/// The path to the directory where the state store and the crypto store are
229+
/// located, if the `Client` instance has been built with a SQLite store
230+
/// backend.
231+
store_path: Option<PathBuf>,
226232
}
227233

228234
impl Client {
229235
pub async fn new(
230236
sdk_client: MatrixClient,
231237
enable_oidc_refresh_lock: bool,
232238
session_delegate: Option<Arc<dyn ClientSessionDelegate>>,
239+
store_path: Option<PathBuf>,
233240
) -> Result<Self, ClientError> {
234241
let session_verification_controller: Arc<
235242
tokio::sync::RwLock<Option<SessionVerificationController>>,
@@ -267,6 +274,7 @@ impl Client {
267274
delegate: OnceLock::new(),
268275
utd_hook_manager: OnceLock::new(),
269276
session_verification_controller,
277+
store_path,
270278
};
271279

272280
if enable_oidc_refresh_lock {
@@ -1408,25 +1416,70 @@ impl Client {
14081416

14091417
/// Clear all the non-critical caches for this Client instance.
14101418
///
1419+
/// WARNING: This will clear all the caches, including the base store (state
1420+
/// store), so callers must make sure that any sync is inactive before
1421+
/// calling this method. In particular, the `SyncService` must not be
1422+
/// running. After the method returns, the Client will be in an unstable
1423+
/// state, and it is required that the caller reinstantiates a new
1424+
/// Client instance, be it via dropping the previous and re-creating it,
1425+
/// restarting their application, or any other similar means.
1426+
///
1427+
/// - This will get rid of the backing state store file, if provided.
14111428
/// - This will empty all the room's persisted event caches, so all rooms
14121429
/// will start as if they were empty.
14131430
/// - This will empty the media cache according to the current media
14141431
/// retention policy.
14151432
pub async fn clear_caches(&self) -> Result<(), ClientError> {
1416-
let closure = async || -> Result<_, EventCacheError> {
1433+
let closure = async || -> Result<_, ClientError> {
14171434
// Clean up the media cache according to the current media retention policy.
1418-
self.inner.event_cache_store().lock().await?.clean_up_media_cache().await?;
1435+
self.inner
1436+
.event_cache_store()
1437+
.lock()
1438+
.await
1439+
.map_err(EventCacheError::from)?
1440+
.clean_up_media_cache()
1441+
.await
1442+
.map_err(EventCacheError::from)?;
14191443

14201444
// Clear all the room chunks. It's important to *not* call
14211445
// `EventCacheStore::clear_all_rooms_chunks` here, because there might be live
14221446
// observers of the linked chunks, and that would cause some very bad state
14231447
// mismatch.
14241448
self.inner.event_cache().clear_all_rooms().await?;
14251449

1450+
// Delete the state store file, if it exists.
1451+
if let Some(store_path) = &self.store_path {
1452+
debug!("Removing the state store: {}", store_path.display());
1453+
1454+
// The state store and the crypto store both live in the same store path, so we
1455+
// can't blindly delete the directory.
1456+
//
1457+
// Delete the state store SQLite file, as well as the write-ahead log (WAL) and
1458+
// shared-memory (SHM) files, if they exist.
1459+
1460+
for file_name in [
1461+
PathBuf::from(STATE_STORE_DATABASE_NAME),
1462+
PathBuf::from(format!("{STATE_STORE_DATABASE_NAME}.wal")),
1463+
PathBuf::from(format!("{STATE_STORE_DATABASE_NAME}.shm")),
1464+
] {
1465+
let file_path = store_path.join(file_name);
1466+
if file_path.exists() {
1467+
debug!("Removing file: {}", file_path.display());
1468+
std::fs::remove_file(&file_path).map_err(|err| ClientError::Generic {
1469+
msg: format!(
1470+
"couldn't delete the state store file {}: {err}",
1471+
file_path.display()
1472+
),
1473+
details: None,
1474+
})?;
1475+
}
1476+
}
1477+
}
1478+
14261479
Ok(())
14271480
};
14281481

1429-
Ok(closure().await?)
1482+
closure().await
14301483
}
14311484

14321485
/// Checks if the server supports the report room API.

bindings/matrix-sdk-ffi/src/client_builder.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,14 +568,16 @@ impl ClientBuilder {
568568
inner_builder.cross_process_store_locks_holder_name(holder_name.clone());
569569
}
570570

571-
if let Some(session_paths) = &builder.session_paths {
571+
let store_path = if let Some(session_paths) = &builder.session_paths {
572+
// This is the path where both the state store and the crypto store will live.
572573
let data_path = Path::new(&session_paths.data_path);
574+
// This is the path where the event cache store will live.
573575
let cache_path = Path::new(&session_paths.cache_path);
574576

575577
debug!(
576578
data_path = %data_path.to_string_lossy(),
577-
cache_path = %cache_path.to_string_lossy(),
578-
"Creating directories for data and cache stores.",
579+
event_cache_path = %cache_path.to_string_lossy(),
580+
"Creating directories for data (state and crypto) and cache stores.",
579581
);
580582

581583
fs::create_dir_all(data_path)?;
@@ -604,9 +606,12 @@ impl ClientBuilder {
604606

605607
inner_builder = inner_builder
606608
.sqlite_store_with_config_and_cache_path(sqlite_store_config, Some(cache_path));
609+
610+
Some(data_path.to_owned())
607611
} else {
608612
debug!("Not using a store path.");
609-
}
613+
None
614+
};
610615

611616
// Determine server either from URL, server name or user ID.
612617
inner_builder = match builder.homeserver_cfg {
@@ -718,8 +723,13 @@ impl ClientBuilder {
718723
let sdk_client = inner_builder.build().await?;
719724

720725
Ok(Arc::new(
721-
Client::new(sdk_client, builder.enable_oidc_refresh_lock, builder.session_delegate)
722-
.await?,
726+
Client::new(
727+
sdk_client,
728+
builder.enable_oidc_refresh_lock,
729+
builder.session_delegate,
730+
store_path,
731+
)
732+
.await?,
723733
))
724734
}
725735

bindings/matrix-sdk-ffi/src/timeline/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use matrix_sdk::{
3333
};
3434
use matrix_sdk_ui::timeline::{
3535
self, AttachmentSource, EventItemOrigin, EventSendProgress as SdkEventSendProgress, Profile,
36-
RepliedToEvent, TimelineDetails, TimelineUniqueId as SdkTimelineUniqueId,
36+
TimelineDetails, TimelineUniqueId as SdkTimelineUniqueId,
3737
};
3838
use mime::Mime;
3939
use reply::{InReplyToDetails, RepliedToEventDetails};

crates/matrix-sdk-base/src/response_processors/room/msc4186/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
pub mod extensions;
1616

1717
use std::collections::BTreeMap;
18+
#[cfg(feature = "e2e-encryption")]
19+
use std::collections::BTreeSet;
1820

1921
#[cfg(feature = "e2e-encryption")]
2022
use matrix_sdk_common::deserialized_responses::TimelineEvent;
@@ -104,12 +106,18 @@ pub async fn update_any_room(
104106
room_info.mark_state_partially_synced();
105107
room_info.handle_encryption_state(requested_required_states.for_room(room_id));
106108

107-
#[cfg_attr(not(feature = "e2e-encryption"), allow(unused))]
108-
let new_user_ids = state_events::sync::dispatch_and_get_new_users(
109+
#[cfg(feature = "e2e-encryption")]
110+
let mut new_user_ids = BTreeSet::new();
111+
112+
#[cfg(not(feature = "e2e-encryption"))]
113+
let mut new_user_ids = ();
114+
115+
state_events::sync::dispatch(
109116
context,
110117
(&raw_state_events, &state_events),
111118
&mut room_info,
112119
ambiguity_cache,
120+
&mut new_user_ids,
113121
)
114122
.await?;
115123

crates/matrix-sdk-base/src/response_processors/room/sync_v2.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ pub async fn update_joined_room(
6363

6464
let (raw_state_events, state_events) = state_events::sync::collect(&joined_room.state.events);
6565

66-
let mut new_user_ids = state_events::sync::dispatch_and_get_new_users(
66+
let mut new_user_ids = BTreeSet::new();
67+
68+
state_events::sync::dispatch(
6769
context,
6870
(&raw_state_events, &state_events),
6971
&mut room_info,
7072
ambiguity_cache,
73+
&mut new_user_ids,
7174
)
7275
.await?;
7376

@@ -80,15 +83,14 @@ pub async fn update_joined_room(
8083
let (raw_state_events_from_timeline, state_events_from_timeline) =
8184
state_events::sync::collect_from_timeline(&joined_room.timeline.events);
8285

83-
let mut other_new_user_ids = state_events::sync::dispatch_and_get_new_users(
86+
state_events::sync::dispatch(
8487
context,
8588
(&raw_state_events_from_timeline, &state_events_from_timeline),
8689
&mut room_info,
8790
ambiguity_cache,
91+
&mut new_user_ids,
8892
)
8993
.await?;
90-
new_user_ids.append(&mut other_new_user_ids);
91-
updated_members_in_room.insert(room_id.to_owned(), new_user_ids.clone());
9294

9395
#[cfg(feature = "e2e-encryption")]
9496
let olm_machine = e2ee.olm_machine;
@@ -132,6 +134,8 @@ pub async fn update_joined_room(
132134
)
133135
.await?;
134136

137+
updated_members_in_room.insert(room_id.to_owned(), new_user_ids);
138+
135139
let notification_count = joined_room.unread_notifications.into();
136140
room_info.update_notification_count(notification_count);
137141

@@ -175,22 +179,24 @@ pub async fn update_left_room(
175179

176180
let (raw_state_events, state_events) = state_events::sync::collect(&left_room.state.events);
177181

178-
let _ = state_events::sync::dispatch_and_get_new_users(
182+
state_events::sync::dispatch(
179183
context,
180184
(&raw_state_events, &state_events),
181185
&mut room_info,
182186
ambiguity_cache,
187+
&mut (),
183188
)
184189
.await?;
185190

186191
let (raw_state_events_from_timeline, state_events_from_timeline) =
187192
state_events::sync::collect_from_timeline(&left_room.timeline.events);
188193

189-
let _ = state_events::sync::dispatch_and_get_new_users(
194+
state_events::sync::dispatch(
190195
context,
191196
(&raw_state_events_from_timeline, &state_events_from_timeline),
192197
&mut room_info,
193198
ambiguity_cache,
199+
&mut (),
194200
)
195201
.await?;
196202

0 commit comments

Comments
 (0)