Skip to content

Commit

Permalink
Rebased #202409281519
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin committed Sep 28, 2024
1 parent 7fcacfd commit 8f761c8
Showing 1 changed file with 3 additions and 77 deletions.
80 changes: 3 additions & 77 deletions app/lib/providers/memory_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,77 +21,6 @@ class MemoryProvider extends ChangeNotifier {
List<ServerProcessingMemory> processingMemories = [];
Timer? _processingMemoryWatchTimer;

void _populateMemoriesWithDatesWithoutNotify() {
memoriesWithDates = [];
for (var i = 0; i < filteredMemories.length; i++) {
if (i == 0) {
memoriesWithDates.add(filteredMemories[i]);
} else {
if (filteredMemories[i].createdAt.day != filteredMemories[i - 1].createdAt.day) {
memoriesWithDates.add(filteredMemories[i].createdAt);
}
memoriesWithDates.add(filteredMemories[i]);
}
}
}

void _filterMemoriesWithoutNotify(String query) {
filteredMemories = [];
filteredMemories = SharedPreferencesUtil().showDiscardedMemories
? memories
: memories.where((memory) => !memory.discarded || memory.isNew).toList();
filteredMemories = query.isEmpty
? filteredMemories
: filteredMemories
.where(
(memory) => (memory.getTranscript() + memory.structured.title + memory.structured.overview)
.toLowerCase()
.contains(query.toLowerCase()),
)
.toList();
if (query == '' && filteredMemories.isEmpty) {
filteredMemories = memories;
SharedPreferencesUtil().showDiscardedMemories = true;
hasNonDiscardedMemories = false;
}
}

void populateMemoriesWithDates() {
_populateMemoriesWithDatesWithoutNotify();
notifyListeners();
}

void initFilteredMemories() {
_filterMemoriesWithoutNotify('');
_populateMemoriesWithDatesWithoutNotify();
notifyListeners();
}

void filterMemories(String query) {
filteredMemories = [];
filteredMemories = SharedPreferencesUtil().showDiscardedMemories
? memories
: memories.where((memory) => !memory.discarded || memory.isNew).toList();
filteredMemories = query.isEmpty
? filteredMemories
: filteredMemories
.where(
(memory) => (memory.getTranscript() + memory.structured.title + memory.structured.overview)
.toLowerCase()
.contains(query.toLowerCase()),
)
.toList();
if (query == '' && filteredMemories.isEmpty) {
filteredMemories = memories;
SharedPreferencesUtil().showDiscardedMemories = true;
hasNonDiscardedMemories = false;
}

_populateMemoriesWithDatesWithoutNotify();

notifyListeners();
}

void toggleDiscardMemories() {
MixpanelManager().showDiscardedMemoriesToggled(!SharedPreferencesUtil().showDiscardedMemories);
SharedPreferencesUtil().showDiscardedMemories = !SharedPreferencesUtil().showDiscardedMemories;
Expand Down Expand Up @@ -123,7 +52,7 @@ class MemoryProvider extends ChangeNotifier {
void groupMemoriesByDate() {
groupedMemories = {};
for (var memory in memories) {
if (SharedPreferencesUtil().showDiscardedMemories && memory.discarded) continue;
if (SharedPreferencesUtil().showDiscardedMemories && memory.discarded && !memory.isNew) continue;
var date = DateTime(memory.createdAt.year, memory.createdAt.month, memory.createdAt.day);
if (!groupedMemories.containsKey(date)) {
groupedMemories[date] = [];
Expand Down Expand Up @@ -159,8 +88,6 @@ class MemoryProvider extends ChangeNotifier {
processingMemories = pms;
notifyListeners();

debugPrint("Set processing memories ${pms.length}");

if (processingMemories.isEmpty) {
_processingMemoryWatchTimer?.cancel();
return;
Expand All @@ -181,7 +108,7 @@ class MemoryProvider extends ChangeNotifier {
}
memories.removeAt(idx);

initFilteredMemories();
filterGroupedMemories('');
}

Future onNewProcessingMemory(ServerProcessingMemory processingMemory) async {
Expand Down Expand Up @@ -220,8 +147,7 @@ class MemoryProvider extends ChangeNotifier {
memories[idx] = memory;
}

// Warn: Too many notifies!
initFilteredMemories();
filterGroupedMemories('');
}

Future _updateProcessingMemories(List<ServerProcessingMemory> pms) async {
Expand Down

0 comments on commit 8f761c8

Please sign in to comment.