use std::time::Duration;
use botkit_core::BotError;
use botkit_core::action::{ChatAction, ChatActionFutureBounds, ChatActionSender};
use matrix_sdk::Room;
#[derive(Clone)]
pub struct MatrixActionSender {
room: Room,
}
impl MatrixActionSender {
pub fn new(room: Room) -> Self {
Self { room }
}
}
impl ChatActionSender for MatrixActionSender {
fn send_action(
&self,
action: ChatAction,
) -> impl ChatActionFutureBounds<Output = Result<(), BotError>> + '_ {
async move {
if action == ChatAction::Typing {
self.room
.typing_notice(true)
.await
.map_err(|e| BotError::Api(e.to_string()))?;
}
Ok(())
}
}
fn action_expiry(&self) -> Duration {
Duration::from_secs(4)
}
fn clear_action(&self) -> impl ChatActionFutureBounds<Output = Result<(), BotError>> + '_ {
async move {
self.room
.typing_notice(false)
.await
.map_err(|e| BotError::Api(e.to_string()))
}
}
}