Fixes "Message not found" error when editing immediately after sending.
**Problem**:
When sending a message, TDLib may return a temporary ID, then send
UpdateMessageSendSucceeded with the real server ID. We weren't handling
this update, so the cache kept the old ID while the server had a different
one, causing "Message not found" errors during edits.
**Solution**:
1. Added UpdateMessageSendSucceeded handler (client.rs:801-830)
- Finds message with temporary ID
- Replaces it with new message containing real server ID
- Preserves reply_info if present
2. Added validation before editing (main_input.rs:574-589)
- Checks message exists in cache
- Better error messages with chat_id and message_id
3. Added positive ID check in start_editing_selected (mod.rs:240)
- Blocks editing messages with temporary IDs (negative)
**Test**:
- Added test_edit_immediately_after_send (edit_message.rs:156-181)
- Verifies editing works right after send_message
- All 22 edit_message tests pass
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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>
- Log chat_id, message_id, text length before calling edit_message_text
- Log success or exact TDLib error
- This will help identify the root cause
Temporary debug commit to investigate issue.
- Изменён порядок хранения сообщений (теперь от старых к новым)
- Исправлена логика выбора сообщений для редактирования
- Исправлена отправка reply (структура условий)
- Добавлено сохранение reply_info при отправке
- Удалены отладочные логи
Fixes: сообщения теперь отображаются корректно в UI
Fixes: редактирование работает без ошибки 'Message not found'
Fixes: reply показывает превью исходного сообщения
Добавлен MessageBuilder для удобного создания MessageInfo с помощью
fluent API вместо вызова конструктора с 14 параметрами.
Изменения:
- Создан MessageBuilder в tdlib/types.rs с fluent API
- Реализованы методы:
* new(id) - создание builder с обязательным ID
* sender_name(), text(), entities(), date(), edit_date()
* outgoing(), incoming(), read(), unread(), edited()
* editable(), deletable_for_self(), deletable_for_all()
* reply_to(), forward_from(), reactions(), add_reaction()
* build() - финальное создание MessageInfo
- Обновлён convert_message() для использования builder
- Добавлен экспорт MessageBuilder в tdlib/mod.rs
- Добавлены 6 unit тестов демонстрирующих fluent API
Преимущества:
- Более читабельный код создания сообщений
- Самодокументирующийся API
- Гибкость в установке опциональных полей
- Легче добавлять новые поля в будущем
Пример использования:
```rust
let message = MessageBuilder::new(MessageId::new(123))
.sender_name("Alice")
.text("Hello, world!")
.outgoing()
.read()
.build();
```
Статус: Priority 2 ЗАВЕРШЁН 100% (5/5 задач)! 🎉
- ✅ Error enum
- ✅ Config validation
- ✅ Newtype для ID
- ✅ MessageInfo реструктуризация
- ✅ MessageBuilder pattern
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Сгруппированы 16 плоских полей MessageInfo в 4 логические структуры
для улучшения организации кода и maintainability.
Новые структуры:
- MessageMetadata: id, sender_name, date, edit_date
- MessageContent: text, entities
- MessageState: is_outgoing, is_read, can_be_edited, can_be_deleted_*
- MessageInteractions: reply_to, forward_from, reactions
Изменения:
- Добавлены 4 новые структуры в tdlib/types.rs
- Обновлена MessageInfo для использования новых структур
- Добавлен конструктор MessageInfo::new() для удобного создания
- Добавлены getter методы (id(), text(), sender_name() и др.) для удобного доступа
- Обновлены все места создания MessageInfo (convert_message)
- Обновлены все места использования (~200+ обращений):
* ui/messages.rs: рендеринг сообщений
* app/mod.rs: логика приложения
* input/main_input.rs: обработка ввода и копирование
* tdlib/client.rs: обработка updates
* Все тестовые файлы (14 файлов)
Преимущества:
- Логическая группировка данных
- Проще понимать структуру сообщения
- Легче добавлять новые поля в будущем
- Улучшенная читаемость кода
Статус: Priority 2 теперь 80% (4/5 задач)
- ✅ Error enum
- ✅ Config validation
- ✅ Newtype для ID
- ✅ MessageInfo реструктуризация
- ⏳ MessageBuilder pattern
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>