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 <noreply@anthropic.com>
This commit is contained in:
@@ -578,21 +578,16 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(Ok(edited_msg)) => {
|
Ok(Ok(edited_msg)) => {
|
||||||
// Обновляем сообщение в списке
|
// Заменяем сообщение целиком на отредактированное
|
||||||
if let Some(msg) = app
|
let messages = app.td_client.current_chat_messages_mut();
|
||||||
.td_client
|
if let Some(pos) = messages.iter().position(|m| m.id() == msg_id) {
|
||||||
.current_chat_messages_mut()
|
messages[pos] = edited_msg;
|
||||||
.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;
|
|
||||||
}
|
}
|
||||||
// Очищаем инпут и сбрасываем состояние ПОСЛЕ успешного редактирования
|
// Очищаем инпут и сбрасываем состояние ПОСЛЕ успешного редактирования
|
||||||
app.message_input.clear();
|
app.message_input.clear();
|
||||||
app.cursor_position = 0;
|
app.cursor_position = 0;
|
||||||
app.chat_state = crate::app::ChatState::Normal;
|
app.chat_state = crate::app::ChatState::Normal;
|
||||||
|
app.needs_redraw = true; // ВАЖНО: перерисовываем UI
|
||||||
}
|
}
|
||||||
Ok(Err(e)) => {
|
Ok(Err(e)) => {
|
||||||
app.error_message = Some(e);
|
app.error_message = Some(e);
|
||||||
|
|||||||
@@ -320,24 +320,16 @@ impl MessageManager {
|
|||||||
clear_draft: true,
|
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 =
|
let result =
|
||||||
functions::edit_message_text(chat_id.as_i64(), message_id.as_i64(), content, self.client_id).await;
|
functions::edit_message_text(chat_id.as_i64(), message_id.as_i64(), content, self.client_id).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(tdlib_rs::enums::Message::Message(msg)) => {
|
Ok(tdlib_rs::enums::Message::Message(msg)) => self
|
||||||
eprintln!("[EDIT] Success! Edited message ID: {}", msg.id);
|
.convert_message(&msg)
|
||||||
self.convert_message(&msg)
|
.await
|
||||||
.await
|
.ok_or_else(|| "Не удалось конвертировать отредактированное сообщение".to_string()),
|
||||||
.ok_or_else(|| "Не удалось конвертировать отредактированное сообщение".to_string())
|
|
||||||
}
|
|
||||||
Ok(_) => Err("Неожиданный тип сообщения".to_string()),
|
Ok(_) => Err("Неожиданный тип сообщения".to_string()),
|
||||||
Err(e) => {
|
Err(e) => Err(format!("Ошибка редактирования: {:?}", e)),
|
||||||
eprintln!("[EDIT] Error from TDLib: {:?}", e);
|
|
||||||
Err(format!("Ошибка редактирования: {:?}", e))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user