refactor: split app/mod.rs into trait-based architecture (1015→371 lines)

Split monolithic App impl into 5 specialized trait modules:
- methods/navigation.rs (NavigationMethods) - 7 methods for chat navigation
- methods/messages.rs (MessageMethods) - 8 methods for message operations
- methods/compose.rs (ComposeMethods) - 10 methods for reply/forward/draft
- methods/search.rs (SearchMethods) - 15 methods for search functionality
- methods/modal.rs (ModalMethods) - 27 methods for modal dialogs

Changes:
- app/mod.rs: 1015→371 lines (removed 644 lines, -63%)
- Created app/methods/ with 5 trait impl blocks
- Left in app/mod.rs: constructors, get_command, get_selected_chat_id/chat, getters/setters
- 116 functions → 5 trait impl blocks (67 in traits + 48 in core)
- Single Responsibility Principle achieved
- Updated CONTEXT.md with refactoring metrics
- Updated ROADMAP.md: Phase 13 Etap 2 marked as DONE

Phase 13 Etap 2: COMPLETED (100%)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Kilin
2026-02-06 00:59:14 +03:00
parent 1d0bfb53e0
commit 931954d829
9 changed files with 969 additions and 688 deletions

View File

@@ -478,7 +478,7 @@
- Каждый handler отвечает за свою область
- **Дополнительно:** Исправлен конфликт Ctrl+I → Ctrl+U для профиля
### Этап 2: Уменьшить app/mod.rs (116 функций → traits) [TODO]
### Этап 2: Уменьшить app/mod.rs (116 функций → traits) [DONE ✅]
**Текущая проблема:**
- God Object с 116 функциями
@@ -486,58 +486,64 @@
- Нарушение Single Responsibility Principle
**План:**
- [ ] Создать `app/methods/` директорию
- [ ] Создать trait `NavigationMethods`
- `next_chat()`, `previous_chat()`
- `scroll_up()`, `scroll_down()`
- `select_chat()`, `open_chat()`
- ~15 методов
- [ ] Создать trait `MessageMethods`
- `send_message()`, `edit_message()`, `delete_message()`
- `reply_to_message()`, `forward_message()`
- `select_message()`, `deselect_message()`
- ~20 методов
- [ ] Создать trait `ComposeMethods`
- `enter_edit_mode()`, `enter_reply_mode()`, `enter_forward_mode()`
- `handle_input_char()`, `move_cursor_left()`, `move_cursor_right()`
- ~15 методов
- [ ] Создать trait `SearchMethods`
- `start_search()`, `search_next()`, `search_previous()`
- `clear_search()`
- ~5 методов
- [ ] Создать trait `ModalMethods`
- `show_delete_confirmation()`, `show_emoji_picker()`
- `show_profile()`, `close_modal()`
- ~10 методов
- [ ] Оставить в `app/mod.rs` только:
- [x] Создать `app/methods/` директорию
- [x] Создать trait `NavigationMethods`
- `next_chat()`, `previous_chat()`, `select_current_chat()`, `close_chat()`
- `next_filtered_chat()`, `previous_filtered_chat()`, `select_filtered_chat()`
- **7 методов**
- [x] Создать trait `MessageMethods`
- `start_message_selection()`, `select_previous/next_message()`
- `get_selected_message()`, `start_editing_selected()`, `cancel_editing()`
- `is_editing()`, `is_selecting_message()`
- **8 методов**
- [x] Создать trait `ComposeMethods`
- `start_reply_to_selected()`, `cancel_reply()`, `is_replying()`, `get_replying_to_message()`
- `start_forward_selected()`, `cancel_forward()`, `is_forwarding()`, `get_forwarding_message()`
- `get_current_draft()`, `load_draft()`
- **10 методов**
- [x] Создать trait `SearchMethods`
- Chat search: `start_search()`, `cancel_search()`, `get_filtered_chats()`
- Message search: `enter/exit_message_search_mode()`, `set/get_search_results()`
- Navigation: `select_previous/next_search_result()`, query управление
- **15 методов**
- [x] Создать trait `ModalMethods`
- Delete confirmation: `is_confirm_delete_shown()`
- Pinned: `is/enter/exit_pinned_mode()`, `select_previous/next_pinned()`, getters
- Profile: `is/enter/exit_profile_mode()`, navigation, leave_group confirmation
- Reactions: `is/enter/exit_reaction_picker_mode()`, `select_previous/next_reaction()`
- **27 методов**
- [x] Оставить в `app/mod.rs` только:
- Struct definition
- Constructor (new, with_client)
- Getters/setters для полей
- ~30-40 методов
- Constructors (new, with_client)
- Utilities (get_command, get_selected_chat_id, get_selected_chat)
- Getters/setters для всех полей
- **~48 методов**
**Структура:**
```rust
// app/mod.rs - только core
mod methods;
pub use methods::*;
impl<T: TdClientTrait> App<T> {
pub fn new() -> Self { ... }
pub fn config(&self) -> &Config { ... }
pub fn get_command(...) -> Option<Command> { ... }
pub fn get_selected_chat_id(&self) -> Option<i64> { ... }
// ... getters/setters ...
}
// app/methods/navigation.rs
pub trait NavigationMethods {
pub trait NavigationMethods<T: TdClientTrait> {
fn next_chat(&mut self);
fn previous_chat(&mut self);
}
impl<T: TdClientTrait> NavigationMethods for App<T> { ... }
// app/methods/messages.rs
pub trait MessageMethods {
async fn send_message(&mut self, text: String);
}
impl<T: TdClientTrait> MessageMethods for App<T> { ... }
impl<T: TdClientTrait> NavigationMethods<T> for App<T> { ... }
```
**Результат:** 116 функций → 6 trait impl блоков
**Результат:** 1015 строк → **371 строка** (удалено 644 строки, -63%)
- 116 функций → 5 trait impl блоков (67 методов в traits + 48 в core)
- Каждый trait отвечает за свою область функциональности
- Соблюдён Single Responsibility Principle ✅
### Этап 3: Разбить ui/messages.rs (893 → <300 строк) [TODO]