From 0ae8a2fb886aea11b1359d85ec91a4cdd28ea955 Mon Sep 17 00:00:00 2001 From: Mikhail Kilin Date: Sun, 1 Feb 2026 00:16:47 +0300 Subject: [PATCH] fix: update UI after editing message Issue: Message edits worked on server (other users saw changes), but local UI didn't update - edited text wasn't visible. Root cause: Code was updating individual fields instead of replacing the whole message, and wasn't triggering UI redraw. Solution: - Replace entire message with edited_msg (not individual fields) - Set needs_redraw = true to trigger UI update - Remove debug logging Now edited messages immediately appear in local UI. Co-Authored-By: Claude Sonnet 4.5 --- src/input/main_input.rs | 15 +++++---------- src/tdlib/messages.rs | 18 +++++------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/input/main_input.rs b/src/input/main_input.rs index 5edd6e8..a5dd8ae 100644 --- a/src/input/main_input.rs +++ b/src/input/main_input.rs @@ -578,21 +578,16 @@ pub async fn handle(app: &mut App, key: KeyEvent) { .await { Ok(Ok(edited_msg)) => { - // Обновляем сообщение в списке - if let Some(msg) = app - .td_client - .current_chat_messages_mut() - .iter_mut() - .find(|m| m.id() == msg_id) - { - msg.content.text = edited_msg.content.text; - msg.content.entities = edited_msg.content.entities; - msg.metadata.edit_date = edited_msg.metadata.edit_date; + // Заменяем сообщение целиком на отредактированное + let messages = app.td_client.current_chat_messages_mut(); + if let Some(pos) = messages.iter().position(|m| m.id() == msg_id) { + messages[pos] = edited_msg; } // Очищаем инпут и сбрасываем состояние ПОСЛЕ успешного редактирования app.message_input.clear(); app.cursor_position = 0; app.chat_state = crate::app::ChatState::Normal; + app.needs_redraw = true; // ВАЖНО: перерисовываем UI } Ok(Err(e)) => { app.error_message = Some(e); diff --git a/src/tdlib/messages.rs b/src/tdlib/messages.rs index 00dde0c..4155c80 100644 --- a/src/tdlib/messages.rs +++ b/src/tdlib/messages.rs @@ -320,24 +320,16 @@ impl MessageManager { clear_draft: true, }); - eprintln!("[EDIT] Calling edit_message_text: chat_id={}, message_id={}, text_len={}", - chat_id.as_i64(), message_id.as_i64(), text.len()); - let result = functions::edit_message_text(chat_id.as_i64(), message_id.as_i64(), content, self.client_id).await; match result { - Ok(tdlib_rs::enums::Message::Message(msg)) => { - eprintln!("[EDIT] Success! Edited message ID: {}", msg.id); - self.convert_message(&msg) - .await - .ok_or_else(|| "Не удалось конвертировать отредактированное сообщение".to_string()) - } + Ok(tdlib_rs::enums::Message::Message(msg)) => self + .convert_message(&msg) + .await + .ok_or_else(|| "Не удалось конвертировать отредактированное сообщение".to_string()), Ok(_) => Err("Неожиданный тип сообщения".to_string()), - Err(e) => { - eprintln!("[EDIT] Error from TDLib: {:?}", e); - Err(format!("Ошибка редактирования: {:?}", e)) - } + Err(e) => Err(format!("Ошибка редактирования: {:?}", e)), } }