From 208ba8edf58c9a3e647a29f372436222541f0110 Mon Sep 17 00:00:00 2001 From: Krushna Kanta Rout <129386740+krushnarout@users.noreply.github.com> Date: Mon, 6 Oct 2025 02:09:48 +0530 Subject: [PATCH 1/2] feat: auto refresh conversation --- app/lib/providers/conversation_provider.dart | 56 ++++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/app/lib/providers/conversation_provider.dart b/app/lib/providers/conversation_provider.dart index 8d57190829..0ef9283269 100644 --- a/app/lib/providers/conversation_provider.dart +++ b/app/lib/providers/conversation_provider.dart @@ -32,6 +32,8 @@ class ConversationProvider extends ChangeNotifier { List processingConversations = []; + final Set _pendingRefreshConversations = {}; + final AppReviewService _appReviewService = AppReviewService(); bool isFetchingConversations = false; @@ -127,8 +129,39 @@ class ConversationProvider extends ChangeNotifier { } void removeProcessingConversation(String conversationId) { + final convo = processingConversations.where((m) => m.id == conversationId).isNotEmpty + ? processingConversations.firstWhere((m) => m.id == conversationId) + : null; + processingConversations.removeWhere((m) => m.id == conversationId); notifyListeners(); + + if (convo != null && convo.status == ConversationStatus.completed) { + upsertConversation(convo); + } + + _pendingRefreshConversations.add(conversationId); + _refreshDebounceTimer?.cancel(); + + _refreshDebounceTimer = Timer(const Duration(milliseconds: 500), () { + + Set conversationsNeedingRefresh = {}; + + for (String pendingId in _pendingRefreshConversations) { + bool conversationExists = conversations.any((conv) => conv.id == pendingId); + if (!conversationExists) { + conversationsNeedingRefresh.add(pendingId); + } + } + + if (conversationsNeedingRefresh.isNotEmpty) { + forceRefreshConversations(); + } else { + debugPrint('No refresh needed'); + } + + _pendingRefreshConversations.clear(); + }); } void onConversationTap(int idx) { @@ -209,17 +242,20 @@ class ConversationProvider extends ChangeNotifier { processingConversations.insertAll(0, upsertConvos); } - // completed convos - upsertConvos = newConversations - .where((c) => c.status == ConversationStatus.completed && conversations.indexWhere((cc) => cc.id == c.id) == -1) - .toList(); - if (upsertConvos.isNotEmpty) { - // Check if this is the first conversation - bool wasEmpty = conversations.isEmpty; - - conversations.insertAll(0, upsertConvos); + for (var c in newConversations) { + if (c.status == ConversationStatus.completed) { + int idx = conversations.indexWhere((cc) => cc.id == c.id); + if (idx == -1) { + conversations.insert(0, c); + } else { + conversations[idx] = c; + } + } + } - // Mark first conversation for app review + // Check if this is the first conversation for app review + if (conversations.isNotEmpty) { + bool wasEmpty = conversations.length == newConversations.where((c) => c.status == ConversationStatus.completed).length; if (wasEmpty && await _appReviewService.isFirstConversation()) { await _appReviewService.markFirstConversation(); } From f1e8a554995b10716b7dc62d0e1545372dacd5c5 Mon Sep 17 00:00:00 2001 From: Krushna Kanta Rout <129386740+krushnarout@users.noreply.github.com> Date: Fri, 7 Nov 2025 12:55:57 +0530 Subject: [PATCH 2/2] fix: use conversation data instead of memory data --- app/lib/backend/schema/conversation.dart | 4 +- app/lib/providers/conversation_provider.dart | 56 ++++---------------- 2 files changed, 13 insertions(+), 47 deletions(-) diff --git a/app/lib/backend/schema/conversation.dart b/app/lib/backend/schema/conversation.dart index c0b674e599..badaba6d02 100644 --- a/app/lib/backend/schema/conversation.dart +++ b/app/lib/backend/schema/conversation.dart @@ -18,7 +18,9 @@ class CreateConversationResponse { factory CreateConversationResponse.fromJson(Map json) { return CreateConversationResponse( messages: ((json['messages'] ?? []) as List).map((message) => ServerMessage.fromJson(message)).toList(), - conversation: json['memory'] != null ? ServerConversation.fromJson(json['memory']) : null, + conversation: json['conversation'] != null + ? ServerConversation.fromJson(json['conversation']) + : (json['memory'] != null ? ServerConversation.fromJson(json['memory']) : null), ); } } diff --git a/app/lib/providers/conversation_provider.dart b/app/lib/providers/conversation_provider.dart index 0ef9283269..8d57190829 100644 --- a/app/lib/providers/conversation_provider.dart +++ b/app/lib/providers/conversation_provider.dart @@ -32,8 +32,6 @@ class ConversationProvider extends ChangeNotifier { List processingConversations = []; - final Set _pendingRefreshConversations = {}; - final AppReviewService _appReviewService = AppReviewService(); bool isFetchingConversations = false; @@ -129,39 +127,8 @@ class ConversationProvider extends ChangeNotifier { } void removeProcessingConversation(String conversationId) { - final convo = processingConversations.where((m) => m.id == conversationId).isNotEmpty - ? processingConversations.firstWhere((m) => m.id == conversationId) - : null; - processingConversations.removeWhere((m) => m.id == conversationId); notifyListeners(); - - if (convo != null && convo.status == ConversationStatus.completed) { - upsertConversation(convo); - } - - _pendingRefreshConversations.add(conversationId); - _refreshDebounceTimer?.cancel(); - - _refreshDebounceTimer = Timer(const Duration(milliseconds: 500), () { - - Set conversationsNeedingRefresh = {}; - - for (String pendingId in _pendingRefreshConversations) { - bool conversationExists = conversations.any((conv) => conv.id == pendingId); - if (!conversationExists) { - conversationsNeedingRefresh.add(pendingId); - } - } - - if (conversationsNeedingRefresh.isNotEmpty) { - forceRefreshConversations(); - } else { - debugPrint('No refresh needed'); - } - - _pendingRefreshConversations.clear(); - }); } void onConversationTap(int idx) { @@ -242,20 +209,17 @@ class ConversationProvider extends ChangeNotifier { processingConversations.insertAll(0, upsertConvos); } - for (var c in newConversations) { - if (c.status == ConversationStatus.completed) { - int idx = conversations.indexWhere((cc) => cc.id == c.id); - if (idx == -1) { - conversations.insert(0, c); - } else { - conversations[idx] = c; - } - } - } + // completed convos + upsertConvos = newConversations + .where((c) => c.status == ConversationStatus.completed && conversations.indexWhere((cc) => cc.id == c.id) == -1) + .toList(); + if (upsertConvos.isNotEmpty) { + // Check if this is the first conversation + bool wasEmpty = conversations.isEmpty; + + conversations.insertAll(0, upsertConvos); - // Check if this is the first conversation for app review - if (conversations.isNotEmpty) { - bool wasEmpty = conversations.length == newConversations.where((c) => c.status == ConversationStatus.completed).length; + // Mark first conversation for app review if (wasEmpty && await _appReviewService.isFirstConversation()) { await _appReviewService.markFirstConversation(); }