add account profile
This commit is contained in:
@@ -167,6 +167,22 @@ pub struct FolderInfo {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// Информация о профиле чата/пользователя
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ProfileInfo {
|
||||
pub chat_id: i64,
|
||||
pub title: String,
|
||||
pub username: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
pub phone_number: Option<String>,
|
||||
pub chat_type: String, // "Личный чат", "Группа", "Канал"
|
||||
pub member_count: Option<i32>,
|
||||
pub description: Option<String>,
|
||||
pub invite_link: Option<String>,
|
||||
pub is_group: bool,
|
||||
pub online_status: Option<String>,
|
||||
}
|
||||
|
||||
/// Состояние сетевого соединения
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum NetworkState {
|
||||
@@ -1213,6 +1229,137 @@ impl TdClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Получение полной информации о чате для профиля
|
||||
pub async fn get_profile_info(&self, chat_id: i64) -> Result<ProfileInfo, String> {
|
||||
use tdlib_rs::enums::ChatType;
|
||||
|
||||
// Получаем основную информацию о чате
|
||||
let chat_result = functions::get_chat(chat_id, self.client_id).await;
|
||||
let chat = match chat_result {
|
||||
Ok(tdlib_rs::enums::Chat::Chat(c)) => c,
|
||||
Err(e) => return Err(format!("Ошибка загрузки чата: {:?}", e)),
|
||||
};
|
||||
|
||||
let mut profile = ProfileInfo {
|
||||
chat_id,
|
||||
title: chat.title.clone(),
|
||||
username: None,
|
||||
bio: None,
|
||||
phone_number: None,
|
||||
chat_type: String::new(),
|
||||
member_count: None,
|
||||
description: None,
|
||||
invite_link: None,
|
||||
is_group: false,
|
||||
online_status: None,
|
||||
};
|
||||
|
||||
match &chat.r#type {
|
||||
ChatType::Private(private_chat) => {
|
||||
profile.chat_type = "Личный чат".to_string();
|
||||
profile.is_group = false;
|
||||
|
||||
// Получаем полную информацию о пользователе
|
||||
let user_result = functions::get_user(private_chat.user_id, self.client_id).await;
|
||||
if let Ok(tdlib_rs::enums::User::User(user)) = user_result {
|
||||
// Username
|
||||
if let Some(usernames) = user.usernames {
|
||||
if let Some(username) = usernames.active_usernames.first() {
|
||||
profile.username = Some(format!("@{}", username));
|
||||
}
|
||||
}
|
||||
|
||||
// Phone number
|
||||
if !user.phone_number.is_empty() {
|
||||
profile.phone_number = Some(format!("+{}", user.phone_number));
|
||||
}
|
||||
|
||||
// Online status
|
||||
profile.online_status = Some(match user.status {
|
||||
tdlib_rs::enums::UserStatus::Online(_) => "Онлайн".to_string(),
|
||||
tdlib_rs::enums::UserStatus::Recently(_) => "Был(а) недавно".to_string(),
|
||||
tdlib_rs::enums::UserStatus::LastWeek(_) => "Был(а) на этой неделе".to_string(),
|
||||
tdlib_rs::enums::UserStatus::LastMonth(_) => "Был(а) в этом месяце".to_string(),
|
||||
tdlib_rs::enums::UserStatus::Offline(offline) => {
|
||||
crate::utils::format_was_online(offline.was_online)
|
||||
}
|
||||
_ => "Давно не был(а)".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
// Bio (getUserFullInfo)
|
||||
let full_info_result = functions::get_user_full_info(private_chat.user_id, self.client_id).await;
|
||||
if let Ok(tdlib_rs::enums::UserFullInfo::UserFullInfo(full_info)) = full_info_result {
|
||||
if let Some(bio_obj) = full_info.bio {
|
||||
profile.bio = Some(bio_obj.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatType::BasicGroup(basic_group) => {
|
||||
profile.chat_type = "Группа".to_string();
|
||||
profile.is_group = true;
|
||||
|
||||
// Получаем информацию о группе
|
||||
let group_result = functions::get_basic_group(basic_group.basic_group_id, self.client_id).await;
|
||||
if let Ok(tdlib_rs::enums::BasicGroup::BasicGroup(group)) = group_result {
|
||||
profile.member_count = Some(group.member_count);
|
||||
}
|
||||
|
||||
// Полная информация о группе
|
||||
let full_info_result = functions::get_basic_group_full_info(basic_group.basic_group_id, self.client_id).await;
|
||||
if let Ok(tdlib_rs::enums::BasicGroupFullInfo::BasicGroupFullInfo(full_info)) = full_info_result {
|
||||
if !full_info.description.is_empty() {
|
||||
profile.description = Some(full_info.description);
|
||||
}
|
||||
if let Some(link) = full_info.invite_link {
|
||||
profile.invite_link = Some(link.invite_link);
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatType::Supergroup(supergroup) => {
|
||||
// Получаем информацию о супергруппе
|
||||
let sg_result = functions::get_supergroup(supergroup.supergroup_id, self.client_id).await;
|
||||
if let Ok(tdlib_rs::enums::Supergroup::Supergroup(sg)) = sg_result {
|
||||
profile.chat_type = if sg.is_channel { "Канал".to_string() } else { "Супергруппа".to_string() };
|
||||
profile.is_group = !sg.is_channel;
|
||||
profile.member_count = Some(sg.member_count);
|
||||
|
||||
// Username
|
||||
if let Some(usernames) = sg.usernames {
|
||||
if let Some(username) = usernames.active_usernames.first() {
|
||||
profile.username = Some(format!("@{}", username));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Полная информация о супергруппе
|
||||
let full_info_result = functions::get_supergroup_full_info(supergroup.supergroup_id, self.client_id).await;
|
||||
if let Ok(tdlib_rs::enums::SupergroupFullInfo::SupergroupFullInfo(full_info)) = full_info_result {
|
||||
if !full_info.description.is_empty() {
|
||||
profile.description = Some(full_info.description);
|
||||
}
|
||||
if let Some(link) = full_info.invite_link {
|
||||
profile.invite_link = Some(link.invite_link);
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatType::Secret(_) => {
|
||||
profile.chat_type = "Секретный чат".to_string();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(profile)
|
||||
}
|
||||
|
||||
/// Выйти из группы/канала
|
||||
pub async fn leave_chat(&self, chat_id: i64) -> Result<(), String> {
|
||||
let result = functions::leave_chat(chat_id, self.client_id).await;
|
||||
match result {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(format!("Ошибка выхода из чата: {:?}", e)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Загрузка старых сообщений (для скролла вверх)
|
||||
pub async fn load_older_messages(
|
||||
&mut self,
|
||||
|
||||
Reference in New Issue
Block a user