fixes
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
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
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::types::{ChatId, MessageId, UserId};
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use tdlib_rs::enums::{
|
||||
ChatList, ConnectionState, Update, UserStatus,
|
||||
Chat as TdChat
|
||||
@@ -32,7 +33,7 @@ use crate::notifications::NotificationManager;
|
||||
/// ```ignore
|
||||
/// use tele_tui::tdlib::TdClient;
|
||||
///
|
||||
/// let mut client = TdClient::new();
|
||||
/// let mut client = TdClient::new(std::path::PathBuf::from("tdlib_data"));
|
||||
///
|
||||
/// // Start authorization
|
||||
/// client.send_phone_number("+1234567890".to_string()).await?;
|
||||
@@ -45,6 +46,7 @@ use crate::notifications::NotificationManager;
|
||||
pub struct TdClient {
|
||||
pub api_id: i32,
|
||||
pub api_hash: String,
|
||||
pub db_path: PathBuf,
|
||||
client_id: i32,
|
||||
|
||||
// Менеджеры (делегируем им функциональность)
|
||||
@@ -71,7 +73,7 @@ impl TdClient {
|
||||
/// # Returns
|
||||
///
|
||||
/// A new `TdClient` instance ready for authentication.
|
||||
pub fn new() -> Self {
|
||||
pub fn new(db_path: PathBuf) -> Self {
|
||||
// Пробуем загрузить credentials из Config (файл или env)
|
||||
let (api_id, api_hash) = crate::config::Config::load_credentials()
|
||||
.unwrap_or_else(|_| {
|
||||
@@ -89,6 +91,7 @@ impl TdClient {
|
||||
Self {
|
||||
api_id,
|
||||
api_hash,
|
||||
db_path,
|
||||
client_id,
|
||||
auth: AuthManager::new(client_id),
|
||||
chat_manager: ChatManager::new(client_id),
|
||||
@@ -624,6 +627,49 @@ impl TdClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Recreates the TDLib client with a new database path.
|
||||
///
|
||||
/// Closes the old client, creates a new one, and spawns TDLib parameter initialization.
|
||||
pub async fn recreate_client(&mut self, db_path: PathBuf) -> Result<(), String> {
|
||||
// 1. Close old client
|
||||
let _ = functions::close(self.client_id).await;
|
||||
|
||||
// 2. Create new client
|
||||
let new_client = TdClient::new(db_path);
|
||||
|
||||
// 3. Spawn set_tdlib_parameters for new client
|
||||
let new_client_id = new_client.client_id;
|
||||
let api_id = new_client.api_id;
|
||||
let api_hash = new_client.api_hash.clone();
|
||||
let db_path_str = new_client.db_path.to_string_lossy().to_string();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let _ = functions::set_tdlib_parameters(
|
||||
false,
|
||||
db_path_str,
|
||||
"".to_string(),
|
||||
"".to_string(),
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
api_id,
|
||||
api_hash,
|
||||
"en".to_string(),
|
||||
"Desktop".to_string(),
|
||||
"".to_string(),
|
||||
env!("CARGO_PKG_VERSION").to_string(),
|
||||
new_client_id,
|
||||
)
|
||||
.await;
|
||||
});
|
||||
|
||||
// 4. Replace self
|
||||
*self = new_client;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn extract_content_text(content: &tdlib_rs::enums::MessageContent) -> String {
|
||||
use tdlib_rs::enums::MessageContent;
|
||||
match content {
|
||||
|
||||
Reference in New Issue
Block a user