From 06d6fa2df0121649bdbabc479333e13c4f3466a6 Mon Sep 17 00:00:00 2001 From: Matthias Nehlsen Date: Sun, 5 May 2024 17:10:42 +0200 Subject: [PATCH] feat: improve task refresh logic --- lib/blocs/journal/journal_page_cubit.dart | 24 ++++++++++++++++------- pubspec.yaml | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/blocs/journal/journal_page_cubit.dart b/lib/blocs/journal/journal_page_cubit.dart index de0e07e96..5e6429daa 100644 --- a/lib/blocs/journal/journal_page_cubit.dart +++ b/lib/blocs/journal/journal_page_cubit.dart @@ -87,20 +87,29 @@ class JournalPageCubit extends Cubit { ); } + String idMapper(JournalEntity entity) => entity.meta.id; + _updateNotifications.updateStream .throttleTime( const Duration(milliseconds: 500), leading: false, trailing: true, ) - .listen((event) { + .listen((event) async { if (_isVisible) { - final displayedIds = - state.pagingController.itemList?.map((e) => e.meta.id).toSet() ?? - {}; - - if (displayedIds.contains(event.id)) { - refreshQuery(); + if (showTasks) { + final newIds = (await _runQuery(0)).map(idMapper).toSet(); + if (!setEquals(_lastIds, newIds)) { + _lastIds = newIds; + await refreshQuery(); + } + } else { + final displayedIds = + state.pagingController.itemList?.map(idMapper).toSet() ?? {}; + + if (displayedIds.contains(event.id)) { + await refreshQuery(); + } } } }); @@ -122,6 +131,7 @@ class JournalPageCubit extends Cubit { bool taskAsListView = true; Set _fullTextMatches = {}; + Set _lastIds = {}; Set _selectedTaskStatuses = { 'OPEN', 'GROOMED', diff --git a/pubspec.yaml b/pubspec.yaml index e4eeb8030..91a805d73 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: lotti description: Achieve your goals and keep your data private with Lotti. publish_to: 'none' -version: 0.9.459+2504 +version: 0.9.459+2505 msix_config: display_name: LottiApp