add typings in/out

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Kilin
2026-01-27 03:59:49 +03:00
parent 46720b3584
commit 4d5625f950
6 changed files with 138 additions and 14 deletions

View File

@@ -1,7 +1,8 @@
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use std::time::Duration;
use std::time::{Duration, Instant};
use tokio::time::timeout;
use crate::app::App;
use crate::tdlib::ChatAction;
pub async fn handle(app: &mut App, key: KeyEvent) {
let has_ctrl = key.modifiers.contains(KeyModifiers::CONTROL);
@@ -220,6 +221,10 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
app.message_input.clear();
app.cursor_position = 0;
app.replying_to_message_id = None;
app.last_typing_sent = None;
// Отменяем typing status
app.td_client.send_chat_action(chat_id, ChatAction::Cancel).await;
match timeout(Duration::from_secs(5), app.td_client.send_message(chat_id, text, reply_to_id, reply_info)).await {
Ok(Ok(sent_msg)) => {
@@ -363,6 +368,17 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
}
app.message_input = new_input;
app.cursor_position += 1;
// Отправляем typing status с throttling (не чаще 1 раза в 5 сек)
let should_send_typing = app.last_typing_sent
.map(|t| t.elapsed().as_secs() >= 5)
.unwrap_or(true);
if should_send_typing {
if let Some(chat_id) = app.get_selected_chat_id() {
app.td_client.send_chat_action(chat_id, ChatAction::Typing).await;
app.last_typing_sent = Some(Instant::now());
}
}
}
KeyCode::Left => {
// Курсор влево