86 lines
2.5 KiB
Rust
86 lines
2.5 KiB
Rust
//! Compose input handlers
|
|
//!
|
|
//! Handles text input and message composition, including:
|
|
//! - Forward mode
|
|
//! - Reply mode
|
|
//! - Edit mode
|
|
//! - Cursor movement and text editing
|
|
|
|
use crate::app::methods::{
|
|
compose::ComposeMethods, navigation::NavigationMethods, search::SearchMethods,
|
|
};
|
|
use crate::app::App;
|
|
use crate::tdlib::TdClientTrait;
|
|
use crate::types::ChatId;
|
|
use crate::utils::with_timeout_msg;
|
|
use crossterm::event::KeyEvent;
|
|
use std::time::Duration;
|
|
|
|
/// Обработка режима выбора чата для пересылки сообщения
|
|
///
|
|
/// Обрабатывает:
|
|
/// - Навигацию по списку чатов (Up/Down)
|
|
/// - Пересылку сообщения в выбранный чат (Enter)
|
|
/// - Отмену пересылки (Esc)
|
|
pub async fn handle_forward_mode<T: TdClientTrait>(
|
|
app: &mut App<T>,
|
|
_key: KeyEvent,
|
|
command: Option<crate::config::Command>,
|
|
) {
|
|
match command {
|
|
Some(crate::config::Command::Cancel) => {
|
|
app.cancel_forward();
|
|
}
|
|
Some(crate::config::Command::SubmitMessage) => {
|
|
forward_selected_message(app).await;
|
|
app.cancel_forward();
|
|
}
|
|
Some(crate::config::Command::MoveDown) => {
|
|
app.next_chat();
|
|
}
|
|
Some(crate::config::Command::MoveUp) => {
|
|
app.previous_chat();
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
/// Пересылает выбранное сообщение в выбранный чат
|
|
pub async fn forward_selected_message<T: TdClientTrait>(app: &mut App<T>) {
|
|
// Get all required IDs with early returns
|
|
let filtered = app.get_filtered_chats();
|
|
let Some(i) = app.chat_list_state.selected() else {
|
|
return;
|
|
};
|
|
let Some(chat) = filtered.get(i) else {
|
|
return;
|
|
};
|
|
let to_chat_id = chat.id;
|
|
|
|
let Some(msg_id) = app.chat_state.selected_message_id() else {
|
|
return;
|
|
};
|
|
let Some(from_chat_id) = app.get_selected_chat_id() else {
|
|
return;
|
|
};
|
|
|
|
// Forward the message with timeout
|
|
let result = with_timeout_msg(
|
|
Duration::from_secs(5),
|
|
app.td_client
|
|
.forward_messages(to_chat_id, ChatId::new(from_chat_id), vec![msg_id]),
|
|
"Таймаут пересылки",
|
|
)
|
|
.await;
|
|
|
|
// Handle result
|
|
match result {
|
|
Ok(_) => {
|
|
app.status_message = Some("Сообщение переслано".to_string());
|
|
}
|
|
Err(e) => {
|
|
app.error_message = Some(e);
|
|
}
|
|
}
|
|
}
|