sdk: Replace dashmap usage by std types
This commit is contained in:
committed by
Jonas Platte
parent
113bdbd835
commit
686fc99ebd
Generated
-14
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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<OwnedRoomId, Instant>,
|
||||
pub(crate) typing_notice_times: StdRwLock<BTreeMap<OwnedRoomId, Instant>>,
|
||||
/// Event handlers. See `add_event_handler`.
|
||||
pub(crate) event_handlers: EventHandlerStore,
|
||||
/// Notification handlers. See `register_notification_handler`.
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user