refactor: implement newtype pattern for IDs (P2.4)
Добавлены типобезопасные обёртки ChatId, MessageId, UserId для предотвращения смешивания разных типов идентификаторов на этапе компиляции. Изменения: - Создан src/types.rs с тремя newtype структурами - Реализованы методы: new(), as_i64(), From<i64>, Display - Добавлены traits: Hash, Eq, Serialize, Deserialize - Обновлены 15+ модулей для использования новых типов: * tdlib: types.rs, chats.rs, messages.rs, users.rs, reactions.rs, client.rs * app: mod.rs, chat_state.rs * input: main_input.rs * tests: app_builder.rs, test_data.rs - Исправлены 53 ошибки компиляции связанные с type conversions Преимущества: - Компилятор предотвращает смешивание разных типов ID - Улучшенная читаемость кода (явные типы вместо i64) - Самодокументирующиеся типы Статус: Priority 2 теперь 60% (3/5 задач) - ✅ Error enum - ✅ Config validation - ✅ Newtype для ID - ⏳ MessageInfo реструктуризация - ⏳ MessageBuilder pattern Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::constants::TDLIB_CHAT_LIMIT;
|
||||
use crate::types::{ChatId, UserId};
|
||||
use std::time::Instant;
|
||||
use tdlib_rs::enums::{ChatAction, ChatList, ChatType};
|
||||
use tdlib_rs::functions;
|
||||
@@ -11,7 +12,7 @@ pub struct ChatManager {
|
||||
pub folders: Vec<FolderInfo>,
|
||||
pub main_chat_list_position: i32,
|
||||
/// Typing status для текущего чата: (user_id, action_text, timestamp)
|
||||
pub typing_status: Option<(i64, String, Instant)>,
|
||||
pub typing_status: Option<(UserId, String, Instant)>,
|
||||
client_id: i32,
|
||||
}
|
||||
|
||||
@@ -50,8 +51,8 @@ impl ChatManager {
|
||||
}
|
||||
|
||||
/// Покинуть чат/группу
|
||||
pub async fn leave_chat(&self, chat_id: i64) -> Result<(), String> {
|
||||
let result = functions::leave_chat(chat_id, self.client_id).await;
|
||||
pub async fn leave_chat(&self, chat_id: ChatId) -> Result<(), String> {
|
||||
let result = functions::leave_chat(chat_id.as_i64(), self.client_id).await;
|
||||
match result {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(format!("Ошибка выхода из чата: {:?}", e)),
|
||||
@@ -59,9 +60,9 @@ impl ChatManager {
|
||||
}
|
||||
|
||||
/// Получить информацию профиля чата
|
||||
pub async fn get_profile_info(&self, chat_id: i64) -> Result<ProfileInfo, String> {
|
||||
pub async fn get_profile_info(&self, chat_id: ChatId) -> Result<ProfileInfo, String> {
|
||||
// Получаем основную информацию о чате
|
||||
let chat_result = functions::get_chat(chat_id, self.client_id).await;
|
||||
let chat_result = functions::get_chat(chat_id.as_i64(), self.client_id).await;
|
||||
let chat_enum = match chat_result {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(format!("Ошибка получения чата: {:?}", e)),
|
||||
@@ -187,8 +188,8 @@ impl ChatManager {
|
||||
}
|
||||
|
||||
/// Отправить typing action
|
||||
pub async fn send_chat_action(&self, chat_id: i64, action: ChatAction) {
|
||||
let _ = functions::send_chat_action(chat_id, 0, Some(action), self.client_id).await;
|
||||
pub async fn send_chat_action(&self, chat_id: ChatId, action: ChatAction) {
|
||||
let _ = functions::send_chat_action(chat_id.as_i64(), 0, Some(action), self.client_id).await;
|
||||
}
|
||||
|
||||
/// Очистить устаревший typing status (вызывать периодически)
|
||||
|
||||
Reference in New Issue
Block a user