add pinned messages
This commit is contained in:
@@ -22,9 +22,69 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
KeyCode::Char('p') if has_ctrl => {
|
||||
// Ctrl+P - режим просмотра закреплённых сообщений
|
||||
if app.selected_chat_id.is_some() && !app.is_pinned_mode() {
|
||||
if let Some(chat_id) = app.get_selected_chat_id() {
|
||||
app.status_message = Some("Загрузка закреплённых...".to_string());
|
||||
match timeout(Duration::from_secs(5), app.td_client.get_pinned_messages(chat_id)).await {
|
||||
Ok(Ok(messages)) => {
|
||||
if messages.is_empty() {
|
||||
app.status_message = Some("Нет закреплённых сообщений".to_string());
|
||||
} else {
|
||||
app.enter_pinned_mode(messages);
|
||||
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;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Режим просмотра закреплённых сообщений
|
||||
if app.is_pinned_mode() {
|
||||
match key.code {
|
||||
KeyCode::Esc => {
|
||||
app.exit_pinned_mode();
|
||||
}
|
||||
KeyCode::Up => {
|
||||
app.select_previous_pinned();
|
||||
}
|
||||
KeyCode::Down => {
|
||||
app.select_next_pinned();
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
// Перейти к сообщению в истории
|
||||
if let Some(msg_id) = app.get_selected_pinned_id() {
|
||||
// Ищем индекс сообщения в текущей истории
|
||||
let msg_index = app.td_client.current_chat_messages
|
||||
.iter()
|
||||
.position(|m| m.id == msg_id);
|
||||
|
||||
if let Some(idx) = msg_index {
|
||||
// Вычисляем scroll offset чтобы показать сообщение
|
||||
let total = app.td_client.current_chat_messages.len();
|
||||
app.message_scroll_offset = total.saturating_sub(idx + 5);
|
||||
}
|
||||
app.exit_pinned_mode();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Модалка подтверждения удаления
|
||||
if app.is_confirm_delete_shown() {
|
||||
match key.code {
|
||||
@@ -129,6 +189,8 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
Ok(Ok(_)) => {
|
||||
// Загружаем недостающие reply info
|
||||
let _ = timeout(Duration::from_secs(5), app.td_client.fetch_missing_reply_info()).await;
|
||||
// Загружаем последнее закреплённое сообщение
|
||||
let _ = timeout(Duration::from_secs(2), app.td_client.load_current_pinned_message(chat_id)).await;
|
||||
app.status_message = None;
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
@@ -256,6 +318,8 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
Ok(Ok(_)) => {
|
||||
// Загружаем недостающие reply info
|
||||
let _ = timeout(Duration::from_secs(5), app.td_client.fetch_missing_reply_info()).await;
|
||||
// Загружаем последнее закреплённое сообщение
|
||||
let _ = timeout(Duration::from_secs(2), app.td_client.load_current_pinned_message(chat_id)).await;
|
||||
app.status_message = None;
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
|
||||
Reference in New Issue
Block a user