Melhoria no funcionamento do histórico, Os nomes no dashboard do aluno carregam a primeira vez e ficam salvos para n ficarem sempre a carregar quando se volta ao dashboard, removi o butão de novo chat na interface de introdução da IA, mudei a aparencia dessa introdução e do histórico

This commit is contained in:
2026-05-23 16:20:27 +01:00
parent 7ee262f4c7
commit 895ce64c6f
22 changed files with 1330 additions and 582 deletions

View File

@@ -39,6 +39,7 @@ class ChatMemoryService {
'updatedAt': FieldValue.serverTimestamp(),
'selectedMaterialIds': selectedMaterialIds,
'messageCount': 0,
'hasUserMessage': false,
});
_currentConversationId = conversationRef.id;
@@ -98,19 +99,24 @@ class ChatMemoryService {
.orderBy('updatedAt', descending: true)
.get();
final conversations = snapshot.docs.map((doc) {
final data = doc.data();
return {
'id': doc.id,
'title': data['title'] as String? ?? 'Sem título',
'createdAt': data['createdAt'] as Timestamp?,
'updatedAt': data['updatedAt'] as Timestamp?,
'selectedMaterialIds':
(data['selectedMaterialIds'] as List<dynamic>?)?.cast<String>() ??
[],
'messageCount': data['messageCount'] as int? ?? 0,
};
}).toList();
final conversations = snapshot.docs
.map((doc) {
final data = doc.data();
return {
'id': doc.id,
'title': data['title'] as String? ?? 'Sem título',
'createdAt': data['createdAt'] as Timestamp?,
'updatedAt': data['updatedAt'] as Timestamp?,
'selectedMaterialIds':
(data['selectedMaterialIds'] as List<dynamic>?)
?.cast<String>() ??
[],
'messageCount': data['messageCount'] as int? ?? 0,
'hasUserMessage': data['hasUserMessage'] as bool? ?? false,
};
})
.where((conv) => (conv['hasUserMessage'] as bool) == true)
.toList();
Logger.info('Retrieved ${conversations.length} conversations');
return conversations;
@@ -193,15 +199,22 @@ class ChatMemoryService {
.add(messageData);
// Update conversation metadata
final updateData = <String, dynamic>{
'updatedAt': FieldValue.serverTimestamp(),
'messageCount': FieldValue.increment(1),
};
// Set hasUserMessage to true if this is a user message
if (role == 'user') {
updateData['hasUserMessage'] = true;
}
await _firestore
.collection('userChats')
.doc(user.uid)
.collection('conversations')
.doc(convId)
.update({
'updatedAt': FieldValue.serverTimestamp(),
'messageCount': FieldValue.increment(1),
});
.update(updateData);
Logger.info(
'Message saved to Firestore: role=$role, conversation=$convId',
@@ -281,6 +294,7 @@ class ChatMemoryService {
(data?['selectedMaterialIds'] as List<dynamic>?)?.cast<String>() ??
[],
'messageCount': data?['messageCount'] as int? ?? 0,
'hasUserMessage': data?['hasUserMessage'] as bool? ?? false,
};
} catch (e) {
Logger.error('Error getting conversation: $e');