diff --git a/REFACTORING_ROADMAP.md b/REFACTORING_ROADMAP.md index a92ab95..6a45c67 100644 --- a/REFACTORING_ROADMAP.md +++ b/REFACTORING_ROADMAP.md @@ -554,11 +554,13 @@ fn test_message_grouping_by_date() { --- -### 12. Добавить rustdoc комментарии +### 12. Добавить rustdoc комментарии ✅ В ПРОЦЕССЕ... + +**Статус**: ЧАСТИЧНО ЗАВЕРШЕНО (+60 doc-комментариев, 2026-01-31) **Проблема**: Публичное API не документировано. -**Решение**: Добавить doc-комментарии: +**Решение**: ✅ Добавлены doc-комментарии для ключевых модулей: ```rust /// TDLib client wrapper for Telegram integration. /// diff --git a/src/app/mod.rs b/src/app/mod.rs index 233415d..bc389aa 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -8,6 +8,41 @@ use crate::tdlib::{ChatInfo, TdClient}; use crate::types::{ChatId, MessageId}; use ratatui::widgets::ListState; +/// Main application state for the Telegram TUI client. +/// +/// Manages all application state including authentication, chats, messages, +/// and UI state. Integrates with TDLib через `TdClient` and handles user input. +/// +/// # State Machine +/// +/// The app uses a type-safe state machine (`ChatState`) for chat-related operations: +/// - `Normal` - default state +/// - `MessageSelection` - selecting a message +/// - `Editing` - editing a message +/// - `Reply` - replying to a message +/// - `Forward` - forwarding a message +/// - `DeleteConfirmation` - confirming deletion +/// - `ReactionPicker` - choosing a reaction +/// - `Profile` - viewing profile +/// - `SearchInChat` - searching within chat +/// - `PinnedMessages` - viewing pinned messages +/// +/// # Examples +/// +/// ```no_run +/// use tele_tui::app::App; +/// use tele_tui::config::Config; +/// +/// let config = Config::default(); +/// let mut app = App::new(config); +/// +/// // Navigate through chats +/// app.next_chat(); +/// app.previous_chat(); +/// +/// // Open a chat +/// app.select_chat(); +/// ``` pub struct App { pub config: crate::config::Config, pub screen: AppScreen, @@ -42,6 +77,18 @@ pub struct App { } impl App { + /// Creates a new App instance with the given configuration. + /// + /// Initializes TDLib client, sets up empty chat list, and configures + /// the app to start on the Loading screen. + /// + /// # Arguments + /// + /// * `config` - Application configuration loaded from config.toml + /// + /// # Returns + /// + /// A new `App` instance ready to start authentication. pub fn new(config: crate::config::Config) -> App { let mut state = ListState::default(); state.select(Some(0)); diff --git a/src/tdlib/client.rs b/src/tdlib/client.rs index a9d6578..88b9d62 100644 --- a/src/tdlib/client.rs +++ b/src/tdlib/client.rs @@ -18,6 +18,31 @@ use super::reactions::ReactionManager; use super::types::{ChatInfo, FolderInfo, ForwardInfo, MessageInfo, NetworkState, ProfileInfo, ReactionInfo, ReplyInfo, UserOnlineStatus}; use super::users::UserCache; +/// TDLib client wrapper for Telegram integration. +/// +/// Provides high-level API for authentication, chat management, messaging, +/// and user caching. Delegates functionality to specialized managers: +/// - `AuthManager` for authentication flow +/// - `ChatManager` for chat operations +/// - `MessageManager` for message operations +/// - `UserCache` for user information caching +/// - `ReactionManager` for message reactions +/// +/// # Examples +/// +/// ```no_run +/// use tele_tui::tdlib::TdClient; +/// +/// let mut client = TdClient::new(); +/// +/// // Start authorization +/// client.send_phone_number("+1234567890".to_string()).await?; +/// client.send_code("12345".to_string()).await?; +/// +/// // Load chats +/// client.load_chats(50).await?; +/// # Ok::<(), String>(()) +/// ``` pub struct TdClient { pub api_id: i32, pub api_hash: String, @@ -36,6 +61,14 @@ pub struct TdClient { #[allow(dead_code)] impl TdClient { + /// Creates a new TDLib client instance. + /// + /// Reads API credentials from environment variables `API_ID` and `API_HASH`. + /// Initializes all managers and sets initial network state to Connecting. + /// + /// # Returns + /// + /// A new `TdClient` instance ready for authentication. pub fn new() -> Self { let api_id = env::var("API_ID") .unwrap_or_else(|_| "0".to_string()) @@ -58,35 +91,121 @@ impl TdClient { } // Делегирование к auth + + /// Checks if the user is authenticated. + /// + /// # Returns + /// + /// `true` if authentication is complete, `false` otherwise. pub fn is_authenticated(&self) -> bool { self.auth.is_authenticated() } + /// Sends phone number for authentication. + /// + /// This is the first step of the authentication flow. + /// + /// # Arguments + /// + /// * `phone` - Phone number in international format (e.g., "+1234567890") + /// + /// # Errors + /// + /// Returns an error if the phone number is invalid or network request fails. pub async fn send_phone_number(&self, phone: String) -> Result<(), String> { self.auth.send_phone_number(phone).await } + /// Sends authentication code received via SMS. + /// + /// This is the second step of the authentication flow. + /// + /// # Arguments + /// + /// * `code` - Authentication code (typically 5 digits) + /// + /// # Errors + /// + /// Returns an error if the code is invalid or expired. pub async fn send_code(&self, code: String) -> Result<(), String> { self.auth.send_code(code).await } + /// Sends 2FA password if required. + /// + /// This is the third step of the authentication flow (if 2FA is enabled). + /// + /// # Arguments + /// + /// * `password` - Two-factor authentication password + /// + /// # Errors + /// + /// Returns an error if the password is incorrect. pub async fn send_password(&self, password: String) -> Result<(), String> { self.auth.send_password(password).await } // Делегирование к chat_manager + + /// Loads chats from the main chat list. + /// + /// Loads up to `limit` chats from ChatList::Main, excluding archived chats. + /// Filters out "Deleted Account" chats automatically. + /// + /// # Arguments + /// + /// * `limit` - Maximum number of chats to load (typically 50-200) + /// + /// # Errors + /// + /// Returns an error if the network request fails. pub async fn load_chats(&mut self, limit: i32) -> Result<(), String> { self.chat_manager.load_chats(limit).await } + /// Loads chats from a specific folder. + /// + /// # Arguments + /// + /// * `folder_id` - Folder ID (1-9 for user folders) + /// * `limit` - Maximum number of chats to load + /// + /// # Errors + /// + /// Returns an error if the folder doesn't exist or network request fails. pub async fn load_folder_chats(&mut self, folder_id: i32, limit: i32) -> Result<(), String> { self.chat_manager.load_folder_chats(folder_id, limit).await } + /// Leaves a group or channel. + /// + /// # Arguments + /// + /// * `chat_id` - ID of the chat to leave + /// + /// # Errors + /// + /// Returns an error if the user is not a member or network request fails. pub async fn leave_chat(&self, chat_id: ChatId) -> Result<(), String> { self.chat_manager.leave_chat(chat_id).await } + /// Gets profile information for a chat. + /// + /// Fetches detailed information including bio, username, member count, etc. + /// + /// # Arguments + /// + /// * `chat_id` - ID of the chat + /// + /// # Returns + /// + /// `ProfileInfo` with chat details + /// + /// # Errors + /// + /// Returns an error if the chat doesn't exist or network request fails. pub async fn get_profile_info(&self, chat_id: ChatId) -> Result { self.chat_manager.get_profile_info(chat_id).await }