From 19b35fb625aa10b50ebdce1b3b7fa7829de999ce Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 23 Jan 2026 13:12:08 -0600 Subject: [PATCH] keep messaging album on first use --- mobile/lib/domain/models/store.model.dart | 3 ++- mobile/lib/providers/cleanup.provider.dart | 16 ++++++++++- mobile/lib/services/app_settings.service.dart | 3 ++- mobile/lib/services/cleanup.service.dart | 14 ++++++++++ .../settings/free_up_space_settings.dart | 27 ++++++++++++------- 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/mobile/lib/domain/models/store.model.dart b/mobile/lib/domain/models/store.model.dart index 1639a47dbb..eaf9593f0b 100644 --- a/mobile/lib/domain/models/store.model.dart +++ b/mobile/lib/domain/models/store.model.dart @@ -88,7 +88,8 @@ enum StoreKey { cleanupKeepFavorites._(1008), cleanupKeepMediaType._(1009), cleanupKeepAlbumIds._(1010), - cleanupCutoffDaysAgo._(1011); + cleanupCutoffDaysAgo._(1011), + cleanupDefaultsInitialized._(1012); const StoreKey._(this.id); final int id; diff --git a/mobile/lib/providers/cleanup.provider.dart b/mobile/lib/providers/cleanup.provider.dart index f03198f46c..4d0bdba301 100644 --- a/mobile/lib/providers/cleanup.provider.dart +++ b/mobile/lib/providers/cleanup.provider.dart @@ -123,7 +123,6 @@ class CleanupNotifier extends StateNotifier { _appSettingsService.setSetting(AppSettingsEnum.cleanupKeepAlbumIds, albumIds.join(',')); } - /// Remove album IDs that no longer exist on the device void cleanupStaleAlbumIds(Set existingAlbumIds) { final staleIds = state.keepAlbumIds.difference(existingAlbumIds); if (staleIds.isNotEmpty) { @@ -133,6 +132,21 @@ class CleanupNotifier extends StateNotifier { } } + void applyDefaultAlbumSelections(List<(String id, String name)> albums) { + final isInitialized = _appSettingsService.getSetting(AppSettingsEnum.cleanupDefaultsInitialized); + if (isInitialized) return; + + final toKeep = _cleanupService.getDefaultKeepAlbumIds(albums); + + if (toKeep.isNotEmpty) { + final keepAlbumIds = {...state.keepAlbumIds, ...toKeep}; + state = state.copyWith(keepAlbumIds: keepAlbumIds); + _persistExcludedAlbumIds(keepAlbumIds); + } + + _appSettingsService.setSetting(AppSettingsEnum.cleanupDefaultsInitialized, true); + } + Future scanAssets() async { if (_userId == null || state.selectedDate == null) { return; diff --git a/mobile/lib/services/app_settings.service.dart b/mobile/lib/services/app_settings.service.dart index b6e03e3f38..4e740ebfe5 100644 --- a/mobile/lib/services/app_settings.service.dart +++ b/mobile/lib/services/app_settings.service.dart @@ -58,7 +58,8 @@ enum AppSettingsEnum { cleanupKeepFavorites(StoreKey.cleanupKeepFavorites, null, true), cleanupKeepMediaType(StoreKey.cleanupKeepMediaType, null, 0), cleanupKeepAlbumIds(StoreKey.cleanupKeepAlbumIds, null, ""), - cleanupCutoffDaysAgo(StoreKey.cleanupCutoffDaysAgo, null, -1); + cleanupCutoffDaysAgo(StoreKey.cleanupCutoffDaysAgo, null, -1), + cleanupDefaultsInitialized(StoreKey.cleanupDefaultsInitialized, null, false); const AppSettingsEnum(this.storeKey, this.hiveKey, this.defaultValue); diff --git a/mobile/lib/services/cleanup.service.dart b/mobile/lib/services/cleanup.service.dart index 3018d0536d..86ccac8067 100644 --- a/mobile/lib/services/cleanup.service.dart +++ b/mobile/lib/services/cleanup.service.dart @@ -43,4 +43,18 @@ class CleanupService { return 0; } + + /// Returns album IDs that should be kept by default (e.g., messaging app albums) + Set getDefaultKeepAlbumIds(List<(String id, String name)> albums) { + const messagingApps = ['whatsapp', 'telegram', 'signal', 'messenger', 'viber', 'wechat', 'line']; + + final toKeep = {}; + for (final (id, name) in albums) { + final albumName = name.toLowerCase(); + if (messagingApps.any((app) => albumName.contains(app))) { + toKeep.add(id); + } + } + return toKeep; + } } diff --git a/mobile/lib/widgets/settings/free_up_space_settings.dart b/mobile/lib/widgets/settings/free_up_space_settings.dart index 479a777812..91eb4e16d3 100644 --- a/mobile/lib/widgets/settings/free_up_space_settings.dart +++ b/mobile/lib/widgets/settings/free_up_space_settings.dart @@ -26,6 +26,24 @@ class _FreeUpSpaceSettingsState extends ConsumerState { bool _hasScanned = false; bool _isKeepSettingsExpanded = false; + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addPostFrameCallback((_) { + _initializeAlbumDefaults(); + }); + } + + Future _initializeAlbumDefaults() async { + final albums = await ref.read(localAlbumProvider.future); + final existingAlbumIds = albums.map((a) => a.id).toSet(); + final albumsWithNames = albums.map((a) => (a.id, a.name)).toList(); + + final notifier = ref.read(cleanupProvider.notifier); + notifier.applyDefaultAlbumSelections(albumsWithNames); + notifier.cleanupStaleAlbumIds(existingAlbumIds); + } + void _resetState() { ref.read(cleanupProvider.notifier).reset(); _hasScanned = false; @@ -779,15 +797,6 @@ class _KeepAlbumsSection extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final albumsAsync = ref.watch(localAlbumProvider); - // Clean up stale album IDs when albums are loaded - albumsAsync.whenData((albums) { - final existingAlbumIds = albums.map((a) => a.id).toSet(); - // Use Future.microtask to avoid modifying state during build - Future.microtask(() { - ref.read(cleanupProvider.notifier).cleanupStaleAlbumIds(existingAlbumIds); - }); - }); - return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [