diff --git a/Cargo.lock b/Cargo.lock index ac64a0a39..a9aceb3a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,19 +1242,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.1", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "data-encoding" version = "2.4.0" @@ -3062,7 +3049,6 @@ dependencies = [ "cfg-vis", "chrono", "ctor", - "dashmap", "dirs", "event-listener 3.0.0", "eyeball", diff --git a/Cargo.toml b/Cargo.toml index d2d9135a6..8331906ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ as_variant = "1.2.0" base64 = "0.21.0" byteorder = "1.4.3" ctor = "0.2.0" -dashmap = "5.2.0" eyeball = { version = "0.8.7", features = ["tracing"] } eyeball-im = { version = "0.4.1", features = ["tracing"] } eyeball-im-util = "0.5.1" diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index b19cec4a5..064e701ed 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -70,7 +70,6 @@ bytes = "1.1.0" bytesize = "1.1" cfg-vis = "0.3.0" chrono = { version = "0.4.23", optional = true } -dashmap = { workspace = true } event-listener = "3.0.0" eyeball = { workspace = true } eyeball-im = { workspace = true } diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 0911e4588..29a9f1e42 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -22,7 +22,6 @@ use std::{ sync::{Arc, Mutex as StdMutex, RwLock as StdRwLock}, }; -use dashmap::DashMap; use eyeball::{SharedObservable, Subscriber}; use futures_core::Stream; #[cfg(feature = "e2e-encryption")] @@ -205,7 +204,7 @@ pub(crate) struct ClientInner { /// to ensure that only a single call to a method happens at once or to /// deduplicate multiple calls to a method. locks: ClientLocks, - pub(crate) typing_notice_times: DashMap, + pub(crate) typing_notice_times: StdRwLock>, /// Event handlers. See `add_event_handler`. pub(crate) event_handlers: EventHandlerStore, /// Notification handlers. See `register_notification_handler`. diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index 5422be96b..2d0dbb09e 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -1041,24 +1041,24 @@ impl Room { self.ensure_room_joined()?; // Only send a request to the homeserver if the old timeout has elapsed - // or the typing notice changed state within the - // TYPING_NOTICE_TIMEOUT - let send = - if let Some(typing_time) = self.client.inner.typing_notice_times.get(self.room_id()) { - if typing_time.elapsed() > TYPING_NOTICE_RESEND_TIMEOUT { - // We always reactivate the typing notice if typing is true or - // we may need to deactivate it if it's - // currently active if typing is false - typing || typing_time.elapsed() <= TYPING_NOTICE_TIMEOUT - } else { - // Only send a request when we need to deactivate typing - !typing - } + // or the typing notice changed state within the `TYPING_NOTICE_TIMEOUT` + let send = if let Some(typing_time) = + self.client.inner.typing_notice_times.read().unwrap().get(self.room_id()) + { + if typing_time.elapsed() > TYPING_NOTICE_RESEND_TIMEOUT { + // We always reactivate the typing notice if typing is true or + // we may need to deactivate it if it's + // currently active if typing is false + typing || typing_time.elapsed() <= TYPING_NOTICE_TIMEOUT } else { - // Typing notice is currently deactivated, therefore, send a request - // only when it's about to be activated - typing - }; + // Only send a request when we need to deactivate typing + !typing + } + } else { + // Typing notice is currently deactivated, therefore, send a request + // only when it's about to be activated + typing + }; if send { self.send_typing_notice(typing).await?; @@ -1070,10 +1070,15 @@ impl Room { #[instrument(name = "typing_notice", skip(self))] async fn send_typing_notice(&self, typing: bool) -> Result<()> { let typing = if typing { - self.client.inner.typing_notice_times.insert(self.room_id().to_owned(), Instant::now()); + self.client + .inner + .typing_notice_times + .write() + .unwrap() + .insert(self.room_id().to_owned(), Instant::now()); Typing::Yes(TYPING_NOTICE_TIMEOUT) } else { - self.client.inner.typing_notice_times.remove(self.room_id()); + self.client.inner.typing_notice_times.write().unwrap().remove(self.room_id()); Typing::No };