diff --git a/src/service.rs b/src/service.rs index 7a279080..754f4634 100644 --- a/src/service.rs +++ b/src/service.rs @@ -4,7 +4,7 @@ use std::{ }; use lru_cache::LruCache; -use tokio::sync::{broadcast, Mutex, RwLock}; +use tokio::sync::Mutex; use crate::{observability::FilterReloadHandles, Config, Result}; @@ -85,11 +85,7 @@ impl Services { directory: db, edus: rooms::edus::Service { read_receipt: db, - typing: rooms::edus::typing::Service { - typing: RwLock::new(BTreeMap::new()), - last_typing_update: RwLock::new(BTreeMap::new()), - typing_update_sender: broadcast::channel(100).0, - }, + typing: rooms::edus::typing::Service::new(), }, event_handler: rooms::event_handler::Service, lazy_loading: rooms::lazy_loading::Service { diff --git a/src/service/rooms/edus/typing.rs b/src/service/rooms/edus/typing.rs index 49b5de95..097fed27 100644 --- a/src/service/rooms/edus/typing.rs +++ b/src/service/rooms/edus/typing.rs @@ -11,14 +11,21 @@ use crate::{services, utils, Result}; pub(crate) struct Service { // u64 is unix timestamp of timeout - pub(crate) typing: - RwLock>>, + typing: RwLock>>, // timestamp of the last change to typing users - pub(crate) last_typing_update: RwLock>, - pub(crate) typing_update_sender: broadcast::Sender, + last_typing_update: RwLock>, + typing_update_sender: broadcast::Sender, } impl Service { + pub(crate) fn new() -> Self { + Self { + typing: RwLock::new(BTreeMap::new()), + last_typing_update: RwLock::new(BTreeMap::new()), + typing_update_sender: broadcast::channel(100).0, + } + } + /// Sets a user as typing until the timeout timestamp is reached or /// `roomtyping_remove` is called. #[tracing::instrument(skip(self))]