refactor: eliminate code duplication - extract helpers and use retry utils
Extracted duplicate code and unified timeout handling across the codebase. Changes: - Extracted open_chat_and_load_data() function (eliminates 52 lines of duplication) - Replaced manual y/н/Enter handling with handle_yes_no() from modal_handler (2 places) - Replaced 7 direct tokio::time::timeout calls with retry utils (auth, main_input, main) - Added with_timeout_ignore() for non-critical operations - Fixed modal_handler.rs bug: corrected Russian 'y' key (д → н) - Removed unused imports in handlers/mod.rs and utils/mod.rs Impact: - main_input.rs: 1164 → 958 lines (-206 lines, -18%) - Code duplication: 52 lines eliminated - Direct timeout calls: 7 → 1 (-86%) - DRY principle applied throughout Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -205,7 +205,7 @@ async fn run_app<B: ratatui::backend::Backend, T: tdlib::TdClientTrait>(
|
||||
|
||||
/// Возвращает true если состояние изменилось и требуется перерисовка
|
||||
async fn update_screen_state<T: tdlib::TdClientTrait>(app: &mut App<T>) -> bool {
|
||||
use tokio::time::timeout;
|
||||
use utils::with_timeout_ignore;
|
||||
|
||||
let prev_screen = app.screen.clone();
|
||||
let prev_status = app.status_message.clone();
|
||||
@@ -227,8 +227,8 @@ async fn update_screen_state<T: tdlib::TdClientTrait>(app: &mut App<T>) -> bool
|
||||
app.is_loading = true;
|
||||
app.status_message = Some("Загрузка чатов...".to_string());
|
||||
|
||||
// Запрашиваем загрузку чатов с таймаутом
|
||||
let _ = timeout(Duration::from_secs(5), app.td_client.load_chats(50)).await;
|
||||
// Запрашиваем загрузку чатов с таймаутом (игнорируем ошибки)
|
||||
with_timeout_ignore(Duration::from_secs(5), app.td_client.load_chats(50)).await;
|
||||
}
|
||||
|
||||
// Синхронизируем чаты из td_client в app
|
||||
|
||||
Reference in New Issue
Block a user