refactor(mobile): download button in new timeline (#20010)

* download button

* minor improvements
This commit is contained in:
Mert
2025-07-19 12:34:17 +03:00
committed by GitHub
parent fafb88d31c
commit 261818ddd9
12 changed files with 170 additions and 21 deletions
@@ -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> {