move typing feature up one level out of rooms.edus.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-03-31 17:14:31 -07:00 committed by June
parent 89a919ce75
commit 9790477b0e
8 changed files with 10 additions and 20 deletions

View file

@ -1003,16 +1003,10 @@ async fn load_joined_room(
.map(|(_, _, v)| v) .map(|(_, _, v)| v)
.collect(); .collect();
if services() if services().rooms.typing.last_typing_update(room_id).await? > since {
.rooms
.edus
.typing
.last_typing_update(room_id)
.await? > since
{
edus.push( edus.push(
serde_json::from_str( serde_json::from_str(
&serde_json::to_string(&services().rooms.edus.typing.typings_all(room_id).await?) &serde_json::to_string(&services().rooms.typing.typings_all(room_id).await?)
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),
) )
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),

View file

@ -28,14 +28,12 @@ pub async fn create_typing_event_route(
); );
services() services()
.rooms .rooms
.edus
.typing .typing
.typing_add(sender_user, &body.room_id, utils::millis_since_unix_epoch() + duration) .typing_add(sender_user, &body.room_id, utils::millis_since_unix_epoch() + duration)
.await?; .await?;
} else { } else {
services() services()
.rooms .rooms
.edus
.typing .typing
.typing_remove(sender_user, &body.room_id) .typing_remove(sender_user, &body.room_id)
.await?; .await?;

View file

@ -410,14 +410,12 @@ pub async fn send_transaction_message_route(
+ services().globals.config.typing_federation_timeout_s * 1000; + services().globals.config.typing_federation_timeout_s * 1000;
services() services()
.rooms .rooms
.edus
.typing .typing
.typing_add(&typing.user_id, &typing.room_id, timeout) .typing_add(&typing.user_id, &typing.room_id, timeout)
.await?; .await?;
} else { } else {
services() services()
.rooms .rooms
.edus
.typing .typing
.typing_remove(&typing.user_id, &typing.room_id) .typing_remove(&typing.user_id, &typing.room_id)
.await?; .await?;

View file

@ -97,7 +97,7 @@ impl service::globals::Data for KeyValueDatabase {
// EDUs // EDUs
futures.push(Box::pin(async move { futures.push(Box::pin(async move {
let _result = services().rooms.edus.typing.wait_for_update(&room_id).await; let _result = services().rooms.typing.wait_for_update(&room_id).await;
})); }));
futures.push(self.readreceiptid_readreceipt.watch_prefix(&roomid_prefix)); futures.push(self.readreceiptid_readreceipt.watch_prefix(&roomid_prefix));

View file

@ -73,11 +73,6 @@ impl Services<'_> {
presence: rooms::edus::presence::Service { presence: rooms::edus::presence::Service {
db, 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,
},
}, },
event_handler: rooms::event_handler::Service, event_handler: rooms::event_handler::Service,
lazy_loading: rooms::lazy_loading::Service { lazy_loading: rooms::lazy_loading::Service {
@ -130,6 +125,11 @@ impl Services<'_> {
threads: rooms::threads::Service { threads: rooms::threads::Service {
db, db,
}, },
typing: rooms::typing::Service {
typing: RwLock::new(BTreeMap::new()),
last_typing_update: RwLock::new(BTreeMap::new()),
typing_update_sender: broadcast::channel(100).0,
},
spaces: rooms::spaces::Service { spaces: rooms::spaces::Service {
roomid_spacehierarchy_cache: Mutex::new(LruCache::new( roomid_spacehierarchy_cache: Mutex::new(LruCache::new(
(100.0 * config.conduit_cache_capacity_modifier) as usize, (100.0 * config.conduit_cache_capacity_modifier) as usize,

View file

@ -1,9 +1,7 @@
pub mod presence; pub mod presence;
pub mod typing;
pub trait Data: presence::Data + 'static {} pub trait Data: presence::Data + 'static {}
pub struct Service { pub struct Service {
pub presence: presence::Service, pub presence: presence::Service,
pub typing: typing::Service,
} }

View file

@ -17,6 +17,7 @@ pub mod state_cache;
pub mod state_compressor; pub mod state_compressor;
pub mod threads; pub mod threads;
pub mod timeline; pub mod timeline;
pub mod typing;
pub mod user; pub mod user;
pub trait Data: pub trait Data:
@ -60,6 +61,7 @@ pub struct Service {
pub state_compressor: state_compressor::Service, pub state_compressor: state_compressor::Service,
pub timeline: timeline::Service, pub timeline: timeline::Service,
pub threads: threads::Service, pub threads: threads::Service,
pub typing: typing::Service,
pub spaces: spaces::Service, pub spaces: spaces::Service,
pub user: user::Service, pub user: user::Service,
} }