feat(folders): Improve folder management and parsing logic
This commit is contained in:
@@ -3003,23 +3003,23 @@ class ApiService {
|
||||
);
|
||||
final data = response.data;
|
||||
// The endpoint can return a List[ChatTitleIdResponse] or a map.
|
||||
// Normalize to a List<Conversation> using our safe parser.
|
||||
// Normalize to a List<Conversation> using our isolate parser.
|
||||
if (data is List) {
|
||||
return data
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map((e) => Conversation.fromJson(parseConversationSummary(e)))
|
||||
.toList();
|
||||
return _parseConversationSummaryList(
|
||||
data,
|
||||
debugLabel: 'parse_search_direct',
|
||||
);
|
||||
}
|
||||
if (data is Map<String, dynamic>) {
|
||||
final list = (data['conversations'] ?? data['items'] ?? data['results']);
|
||||
if (list is List) {
|
||||
return list
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map((e) => Conversation.fromJson(parseConversationSummary(e)))
|
||||
.toList();
|
||||
return _parseConversationSummaryList(
|
||||
list,
|
||||
debugLabel: 'parse_search_wrapped',
|
||||
);
|
||||
}
|
||||
}
|
||||
return <Conversation>[];
|
||||
return const <Conversation>[];
|
||||
}
|
||||
|
||||
/// Search within messages content (capability-safe)
|
||||
|
||||
@@ -322,9 +322,13 @@ class OptimizedStorageService {
|
||||
|
||||
Future<void> saveLocalConversations(List<Conversation> conversations) async {
|
||||
try {
|
||||
final serialized = conversations
|
||||
final jsonReady = conversations
|
||||
.map((conversation) => conversation.toJson())
|
||||
.toList();
|
||||
final serialized = await _workerManager
|
||||
.schedule<Map<String, dynamic>, String>(_encodeConversationsWorker, {
|
||||
'conversations': jsonReady,
|
||||
}, debugLabel: 'encode_local_conversations');
|
||||
await _cachesBox.put(_localConversationsKey, serialized);
|
||||
DebugLogger.log(
|
||||
'Saved ${conversations.length} local conversations',
|
||||
@@ -478,3 +482,15 @@ List<Map<String, dynamic>> _decodeStoredConversationsWorker(
|
||||
|
||||
return <Map<String, dynamic>>[];
|
||||
}
|
||||
|
||||
String _encodeConversationsWorker(Map<String, dynamic> payload) {
|
||||
final raw = payload['conversations'];
|
||||
if (raw is List) {
|
||||
return jsonEncode(raw);
|
||||
}
|
||||
if (raw is String) {
|
||||
// Already encoded.
|
||||
return raw;
|
||||
}
|
||||
return jsonEncode([]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user