add account profile
This commit is contained in:
@@ -56,9 +56,109 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Режим профиля
|
||||
if app.is_profile_mode() {
|
||||
// Обработка подтверждения выхода из группы
|
||||
let confirmation_step = app.get_leave_group_confirmation_step();
|
||||
if confirmation_step > 0 {
|
||||
match key.code {
|
||||
KeyCode::Char('y') | KeyCode::Char('н') | KeyCode::Enter => {
|
||||
if confirmation_step == 1 {
|
||||
// Первое подтверждение - показываем второе
|
||||
app.show_leave_group_final_confirmation();
|
||||
} else if confirmation_step == 2 {
|
||||
// Второе подтверждение - выходим из группы
|
||||
if let Some(chat_id) = app.selected_chat_id {
|
||||
let leave_result = app.td_client.leave_chat(chat_id).await;
|
||||
match leave_result {
|
||||
Ok(_) => {
|
||||
app.status_message = Some("Вы вышли из группы".to_string());
|
||||
app.exit_profile_mode();
|
||||
app.close_chat();
|
||||
}
|
||||
Err(e) => {
|
||||
app.error_message = Some(e);
|
||||
app.cancel_leave_group();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyCode::Char('n') | KeyCode::Char('т') | KeyCode::Esc => {
|
||||
// Отмена
|
||||
app.cancel_leave_group();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Обычная навигация по профилю
|
||||
match key.code {
|
||||
KeyCode::Esc => {
|
||||
app.exit_profile_mode();
|
||||
}
|
||||
KeyCode::Up => {
|
||||
app.select_previous_profile_action();
|
||||
}
|
||||
KeyCode::Down => {
|
||||
if let Some(profile) = &app.profile_info {
|
||||
let max_actions = get_available_actions_count(profile);
|
||||
app.select_next_profile_action(max_actions);
|
||||
}
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
// Выполнить выбранное действие
|
||||
if let Some(profile) = &app.profile_info {
|
||||
let actions = get_available_actions_count(profile);
|
||||
let action_index = app.selected_profile_action;
|
||||
|
||||
if action_index < actions {
|
||||
// Определяем какое действие выбрано
|
||||
let mut current_idx = 0;
|
||||
|
||||
// Действие: Открыть в браузере
|
||||
if profile.username.is_some() {
|
||||
if action_index == current_idx {
|
||||
if let Some(username) = &profile.username {
|
||||
let url = format!("https://t.me/{}", username.trim_start_matches('@'));
|
||||
match open::that(&url) {
|
||||
Ok(_) => {
|
||||
app.status_message = Some(format!("Открыто: {}", url));
|
||||
}
|
||||
Err(e) => {
|
||||
app.error_message = Some(format!("Ошибка открытия браузера: {}", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
current_idx += 1;
|
||||
}
|
||||
|
||||
// Действие: Скопировать ID
|
||||
if action_index == current_idx {
|
||||
app.status_message = Some(format!("ID скопирован: {}", profile.chat_id));
|
||||
return;
|
||||
}
|
||||
current_idx += 1;
|
||||
|
||||
// Действие: Покинуть группу
|
||||
if profile.is_group && action_index == current_idx {
|
||||
app.show_leave_group_confirmation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Режим поиска по сообщениям
|
||||
if app.is_message_search_mode() {
|
||||
match key.code {
|
||||
@@ -468,6 +568,29 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ctrl+U для профиля
|
||||
if key.code == KeyCode::Char('u') && has_ctrl {
|
||||
if let Some(chat_id) = app.selected_chat_id {
|
||||
app.status_message = Some("Загрузка профиля...".to_string());
|
||||
match timeout(Duration::from_secs(5), app.td_client.get_profile_info(chat_id)).await {
|
||||
Ok(Ok(profile)) => {
|
||||
app.profile_info = Some(profile);
|
||||
app.enter_profile_mode();
|
||||
app.status_message = None;
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
app.error_message = Some(e);
|
||||
app.status_message = None;
|
||||
}
|
||||
Err(_) => {
|
||||
app.error_message = Some("Таймаут загрузки профиля".to_string());
|
||||
app.status_message = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
match key.code {
|
||||
KeyCode::Backspace => {
|
||||
// Удаляем символ слева от курсора
|
||||
@@ -616,3 +739,20 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Подсчёт количества доступных действий в профиле
|
||||
fn get_available_actions_count(profile: &crate::tdlib::ProfileInfo) -> usize {
|
||||
let mut count = 0;
|
||||
|
||||
if profile.username.is_some() {
|
||||
count += 1; // Открыть в браузере
|
||||
}
|
||||
|
||||
count += 1; // Скопировать ID
|
||||
|
||||
if profile.is_group {
|
||||
count += 1; // Покинуть группу
|
||||
}
|
||||
|
||||
count
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user