refactor: integrate validation utils and complete refactoring #1
Завершена интеграция validation utils во всех местах проверки user input: Changes: - src/utils/mod.rs: раскомментирован экспорт validation::* - src/input/auth.rs: 3 замены .is_empty() -> is_non_empty() * phone_input validation (line 18) * code_input validation (line 50) * password_input validation (line 82) - src/input/main_input.rs: 1 замена для message_input (line 484) - src/main.rs: заменён последний прямой timeout на with_timeout_ignore Documentation: - REFACTORING_OPPORTUNITIES.md: обновлён статус категории #1 * Отмечено как "ПОЛНОСТЬЮ ЗАВЕРШЕНО" (2026-02-02) * Добавлены метрики: 100% покрытие retry utils, 0 прямых timeouts * Обновлён план выполнения: фаза 1 завершена - CONTEXT.md: добавлен раздел об интеграции validation utils Result: ✅ Категория #1 (Дублирование кода) - ПОЛНОСТЬЮ ЗАВЕРШЕНА! - retry utils: 100% покрытие (8+ мест) - modal_handler: 2 диалога - validation: 4 места Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::app::App;
|
||||
use crate::tdlib::{AuthState, TdClientTrait};
|
||||
use crate::utils::with_timeout_msg;
|
||||
use crate::utils::{is_non_empty, with_timeout_msg};
|
||||
use crossterm::event::KeyCode;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -16,7 +16,7 @@ pub async fn handle<T: TdClientTrait>(app: &mut App<T>, key_code: KeyCode) {
|
||||
app.error_message = None;
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if !app.phone_input.is_empty() {
|
||||
if is_non_empty(&app.phone_input) {
|
||||
app.status_message = Some("Отправка номера...".to_string());
|
||||
match with_timeout_msg(
|
||||
Duration::from_secs(10),
|
||||
@@ -48,7 +48,7 @@ pub async fn handle<T: TdClientTrait>(app: &mut App<T>, key_code: KeyCode) {
|
||||
app.error_message = None;
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if !app.code_input.is_empty() {
|
||||
if is_non_empty(&app.code_input) {
|
||||
app.status_message = Some("Проверка кода...".to_string());
|
||||
match with_timeout_msg(
|
||||
Duration::from_secs(10),
|
||||
@@ -80,7 +80,7 @@ pub async fn handle<T: TdClientTrait>(app: &mut App<T>, key_code: KeyCode) {
|
||||
app.error_message = None;
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if !app.password_input.is_empty() {
|
||||
if is_non_empty(&app.password_input) {
|
||||
app.status_message = Some("Проверка пароля...".to_string());
|
||||
match with_timeout_msg(
|
||||
Duration::from_secs(10),
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::input::handlers::{
|
||||
};
|
||||
use crate::tdlib::ChatAction;
|
||||
use crate::types::{ChatId, MessageId};
|
||||
use crate::utils::{with_timeout, with_timeout_msg, with_timeout_ignore};
|
||||
use crate::utils::{is_non_empty, with_timeout, with_timeout_msg, with_timeout_ignore};
|
||||
use crate::utils::modal_handler::handle_yes_no;
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use std::time::{Duration, Instant};
|
||||
@@ -481,7 +481,7 @@ pub async fn handle<T: TdClientTrait>(app: &mut App<T>, key: KeyEvent) {
|
||||
}
|
||||
|
||||
// Отправка или редактирование сообщения
|
||||
if !app.message_input.is_empty() {
|
||||
if is_non_empty(&app.message_input) {
|
||||
if let Some(chat_id) = app.get_selected_chat_id() {
|
||||
let text = app.message_input.clone();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ use app::{App, AppScreen};
|
||||
use constants::{POLL_TIMEOUT_MS, SHUTDOWN_TIMEOUT_SECS};
|
||||
use input::{handle_auth_input, handle_main_input};
|
||||
use tdlib::AuthState;
|
||||
use utils::disable_tdlib_logs;
|
||||
use utils::{disable_tdlib_logs, with_timeout_ignore};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), io::Error> {
|
||||
@@ -177,7 +177,7 @@ async fn run_app<B: ratatui::backend::Backend, T: tdlib::TdClientTrait>(
|
||||
let _ = tdlib_rs::functions::close(app.td_client.client_id()).await;
|
||||
|
||||
// Ждём завершения polling задачи (с таймаутом)
|
||||
let _ = tokio::time::timeout(Duration::from_secs(SHUTDOWN_TIMEOUT_SECS), polling_handle).await;
|
||||
with_timeout_ignore(Duration::from_secs(SHUTDOWN_TIMEOUT_SECS), polling_handle).await;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ pub use formatting::*;
|
||||
// pub use modal_handler::*; // Используется через явный import
|
||||
pub use retry::{with_timeout, with_timeout_msg, with_timeout_ignore};
|
||||
pub use tdlib::*;
|
||||
// pub use validation::*; // Пока не используется
|
||||
pub use validation::*;
|
||||
|
||||
Reference in New Issue
Block a user