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

120
src/app/methods/compose.rs Normal file
View File

@@ -0,0 +1,120 @@
//! Compose methods for App
//!
//! Handles reply, forward, and draft functionality
use crate::app::{App, ChatState};
use crate::tdlib::{MessageInfo, TdClientTrait};
/// Compose methods for reply/forward/draft
pub trait ComposeMethods<T: TdClientTrait> {
/// Start replying to the selected message
/// Returns true if reply mode started, false if no message selected
fn start_reply_to_selected(&mut self) -> bool;
/// Cancel reply mode
fn cancel_reply(&mut self);
/// Check if currently in reply mode
fn is_replying(&self) -> bool;
/// Get the message being replied to
fn get_replying_to_message(&self) -> Option<MessageInfo>;
/// Start forwarding the selected message
/// Returns true if forward mode started, false if no message selected
fn start_forward_selected(&mut self) -> bool;
/// Cancel forward mode
fn cancel_forward(&mut self);
/// Check if currently in forward mode (selecting target chat)
fn is_forwarding(&self) -> bool;
/// Get the message being forwarded
fn get_forwarding_message(&self) -> Option<MessageInfo>;
/// Get draft for the currently selected chat
fn get_current_draft(&self) -> Option<String>;
/// Load draft into message_input (called when opening chat)
fn load_draft(&mut self);
}
impl<T: TdClientTrait> ComposeMethods<T> for App<T> {
fn start_reply_to_selected(&mut self) -> bool {
if let Some(msg) = self.get_selected_message() {
self.chat_state = ChatState::Reply {
message_id: msg.id(),
};
return true;
}
false
}
fn cancel_reply(&mut self) {
self.chat_state = ChatState::Normal;
}
fn is_replying(&self) -> bool {
self.chat_state.is_reply()
}
fn get_replying_to_message(&self) -> Option<MessageInfo> {
self.chat_state.selected_message_id().and_then(|id| {
self.td_client
.current_chat_messages()
.iter()
.find(|m| m.id() == id)
.cloned()
})
}
fn start_forward_selected(&mut self) -> bool {
if let Some(msg) = self.get_selected_message() {
self.chat_state = ChatState::Forward {
message_id: msg.id(),
};
// Сбрасываем выбор чата на первый
self.chat_list_state.select(Some(0));
return true;
}
false
}
fn cancel_forward(&mut self) {
self.chat_state = ChatState::Normal;
}
fn is_forwarding(&self) -> bool {
self.chat_state.is_forward()
}
fn get_forwarding_message(&self) -> Option<MessageInfo> {
if !self.chat_state.is_forward() {
return None;
}
self.chat_state.selected_message_id().and_then(|id| {
self.td_client
.current_chat_messages()
.iter()
.find(|m| m.id() == id)
.cloned()
})
}
fn get_current_draft(&self) -> Option<String> {
self.selected_chat_id.and_then(|chat_id| {
self.chats
.iter()
.find(|c| c.id == chat_id)
.and_then(|c| c.draft_text.clone())
})
}
fn load_draft(&mut self) {
if let Some(draft) = self.get_current_draft() {
self.message_input = draft;
self.cursor_position = self.message_input.chars().count();
}
}
}