refactor(mobile): download button in new timeline (#20010)
* download button * minor improvements
This commit is contained in:
@@ -41,7 +41,8 @@ class ActionNotifier extends Notifier<void> {
|
||||
}
|
||||
|
||||
List<String> _getRemoteIdsForSource(ActionSource source) {
|
||||
return _getIdsForSource<RemoteAsset>(source)
|
||||
return _getAssets(source)
|
||||
.whereType<RemoteAsset>()
|
||||
.toIds()
|
||||
.toList(growable: false);
|
||||
}
|
||||
@@ -63,7 +64,8 @@ class ActionNotifier extends Notifier<void> {
|
||||
|
||||
List<String> _getOwnedRemoteIdsForSource(ActionSource source) {
|
||||
final ownerId = ref.read(currentUserProvider)?.id;
|
||||
return _getIdsForSource<RemoteAsset>(source)
|
||||
return _getAssets(source)
|
||||
.whereType<RemoteAsset>()
|
||||
.ownedAssets(ownerId)
|
||||
.toIds()
|
||||
.toList(growable: false);
|
||||
@@ -331,6 +333,24 @@ class ActionNotifier extends Notifier<void> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<ActionResult> downloadAll(ActionSource source) async {
|
||||
final assets =
|
||||
_getAssets(source).whereType<RemoteAsset>().toList(growable: false);
|
||||
|
||||
try {
|
||||
final didEnqueue = await _service.downloadAll(assets);
|
||||
final enqueueCount = didEnqueue.where((e) => e).length;
|
||||
return ActionResult(count: enqueueCount, success: true);
|
||||
} catch (error, stack) {
|
||||
_logger.severe('Failed to download assets', error, stack);
|
||||
return ActionResult(
|
||||
count: assets.length,
|
||||
success: false,
|
||||
error: error.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension on Iterable<RemoteAsset> {
|
||||
|
||||
Reference in New Issue
Block a user