fix(app): a sent message keeps its place in the transcript, so each reply follows it

This commit is contained in:
2026-10-23 15:34:46 +01:00
parent d791fce36c
commit 37c155e6e9
4 changed files with 95 additions and 45 deletions
@@ -304,6 +304,28 @@ class ChatThreadController extends ChangeNotifier {
bool _owned(int token) => !_disposed && token == _generation;
/// Puts a sent turn into the transcript where it was sent, as the web does:
/// after everything held so far and before any reply frame that follows. It
/// carries the id the harness will persist, so the live echo is ignored and
/// the history copy replaces it in place instead of moving it.
void insertLocal(JsonMap message) {
if (_disposed) return;
_messages = [..._messages, message];
_notify();
}
/// Removes a sent turn the server refused.
void removeLocal(String operationId) {
if (_disposed) return;
final next = [
for (final message in _messages)
if (message['operation_id'] != operationId) message,
];
if (next.length == _messages.length) return;
_messages = next;
_notify();
}
void _notify() {
if (!_disposed) notifyListeners();
}