refactor: enhance API service to include non-image files in requests and improve chat message synchronization logic

This commit is contained in:
cogwheel0
2025-08-26 11:21:26 +05:30
parent 494427dd04
commit 8692bf3bb6
2 changed files with 16 additions and 2 deletions

View File

@@ -37,9 +37,15 @@ class ChatMessagesNotifier extends StateNotifier<List<ChatMessage>> {
// Only react when the conversation actually changes
if (previous?.id == next?.id) {
// If same conversation but server updated it (e.g., title/content), sync messages without flicker
// If same conversation but server updated it (e.g., title/content), avoid overwriting
// locally streamed assistant content with an outdated server copy.
if (previous?.updatedAt != next?.updatedAt) {
state = next?.messages ?? state;
final serverMessages = next?.messages ?? const [];
// Only replace local messages if the server has strictly more messages
// (i.e., includes new content we don't have yet).
if (serverMessages.length > state.length) {
state = serverMessages;
}
}
return;
}