fix: image attachment flashing and not persisting

This commit is contained in:
cogwheel0
2025-08-16 21:17:01 +05:30
parent 9be04ef2b9
commit d57ddf67c5
4 changed files with 310 additions and 338 deletions

View File

@@ -636,12 +636,27 @@ class ApiService {
role = 'user';
}
// Parse attachments from 'files' field
List<String>? attachmentIds;
if (msgData['files'] != null) {
final filesList = msgData['files'] as List;
attachmentIds = filesList
.where((file) => file is Map && file['file_id'] != null)
.map((file) => file['file_id'] as String)
.toList();
if (attachmentIds.isEmpty) {
attachmentIds = null;
}
}
return ChatMessage(
id: msgData['id']?.toString() ?? uuid.v4(),
role: role,
content: contentString,
timestamp: _parseTimestamp(msgData['timestamp']),
model: msgData['model'] as String?,
attachmentIds: attachmentIds,
);
}
@@ -760,6 +775,8 @@ class ApiService {
if (msg.role == 'assistant') 'modelIdx': 0,
if (msg.role == 'assistant') 'done': true,
if (msg.role == 'user' && model != null) 'models': [model],
if (msg.attachmentIds != null && msg.attachmentIds!.isNotEmpty)
'files': msg.attachmentIds!.map((id) => {'file_id': id}).toList(),
};
// Update parent's childrenIds
@@ -780,6 +797,8 @@ class ApiService {
if (msg.role == 'assistant') 'modelIdx': 0,
if (msg.role == 'assistant') 'done': true,
if (msg.role == 'user' && model != null) 'models': [model],
if (msg.attachmentIds != null && msg.attachmentIds!.isNotEmpty)
'files': msg.attachmentIds!.map((id) => {'file_id': id}).toList(),
});
previousId = messageId;