fixes
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use crate::app::App;
|
||||
use crate::tdlib::client::AuthState;
|
||||
use crate::tdlib::AuthState;
|
||||
use crossterm::event::KeyCode;
|
||||
use std::time::Duration;
|
||||
use tokio::time::timeout;
|
||||
|
||||
pub async fn handle(app: &mut App, key_code: KeyCode) {
|
||||
match &app.td_client.auth_state {
|
||||
match &app.td_client.auth_state() {
|
||||
AuthState::WaitPhoneNumber => match key_code {
|
||||
KeyCode::Char(c) => {
|
||||
app.phone_input.push(c);
|
||||
|
||||
@@ -189,12 +189,12 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
if let Some(msg_id) = app.get_selected_search_result_id() {
|
||||
let msg_index = app
|
||||
.td_client
|
||||
.current_chat_messages
|
||||
.current_chat_messages()
|
||||
.iter()
|
||||
.position(|m| m.id == msg_id);
|
||||
|
||||
if let Some(idx) = msg_index {
|
||||
let total = app.td_client.current_chat_messages.len();
|
||||
let total = app.td_client.current_chat_messages().len();
|
||||
app.message_scroll_offset = total.saturating_sub(idx + 5);
|
||||
}
|
||||
app.exit_message_search_mode();
|
||||
@@ -263,13 +263,13 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
// Ищем индекс сообщения в текущей истории
|
||||
let msg_index = app
|
||||
.td_client
|
||||
.current_chat_messages
|
||||
.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();
|
||||
let total = app.td_client.current_chat_messages().len();
|
||||
app.message_scroll_offset = total.saturating_sub(idx + 5);
|
||||
}
|
||||
app.exit_pinned_mode();
|
||||
@@ -375,7 +375,7 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
// Находим сообщение для проверки can_be_deleted_for_all_users
|
||||
let can_delete_for_all = app
|
||||
.td_client
|
||||
.current_chat_messages
|
||||
.current_chat_messages()
|
||||
.iter()
|
||||
.find(|m| m.id == msg_id)
|
||||
.map(|m| m.can_be_deleted_for_all_users)
|
||||
@@ -394,7 +394,7 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
Ok(Ok(_)) => {
|
||||
// Удаляем из локального списка
|
||||
app.td_client
|
||||
.current_chat_messages
|
||||
.current_chat_messages_mut()
|
||||
.retain(|m| m.id != msg_id);
|
||||
// Сбрасываем состояние
|
||||
app.chat_state = crate::app::ChatState::Normal;
|
||||
@@ -576,7 +576,7 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
// Обновляем сообщение в списке
|
||||
if let Some(msg) = app
|
||||
.td_client
|
||||
.current_chat_messages
|
||||
.current_chat_messages_mut()
|
||||
.iter_mut()
|
||||
.find(|m| m.id == msg_id)
|
||||
{
|
||||
@@ -602,7 +602,7 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
};
|
||||
// Создаём ReplyInfo ДО отправки, пока сообщение точно доступно
|
||||
let reply_info = app.get_replying_to_message().map(|m| {
|
||||
crate::tdlib::client::ReplyInfo {
|
||||
crate::tdlib::ReplyInfo {
|
||||
message_id: m.id,
|
||||
sender_name: m.sender_name.clone(),
|
||||
text: m.content.clone(),
|
||||
@@ -933,31 +933,29 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
app.message_scroll_offset += 3;
|
||||
|
||||
// Проверяем, нужно ли подгрузить старые сообщения
|
||||
if !app.td_client.current_chat_messages.is_empty() {
|
||||
if !app.td_client.current_chat_messages().is_empty() {
|
||||
let oldest_msg_id = app
|
||||
.td_client
|
||||
.current_chat_messages
|
||||
.current_chat_messages()
|
||||
.first()
|
||||
.map(|m| m.id)
|
||||
.unwrap_or(0);
|
||||
if let Some(chat_id) = app.get_selected_chat_id() {
|
||||
// Подгружаем больше сообщений если скролл близко к верху
|
||||
if app.message_scroll_offset
|
||||
> app.td_client.current_chat_messages.len().saturating_sub(10)
|
||||
> app.td_client.current_chat_messages().len().saturating_sub(10)
|
||||
{
|
||||
if let Ok(Ok(older)) = timeout(
|
||||
Duration::from_secs(3),
|
||||
app.td_client
|
||||
.load_older_messages(chat_id, oldest_msg_id, 20),
|
||||
.load_older_messages(chat_id, oldest_msg_id),
|
||||
)
|
||||
.await
|
||||
{
|
||||
if !older.is_empty() {
|
||||
// Добавляем старые сообщения в начало
|
||||
let mut new_messages = older;
|
||||
new_messages
|
||||
.extend(app.td_client.current_chat_messages.drain(..));
|
||||
app.td_client.current_chat_messages = new_messages;
|
||||
let msgs = app.td_client.current_chat_messages_mut();
|
||||
msgs.splice(0..0, older);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -984,7 +982,7 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
app.selected_folder_id = None;
|
||||
} else {
|
||||
// 2, 3, 4... = папки из TDLib
|
||||
if let Some(folder) = app.td_client.folders.get(folder_num - 1) {
|
||||
if let Some(folder) = app.td_client.folders().get(folder_num - 1) {
|
||||
let folder_id = folder.id;
|
||||
app.selected_folder_id = Some(folder_id);
|
||||
// Загружаем чаты папки
|
||||
@@ -1035,7 +1033,7 @@ fn copy_to_clipboard(text: &str) -> Result<(), String> {
|
||||
}
|
||||
|
||||
/// Форматирует сообщение для копирования с контекстом
|
||||
fn format_message_for_clipboard(msg: &crate::tdlib::client::MessageInfo) -> String {
|
||||
fn format_message_for_clipboard(msg: &crate::tdlib::MessageInfo) -> String {
|
||||
let mut result = String::new();
|
||||
|
||||
// Добавляем forward контекст если есть
|
||||
|
||||
Reference in New Issue
Block a user