Typing indicator send

This commit is contained in:
2025-12-23 13:23:52 +01:00
parent fcdf8e2e38
commit f9c934b8a2
2 changed files with 31 additions and 3 deletions
+27 -3
View File
@@ -15,16 +15,40 @@ pub struct IndicatorContext {
pub expires: u16, pub expires: u16,
} }
impl Server {
pub fn spawn_indicator_thread(self: &Arc<Self>) {
let server = self.clone();
std::thread::spawn(move || {
loop {
let mut remove = Vec::new();
for (i, indicator) in server.indicators.lock().unwrap().iter_mut().enumerate() {
indicator.expires -= 1;
if indicator.expires == 0 {
remove.push(i);
}
}
for r in remove {
server.indicators.lock().unwrap().remove(r);
}
}
});
}
}
crate::logger!(LOGGER "Typing Indicator"); crate::logger!(LOGGER "Typing Indicator");
pub fn start_typing(server: &Arc<Server>, client: &Client, channel_id: &str) -> crate::Result<()> { pub fn start_typing(server: &Arc<Server>, client: &Client, channel_id: &str) -> crate::Result<()> {
server.broadcast(ServerMessage::Indicator(IndicatorContext { let indicator = IndicatorContext {
indicator: Indicator::Typing { indicator: Indicator::Typing {
user_id: client.get_uuid().context("Failed to get uuid")?, user_id: client.get_uuid().context("Failed to get uuid")?,
channel_id: channel_id.to_string(), channel_id: channel_id.to_string(),
}, },
expires: 5, // 5 secs expires: 2, // 2 secs
})); };
server.broadcast(ServerMessage::Indicator(indicator.clone()));
server.indicators.lock().unwrap().push(indicator);
Ok(()) Ok(())
} }
+4
View File
@@ -99,6 +99,10 @@ impl Server {
Self::LOGGER.info("Authenticating"); Self::LOGGER.info("Authenticating");
auth::test(self)?; auth::test(self)?;
// Initialize indicators
Self::LOGGER.info("Initializing indicators");
self.spawn_indicator_thread();
// Initialize CLI // Initialize CLI
Self::LOGGER.info("Initializing CLI"); Self::LOGGER.info("Initializing CLI");
cli::start_cli(self.clone(), plugin_loader); cli::start_cli(self.clone(), plugin_loader);