getAllSessionsForTopic method
Returns ALL sessions (active + ended) for the given topic and session type, ordered chronologically. Used to merge conversation history.
Implementation
Future<List<LearningSessionModel>> getAllSessionsForTopic({
required String topicId,
required String sessionType,
}) async {
final userId = _client.auth.currentUser?.id;
if (userId == null) return [];
final response = await _client
.from('learning_sessions')
.select()
.eq('user_id', userId)
.eq('topic_id', topicId)
.eq('session_type', sessionType)
.order('started_at', ascending: true);
return (response as List<dynamic>)
.map(
(row) => LearningSessionModel.fromJson(row as Map<String, dynamic>),
)
.toList();
}