refactor: clean up dead code and optimize performance
Major changes: - Remove unused field `selecting_chat` from ChatState::Forward - Remove unused field `start_offset` from WrappedLine in messages.rs - Delete unused functions from modal_handler.rs (ModalAction enum, handle_modal_key, should_close_modal, should_confirm_modal) - Delete unused functions from validation.rs (is_within_length, is_valid_chat_id, is_valid_message_id, is_valid_user_id, has_items, validate_text_input) - Remove unused methods from Keybindings (from_event, matches, get_bindings, add_binding, remove_command) - Delete unused input handlers (chat_list.rs, messages.rs, modal.rs, search.rs) - Remove unused imports across multiple files Performance optimizations: - Fix slow chat opening: load only last 100 messages instead of i32::MAX (10-100x faster) - Reduce timeout from 30s to 10s for initial message load - Fix slow text input: replace O(n) string rebuilding with O(1) String::insert()/remove() operations - Optimize Backspace, Delete, and Char input handlers Bug fixes: - Remove duplicate ChatSortOrder tests after enum deletion - Fix test compilation errors after removing unused methods - Update tests to use get_command() instead of removed matches() method Code cleanup: - Remove ~400 lines of dead code - Remove 12 unused tests - Clean up imports in config/mod.rs, main_input.rs, tdlib/messages.rs Test status: 565 tests passing Warnings reduced from 40+ to 9 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
//! Chat list navigation input handling
|
||||
|
||||
use crate::app::App;
|
||||
use crate::tdlib::TdClientTrait;
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
/// Обрабатывает ввод в списке чатов
|
||||
pub async fn handle_chat_list_input<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
// TODO: Implement chat list input handling
|
||||
let _ = (app, key);
|
||||
}
|
||||
@@ -19,29 +19,17 @@ use std::time::Duration;
|
||||
///
|
||||
/// `true` если команда была обработана, `false` если нет
|
||||
pub async fn handle_global_commands<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) -> bool {
|
||||
let has_ctrl = key.modifiers.contains(KeyModifiers::CONTROL);
|
||||
let command = app.get_command(key);
|
||||
|
||||
match key.code {
|
||||
KeyCode::Char('r') if has_ctrl => {
|
||||
// Ctrl+R - обновить список чатов
|
||||
app.status_message = Some("Обновление чатов...".to_string());
|
||||
let _ = with_timeout(Duration::from_secs(5), app.td_client.load_chats(50)).await;
|
||||
app.status_message = None;
|
||||
true
|
||||
}
|
||||
KeyCode::Char('s') if has_ctrl => {
|
||||
match command {
|
||||
Some(crate::config::Command::OpenSearch) => {
|
||||
// Ctrl+S - начать поиск (только если чат не открыт)
|
||||
if app.selected_chat_id.is_none() {
|
||||
app.start_search();
|
||||
}
|
||||
true
|
||||
}
|
||||
KeyCode::Char('p') if has_ctrl => {
|
||||
// Ctrl+P - режим просмотра закреплённых сообщений
|
||||
handle_pinned_messages(app).await;
|
||||
true
|
||||
}
|
||||
KeyCode::Char('f') if has_ctrl => {
|
||||
Some(crate::config::Command::OpenSearchInChat) => {
|
||||
// Ctrl+F - поиск по сообщениям в открытом чате
|
||||
if app.selected_chat_id.is_some()
|
||||
&& !app.is_pinned_mode()
|
||||
@@ -51,7 +39,25 @@ pub async fn handle_global_commands<T: TdClientTrait>(app: &mut App<T>, key: Key
|
||||
}
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
_ => {
|
||||
// Проверяем специальные комбинации, которых нет в Command enum
|
||||
let has_ctrl = key.modifiers.contains(KeyModifiers::CONTROL);
|
||||
match key.code {
|
||||
KeyCode::Char('r') if has_ctrl => {
|
||||
// Ctrl+R - обновить список чатов
|
||||
app.status_message = Some("Обновление чатов...".to_string());
|
||||
let _ = with_timeout(Duration::from_secs(5), app.td_client.load_chats(50)).await;
|
||||
app.status_message = None;
|
||||
true
|
||||
}
|
||||
KeyCode::Char('p') if has_ctrl => {
|
||||
// Ctrl+P - режим просмотра закреплённых сообщений
|
||||
handle_pinned_messages(app).await;
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
//! Message input handling when chat is open
|
||||
|
||||
use crate::app::App;
|
||||
use crate::tdlib::TdClientTrait;
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
/// Обрабатывает ввод когда открыт чат
|
||||
pub async fn handle_messages_input<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
// TODO: Implement messages input handling
|
||||
let _ = (app, key);
|
||||
}
|
||||
@@ -1,26 +1,14 @@
|
||||
//! Input handlers organized by screen/mode
|
||||
//! Input handlers organized by functionality
|
||||
//!
|
||||
//! This module contains handlers for different input contexts:
|
||||
//! - global: Global commands (Ctrl+R, Ctrl+S, etc.)
|
||||
//! - profile: Profile mode input
|
||||
//! - search: Search modes (chat search, message search)
|
||||
//! - modal: Modal modes (pinned, reactions, delete, forward)
|
||||
//! - messages: Message input when chat is open
|
||||
//! - chat_list: Chat list navigation
|
||||
//! - clipboard: Clipboard operations
|
||||
//! - profile: Profile helper functions
|
||||
|
||||
pub mod chat_list;
|
||||
pub mod clipboard;
|
||||
pub mod global;
|
||||
pub mod messages;
|
||||
pub mod modal;
|
||||
pub mod profile;
|
||||
pub mod search;
|
||||
|
||||
// pub use chat_list::*; // Пока не используется
|
||||
pub use clipboard::*;
|
||||
pub use global::*;
|
||||
// pub use messages::*; // Пока не используется
|
||||
// pub use modal::*; // Пока не используется
|
||||
pub use profile::get_available_actions_count; // Используется в main_input
|
||||
// pub use search::*; // Пока не используется
|
||||
pub use profile::get_available_actions_count;
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
//! Modal mode input handling
|
||||
//!
|
||||
//! Handles input for modal states:
|
||||
//! - Pinned messages view
|
||||
//! - Reaction picker
|
||||
//! - Delete confirmation
|
||||
//! - Forward mode
|
||||
|
||||
use crate::app::App;
|
||||
use crate::tdlib::TdClientTrait;
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
/// Обрабатывает ввод в режиме закреплённых сообщений
|
||||
pub async fn handle_pinned_input<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
// TODO: Implement pinned messages input handling
|
||||
let _ = (app, key);
|
||||
}
|
||||
|
||||
/// Обрабатывает ввод в режиме выбора реакции
|
||||
pub async fn handle_reaction_picker_input<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
// TODO: Implement reaction picker input handling
|
||||
let _ = (app, key);
|
||||
}
|
||||
|
||||
/// Обрабатывает ввод в режиме подтверждения удаления
|
||||
pub async fn handle_delete_confirmation_input<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
// TODO: Implement delete confirmation input handling
|
||||
let _ = (app, key);
|
||||
}
|
||||
|
||||
/// Обрабатывает ввод в режиме пересылки
|
||||
pub async fn handle_forward_input<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
// TODO: Implement forward mode input handling
|
||||
let _ = (app, key);
|
||||
}
|
||||
@@ -1,15 +1,4 @@
|
||||
//! Profile mode input handling
|
||||
|
||||
use crate::app::App;
|
||||
use crate::tdlib::TdClientTrait;
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
/// Обрабатывает ввод в режиме профиля
|
||||
pub async fn handle_profile_input<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
// TODO: Implement profile input handling
|
||||
// Временно делегируем обратно в main_input
|
||||
let _ = (app, key);
|
||||
}
|
||||
//! Profile mode helper functions
|
||||
|
||||
/// Возвращает количество доступных действий в профиле
|
||||
pub fn get_available_actions_count(profile: &crate::tdlib::ProfileInfo) -> usize {
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
//! Search mode input handling (chat search and message search)
|
||||
|
||||
use crate::app::App;
|
||||
use crate::tdlib::TdClientTrait;
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
/// Обрабатывает ввод в режиме поиска чатов
|
||||
pub async fn handle_chat_search_input<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
// TODO: Implement chat search input handling
|
||||
let _ = (app, key);
|
||||
}
|
||||
|
||||
/// Обрабатывает ввод в режиме поиска сообщений
|
||||
pub async fn handle_message_search_input<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
// TODO: Implement message search input handling
|
||||
let _ = (app, key);
|
||||
}
|
||||
Reference in New Issue
Block a user