mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Fix dir collection not populating correctly when offline
This commit is contained in:
parent
cb62b76d87
commit
64a4fa825f
2 changed files with 50 additions and 15 deletions
|
@ -298,6 +298,8 @@ class CollectionItemsController {
|
|||
Future<void> _load() async {
|
||||
try {
|
||||
List<CollectionItem>? items;
|
||||
ExceptionEvent? originalException;
|
||||
try {
|
||||
await for (final r in ListCollectionItem(_c)(account, collection)) {
|
||||
items = r;
|
||||
_dataStreamController.add(CollectionItemStreamData(
|
||||
|
@ -306,18 +308,46 @@ class CollectionItemsController {
|
|||
hasNext: true,
|
||||
));
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
_log.severe("[_load] Failed while ListCollectionItem, try with local",
|
||||
e, stackTrace);
|
||||
originalException = ExceptionEvent(e, stackTrace);
|
||||
}
|
||||
if (originalException != null) {
|
||||
// try again with local repos
|
||||
try {
|
||||
await for (final r
|
||||
in ListCollectionItem(_c.withLocalRepo())(account, collection)) {
|
||||
items = r;
|
||||
_dataStreamController.add(CollectionItemStreamData(
|
||||
items: r,
|
||||
rawItems: r,
|
||||
hasNext: true,
|
||||
));
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
_log.severe(
|
||||
"[_load] Failed while ListCollectionItem with local repos",
|
||||
e,
|
||||
stackTrace);
|
||||
originalException.throwMe();
|
||||
}
|
||||
}
|
||||
if (items != null) {
|
||||
_dataStreamController.add(CollectionItemStreamData(
|
||||
items: items,
|
||||
rawItems: items,
|
||||
hasNext: false,
|
||||
));
|
||||
if (originalException == null) {
|
||||
// only update if the data is queried from remote
|
||||
final newCollection =
|
||||
await UpdateCollectionPostLoad(_c)(account, collection, items);
|
||||
if (newCollection != null) {
|
||||
onCollectionUpdated(newCollection);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
_dataStreamController
|
||||
..addError(e, stackTrace)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:clock/clock.dart';
|
||||
import 'package:kiwi/kiwi.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/debug_util.dart';
|
||||
|
@ -41,14 +40,17 @@ class PopulateAlbum {
|
|||
assert(album.provider is AlbumDirProvider);
|
||||
final provider = album.provider as AlbumDirProvider;
|
||||
final products = <AlbumItem>[];
|
||||
var hasGood = false;
|
||||
ExceptionEvent? firstException;
|
||||
for (final d in provider.dirs) {
|
||||
final stream = ScanDir(_c.fileRepo)(account, d);
|
||||
await for (final result in stream) {
|
||||
if (result is ExceptionEvent) {
|
||||
_log.shout(
|
||||
_log.severe(
|
||||
"[_populateDirAlbum] Failed while scanning dir: ${logFilename(d.path)}",
|
||||
result.error,
|
||||
result.stackTrace);
|
||||
firstException = result;
|
||||
continue;
|
||||
}
|
||||
products.addAll((result as List).cast<File>().map((f) => AlbumFileItem(
|
||||
|
@ -57,8 +59,12 @@ class PopulateAlbum {
|
|||
file: f,
|
||||
ownerId: f.ownerId ?? account.userId,
|
||||
)));
|
||||
hasGood = true;
|
||||
}
|
||||
}
|
||||
if (!hasGood && firstException != null) {
|
||||
firstException.throwMe();
|
||||
}
|
||||
return products;
|
||||
}
|
||||
|
||||
|
@ -67,8 +73,7 @@ class PopulateAlbum {
|
|||
assert(album.provider is AlbumTagProvider);
|
||||
final provider = album.provider as AlbumTagProvider;
|
||||
final products = <AlbumItem>[];
|
||||
final c = KiwiContainer().resolve<DiContainer>();
|
||||
final files = await ListTaggedFile(c)(account, provider.tags);
|
||||
final files = await ListTaggedFile(_c)(account, provider.tags);
|
||||
products.addAll(files.map((f) => AlbumFileItem(
|
||||
addedBy: account.userId,
|
||||
addedAt: clock.now(),
|
||||
|
|
Loading…
Reference in a new issue