Mikhail Kilin
|
c881f74ecb
|
refactor: complete nesting simplification (category 3 - 100%)
Simplified deep nesting across the codebase using modern Rust patterns:
let-else guards, early returns, iterator chains, and extracted functions.
**Files improved:**
1. src/tdlib/messages.rs (44 → 28 spaces max indent)
- fetch_missing_reply_info(): 7 → 2-3 levels
* Extracted fetch_and_update_reply()
* Used filter_map and iterator chains
- get_chat_history() retry loop: 6 → 3 levels
* Early continue for empty results
* Used .flatten() instead of nested if-let
2. src/input/main_input.rs (40 → 36 spaces max indent)
- handle_forward_mode(): 7 → 2-3 levels
* Extracted forward_selected_message()
- Reaction picker: 5 → 2-3 levels
* Extracted send_reaction()
- Scroll + load older: 6 → 2-3 levels
* Extracted load_older_messages_if_needed()
3. src/config.rs (36 → 32 spaces max indent)
- load_credentials(): 7 → 2-3 levels
* Extracted load_credentials_from_file()
* Extracted load_credentials_from_env()
* Used ? operator for Option chains
**Results:**
- Max nesting in entire project: ≤32 spaces (8 levels)
- 8 new functions extracted for better separation of concerns
- All 343 tests passing ✅
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
2026-02-04 02:35:56 +03:00 |
|
Mikhail Kilin
|
5ac10ea24c
|
refactor: complete large files/functions refactoring (Phase 6-7)
Phase 6: Refactor tdlib/client.rs ✅
- Extract update handlers to update_handlers.rs (302 lines, 8 functions)
- Extract message converter to message_converter.rs (250 lines, 6 functions)
- Extract chat helpers to chat_helpers.rs (149 lines, 3 functions)
- Result: client.rs 1259 → 599 lines (-52%)
Phase 7: Refactor tdlib/messages.rs ✅
- Create message_conversion.rs module (158 lines)
- Extract 6 helper functions:
- extract_content_text() - content extraction (~80 lines)
- extract_entities() - formatting extraction (~10 lines)
- extract_sender_name() - sender name with API call (~15 lines)
- extract_forward_info() - forward info (~12 lines)
- extract_reply_info() - reply info (~15 lines)
- extract_reactions() - reactions extraction (~26 lines)
- Result: convert_message() 150 → 57 lines (-62%)
- Result: messages.rs 850 → 757 lines (-11%)
Summary:
- ✅ All 4 large files refactored (100%)
- ✅ All 629 tests passing
- ✅ Category #2 "Large files/functions" COMPLETE
- ✅ Documentation updated (REFACTORING_OPPORTUNITIES.md, CONTEXT.md)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
2026-02-04 01:29:26 +03:00 |
|
Mikhail Kilin
|
3c8fec7ca6
|
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>
|
2026-02-02 17:38:49 +03:00 |
|
Mikhail Kilin
|
4d9d76ed23
|
refactor: prepare handlers structure for future input refactoring
Preparation for splitting large input file (#2):
- Created src/input/handlers/ structure (7 modules)
- clipboard.rs (~100 lines) - clipboard operations extracted
- global.rs (~90 lines) - global commands (Ctrl+R/S/P/F) extracted
- Stubs: profile.rs, search.rs, modal.rs, messages.rs, chat_list.rs
- main_input.rs remains monolithic (1139 lines)
- Attempted full migration broke navigation - rolled back
- Handlers remain as preparation for gradual migration
Updated documentation:
- REFACTORING_OPPORTUNITIES.md: #2.1 status updated
- CONTEXT.md: Added lesson about careful refactoring
Lesson learned: Critical input logic requires careful step-by-step
refactoring with functionality verification after each step.
Tests: 563 passed, 0 failed
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
2026-02-02 00:08:56 +03:00 |
|
Mikhail Kilin
|
dff0897da4
|
refactor: add modal/validation utils and partial App encapsulation
Quick wins refactoring (Variant 1):
- Created src/utils/modal_handler.rs (120+ lines)
- 4 functions for modal handling (close, confirm, yes/no)
- ModalAction enum for type-safe processing
- English and Russian keyboard layout support
- 4 unit tests
- Created src/utils/validation.rs (180+ lines)
- 7 validation functions (empty, length, IDs, etc)
- Covers all common validation patterns
- 7 unit tests
- Partial App encapsulation:
- Made config field private (readonly via app.config())
- Added 30+ getter/setter methods
- Updated ui/messages.rs to use config()
- Updated documentation:
- REFACTORING_OPPORTUNITIES.md: #1 Complete, #5 Partial
- CONTEXT.md: Added quick wins section
Tests: 563 passed, 0 failed
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
2026-02-01 23:55:49 +03:00 |
|
Mikhail Kilin
|
c6beea5608
|
refactor: create timeout/retry utilities to reduce code duplication (P1.1)
Created new utility modules to eliminate repeated timeout/retry patterns:
- src/utils/retry.rs: with_timeout() and with_timeout_msg() helpers
- src/utils/formatting.rs: timestamp formatting utilities (from utils.rs)
- src/utils/tdlib.rs: TDLib log configuration utilities (from utils.rs)
Refactored src/input/main_input.rs:
- Replaced 18+ instances of timeout(Duration, op).await pattern
- Simplified error handling from nested Ok(Ok(...))/Ok(Err(...))/Err(...)
to cleaner Ok(...)/Err(...) with custom timeout messages
- Added type annotations for compiler type inference
Benefits:
- Reduced code duplication from ~20 instances to 2 utility functions
- Cleaner, more readable error handling
- Easier to maintain timeout logic in one place
- All 59 tests passing
Progress: REFACTORING_OPPORTUNITIES.md #1 (Дублирование кода) - Частично выполнено
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
2026-02-01 19:56:33 +03:00 |
|