mirror of
https://github.com/immich-app/immich.git
synced 2026-01-24 02:14:46 -08:00
keep messaging album on first use
This commit is contained in:
@@ -88,7 +88,8 @@ enum StoreKey<T> {
|
||||
cleanupKeepFavorites<bool>._(1008),
|
||||
cleanupKeepMediaType<int>._(1009),
|
||||
cleanupKeepAlbumIds<String>._(1010),
|
||||
cleanupCutoffDaysAgo<int>._(1011);
|
||||
cleanupCutoffDaysAgo<int>._(1011),
|
||||
cleanupDefaultsInitialized<bool>._(1012);
|
||||
|
||||
const StoreKey._(this.id);
|
||||
final int id;
|
||||
|
||||
@@ -123,7 +123,6 @@ class CleanupNotifier extends StateNotifier<CleanupState> {
|
||||
_appSettingsService.setSetting(AppSettingsEnum.cleanupKeepAlbumIds, albumIds.join(','));
|
||||
}
|
||||
|
||||
/// Remove album IDs that no longer exist on the device
|
||||
void cleanupStaleAlbumIds(Set<String> existingAlbumIds) {
|
||||
final staleIds = state.keepAlbumIds.difference(existingAlbumIds);
|
||||
if (staleIds.isNotEmpty) {
|
||||
@@ -133,6 +132,21 @@ class CleanupNotifier extends StateNotifier<CleanupState> {
|
||||
}
|
||||
}
|
||||
|
||||
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<void> scanAssets() async {
|
||||
if (_userId == null || state.selectedDate == null) {
|
||||
return;
|
||||
|
||||
@@ -58,7 +58,8 @@ enum AppSettingsEnum<T> {
|
||||
cleanupKeepFavorites<bool>(StoreKey.cleanupKeepFavorites, null, true),
|
||||
cleanupKeepMediaType<int>(StoreKey.cleanupKeepMediaType, null, 0),
|
||||
cleanupKeepAlbumIds<String>(StoreKey.cleanupKeepAlbumIds, null, ""),
|
||||
cleanupCutoffDaysAgo<int>(StoreKey.cleanupCutoffDaysAgo, null, -1);
|
||||
cleanupCutoffDaysAgo<int>(StoreKey.cleanupCutoffDaysAgo, null, -1),
|
||||
cleanupDefaultsInitialized<bool>(StoreKey.cleanupDefaultsInitialized, null, false);
|
||||
|
||||
const AppSettingsEnum(this.storeKey, this.hiveKey, this.defaultValue);
|
||||
|
||||
|
||||
@@ -43,4 +43,18 @@ class CleanupService {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Returns album IDs that should be kept by default (e.g., messaging app albums)
|
||||
Set<String> getDefaultKeepAlbumIds(List<(String id, String name)> albums) {
|
||||
const messagingApps = ['whatsapp', 'telegram', 'signal', 'messenger', 'viber', 'wechat', 'line'];
|
||||
|
||||
final toKeep = <String>{};
|
||||
for (final (id, name) in albums) {
|
||||
final albumName = name.toLowerCase();
|
||||
if (messagingApps.any((app) => albumName.contains(app))) {
|
||||
toKeep.add(id);
|
||||
}
|
||||
}
|
||||
return toKeep;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,24 @@ class _FreeUpSpaceSettingsState extends ConsumerState<FreeUpSpaceSettings> {
|
||||
bool _hasScanned = false;
|
||||
bool _isKeepSettingsExpanded = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_initializeAlbumDefaults();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _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: [
|
||||
|
||||
Reference in New Issue
Block a user