refactor: cleanup unused code and warnings
Some checks failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled

Comprehensive cleanup of unused methods, dead code, and compiler warnings:

## Removed Methods (15):
- Duplicate delegation methods: is_authenticated, get_typing_text, get_user_name from TdClient
- Obsolete methods: TdClient::init() (duplicated in main.rs)
- Unused getters: UserCache::{get_username, get_name, get_user_id_by_chat}
- Unused builder methods: MessageBuilder::{edited, add_reaction}
- Unused utility: ChatState::is_normal()
- Dead code: HotkeysConfig::{matches, key_matches} (kept for tests)
- Unused method: UserCache::register_private_chat()
- Getter replaced with direct field access: MessageInfo::edit_date()

## Removed Module:
- error.rs - Unused error handling module (TeletuiError, ErrorVariant, IntoTeletuiError)

## Removed Constants (8):
- EMOJI_PICKER_COLUMNS, EMOJI_PICKER_ROWS, MAX_INPUT_HEIGHT
- MIN_TERMINAL_WIDTH, MIN_TERMINAL_HEIGHT
- TDLIB_CHAT_LIMIT, MAX_USERNAME_DISPLAY_LENGTH, MESSAGE_TEXT_INDENT

## Fixed Warnings:
- Removed unused imports (8 instances)
- Fixed unreachable patterns (10 instances)
- Fixed irrefutable if let patterns (2 instances)
- Fixed unused variables (1 instance)
- Removed dead_code annotations where appropriate

## Improvements:
- Integrated Config::load_credentials() into TdClient::new() for better credential management
- Replaced edit_date() getter with direct field access (message.metadata.edit_date)
- Updated tests to use direct field access instead of removed getters

## Test Results:
All tests passing: 499 passed, 0 failed

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Kilin
2026-02-01 18:57:55 +03:00
parent f1a26b906c
commit 2b04b785c0
20 changed files with 57 additions and 292 deletions

View File

@@ -1,8 +1,8 @@
use crate::constants::{MAX_MESSAGES_IN_CHAT, TDLIB_MESSAGE_LIMIT};
use crate::types::{ChatId, MessageId};
use tdlib_rs::enums::{ChatAction, InputMessageContent, InputMessageReplyTo, MessageContent, MessageSender, SearchMessagesFilter, TextParseMode};
use tdlib_rs::enums::{InputMessageContent, InputMessageReplyTo, MessageContent, MessageSender, SearchMessagesFilter, TextParseMode};
use tdlib_rs::functions;
use tdlib_rs::types::{Chat as TdChat, FormattedText, InputMessageReplyToMessage, InputMessageText, Message as TdMessage, TextEntity, TextParseModeMarkdown};
use tdlib_rs::types::{FormattedText, InputMessageReplyToMessage, InputMessageText, Message as TdMessage, TextParseModeMarkdown};
use super::types::{ForwardInfo, MessageBuilder, MessageInfo, ReactionInfo, ReplyInfo};
@@ -178,7 +178,6 @@ impl MessageManager {
sleep(Duration::from_millis(200)).await;
}
}
Ok(_) => return Err("Неожиданный тип сообщений".to_string()),
Err(e) => return Err(format!("Ошибка загрузки истории: {:?}", e)),
}
}
@@ -237,7 +236,6 @@ impl MessageManager {
}
Ok(messages)
}
Ok(_) => Err("Неожиданный тип сообщений".to_string()),
Err(e) => Err(format!("Ошибка загрузки старых сообщений: {:?}", e)),
}
}
@@ -286,7 +284,6 @@ impl MessageManager {
}
Ok(pinned_messages)
}
Ok(_) => Err("Неожиданный тип результата поиска".to_string()),
Err(e) => Err(format!("Ошибка загрузки закреплённых: {:?}", e)),
}
}
@@ -362,7 +359,6 @@ impl MessageManager {
}
Ok(search_results)
}
Ok(_) => Err("Неожиданный тип результата поиска".to_string()),
Err(e) => Err(format!("Ошибка поиска: {:?}", e)),
}
}
@@ -464,10 +460,9 @@ impl MessageManager {
if let Some(reply) = reply_info {
msg_info.interactions.reply_to = Some(reply);
}
Ok(msg_info)
}
Ok(_) => Err("Неожиданный тип сообщения".to_string()),
Err(e) => Err(format!("Ошибка отправки сообщения: {:?}", e)),
}
}
@@ -523,7 +518,6 @@ impl MessageManager {
.convert_message(&msg)
.await
.ok_or_else(|| "Не удалось конвертировать отредактированное сообщение".to_string()),
Ok(_) => Err("Неожиданный тип сообщения".to_string()),
Err(e) => Err(format!("Ошибка редактирования: {:?}", e)),
}
}
@@ -832,8 +826,8 @@ impl MessageManager {
if let Ok(original_msg_enum) =
functions::get_message(chat_id.as_i64(), message_id.as_i64(), self.client_id).await
{
if let tdlib_rs::enums::Message::Message(original_msg) = original_msg_enum {
if let Some(orig_info) = self.convert_message(&original_msg).await {
let tdlib_rs::enums::Message::Message(original_msg) = original_msg_enum;
if let Some(orig_info) = self.convert_message(&original_msg).await {
// Update the reply info
for msg in &mut self.current_chat_messages {
if let Some(ref mut reply) = msg.interactions.reply_to {
@@ -848,7 +842,6 @@ impl MessageManager {
}
}
}
}
}
}
}