Skip to content

Commit

Permalink
fix(mobile): fix forgetting backup albums (#3108)
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Jul 13, 2023
1 parent b71d7e3 commit 1bdc27b
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions mobile/lib/modules/backup/providers/backup.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ class BackupNotifier extends StateNotifier<BackUpState> {
type: RequestType.common,
);

// Map of id -> album for quick album lookup later on.
Map<String, AssetPathEntity> albumMap = {};

log.info('Found ${albums.length} local albums');

for (AssetPathEntity album in albums) {
Expand Down Expand Up @@ -235,6 +238,8 @@ class BackupNotifier extends StateNotifier<BackUpState> {
}

availableAlbums.add(availableAlbum);

albumMap[album.id] = album;
}
}

Expand Down Expand Up @@ -270,30 +275,37 @@ class BackupNotifier extends StateNotifier<BackUpState> {
}

// Generate AssetPathEntity from id to add to local state
try {
final Set<AvailableAlbum> selectedAlbums = {};
for (final BackupAlbum ba in selectedBackupAlbums) {
final albumAsset = await AssetPathEntity.fromId(ba.id);
final Set<AvailableAlbum> selectedAlbums = {};
for (final BackupAlbum ba in selectedBackupAlbums) {
final albumAsset = albumMap[ba.id];

if (albumAsset != null) {
selectedAlbums.add(
AvailableAlbum(albumEntity: albumAsset, lastBackup: ba.lastBackup),
);
} else {
log.severe('Selected album not found');
}
}

final Set<AvailableAlbum> excludedAlbums = {};
for (final BackupAlbum ba in excludedBackupAlbums) {
final albumAsset = albumMap[ba.id];

final Set<AvailableAlbum> excludedAlbums = {};
for (final BackupAlbum ba in excludedBackupAlbums) {
final albumAsset = await AssetPathEntity.fromId(ba.id);
if (albumAsset != null) {
excludedAlbums.add(
AvailableAlbum(albumEntity: albumAsset, lastBackup: ba.lastBackup),
);
} else {
log.severe('Excluded album not found');
}
state = state.copyWith(
selectedBackupAlbums: selectedAlbums,
excludedBackupAlbums: excludedAlbums,
);
} catch (e, stackTrace) {
log.severe("Failed to generate album from id", e, stackTrace);
}

state = state.copyWith(
selectedBackupAlbums: selectedAlbums,
excludedBackupAlbums: excludedAlbums,
);

debugPrint("_getBackupAlbumsInfo takes ${stopwatch.elapsedMilliseconds}ms");
}

Expand Down

0 comments on commit 1bdc27b

Please sign in to comment.