From 4b2dafda9a56308b26fc0f7b65cb513228330e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?th=E1=BB=8Bnh?= Date: Thu, 16 Jan 2025 18:21:41 +0700 Subject: [PATCH] Dont show new discarded convo if the user is filtering not-include-discarded --- app/lib/providers/conversation_provider.dart | 62 ++++---------------- 1 file changed, 10 insertions(+), 52 deletions(-) diff --git a/app/lib/providers/conversation_provider.dart b/app/lib/providers/conversation_provider.dart index ebb333b3c..2cbc745fe 100644 --- a/app/lib/providers/conversation_provider.dart +++ b/app/lib/providers/conversation_provider.dart @@ -77,8 +77,6 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener totalSearchPages = 0; searchedConversations = []; groupConversationsByDate(); - - notifyListeners(); return; } @@ -192,7 +190,12 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener } List _filterOutConvos(List convos) { - return convos; + return convos.where((convo) { + if (!showDiscardedConversations && convo.discarded) { + return false; + } + return true; + }).toList(); } void _groupSearchConvosByDateWithoutNotify() { @@ -247,17 +250,6 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener return conversations; } - // void createEventsForMemories() { - // for (var memory in memories) { - // if (memory.structured.events.isNotEmpty && - // !memory.structured.events.first.created && - // memory.startedAt != null && - // memory.startedAt!.isAfter(DateTime.now().add(const Duration(days: -1)))) { - // _handleCalendarCreation(memory); - // } - // } - // } - void updateActionItemState(String convoId, bool state, int i, DateTime date) { conversations.firstWhere((element) => element.id == convoId).structured.actionItems[i].completed = state; groupedConversations[date]!.firstWhere((element) => element.id == convoId).structured.actionItems[i].completed = @@ -273,14 +265,14 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener await getConversations(offset: conversations.length, includeDiscarded: showDiscardedConversations); conversations.addAll(newConversations); conversations.sort((a, b) => b.createdAt.compareTo(a.createdAt)); - groupConversationsByDate(); + _groupConversationsByDateWithoutNotify(); setLoadingConversations(false); notifyListeners(); } void addConversation(ServerConversation conversation) { conversations.insert(0, conversation); - addConvoToGroupedConversations(conversation); + _groupConversationsByDateWithoutNotify(); notifyListeners(); } @@ -293,31 +285,6 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener } } - void addConvoToGroupedConversations(ServerConversation conversation) { - var date = DateTime(conversation.createdAt.year, conversation.createdAt.month, conversation.createdAt.day); - if (groupedConversations.containsKey(date)) { - groupedConversations[date]!.insert(0, conversation); - groupedConversations[date]!.sort((a, b) => b.createdAt.compareTo(a.createdAt)); - if (syncedConversationsPointers.isNotEmpty) { - // if the synced conversation pointers contain a conversation on this date, then update their index - // This usually happens when a conversation is added to the grouped memories while/after syncing - if (syncedConversationsPointers.where((element) => element.key == date).isNotEmpty) { - var len = syncedConversationsPointers.where((element) => element.key == date).length; - for (var i = 0; i < len; i++) { - var mem = syncedConversationsPointers.where((element) => element.key == date).elementAt(i); - var newIdx = groupedConversations[date]!.indexWhere((m) => m.id == mem.conversation.id); - updateSyncedConversationPointerIndex(mem, newIdx); - } - } - } - } else { - groupedConversations[date] = [conversation]; - groupedConversations = - Map.fromEntries(groupedConversations.entries.toList()..sort((a, b) => b.key.compareTo(a.key))); - } - notifyListeners(); - } - void updateConversationInSortedList(ServerConversation conversation) { var date = DateTime(conversation.createdAt.year, conversation.createdAt.month, conversation.createdAt.day); if (groupedConversations.containsKey(date)) { @@ -361,7 +328,7 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener } } conversations.sort((a, b) => b.createdAt.compareTo(a.createdAt)); - groupConversationsByDate(); + _groupConversationsByDateWithoutNotify(); notifyListeners(); } @@ -406,21 +373,12 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener memoriesToDelete.remove(conversationId); } - void undoDeleteConversation(String conversationId, int index) { - if (memoriesToDelete.containsKey(conversationId)) { - ServerConversation conversation = memoriesToDelete.remove(conversationId)!; - conversations.insert(0, conversation); - addConvoToGroupedConversations(conversation); - } - notifyListeners(); - } - ///////////////////////////////////////////////////////////////// void deleteConversation(ServerConversation conversation, int index) { conversations.removeWhere((element) => element.id == conversation.id); deleteConversationServer(conversation.id); - groupConversationsByDate(); + _groupConversationsByDateWithoutNotify(); notifyListeners(); }