Skip to content

Commit

Permalink
Dont show new discarded convo if the user is filtering not-include-di…
Browse files Browse the repository at this point in the history
…scarded (#1705)
  • Loading branch information
beastoin authored Jan 16, 2025
2 parents e0b1bda + 4b2dafd commit c8c6b93
Showing 1 changed file with 10 additions and 52 deletions.
62 changes: 10 additions & 52 deletions app/lib/providers/conversation_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener
totalSearchPages = 0;
searchedConversations = [];
groupConversationsByDate();

notifyListeners();
return;
}

Expand Down Expand Up @@ -192,7 +190,12 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener
}

List<ServerConversation> _filterOutConvos(List<ServerConversation> convos) {
return convos;
return convos.where((convo) {
if (!showDiscardedConversations && convo.discarded) {
return false;
}
return true;
}).toList();
}

void _groupSearchConvosByDateWithoutNotify() {
Expand Down Expand Up @@ -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 =
Expand All @@ -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();
}

Expand All @@ -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)) {
Expand Down Expand Up @@ -361,7 +328,7 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener
}
}
conversations.sort((a, b) => b.createdAt.compareTo(a.createdAt));
groupConversationsByDate();
_groupConversationsByDateWithoutNotify();
notifyListeners();
}

Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit c8c6b93

Please sign in to comment.