mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(mobile): handle readonly and offline assets (#5565)
* feat: add isReadOnly and isOffline fields to Asset collection * refactor: move asset iterable filters to extension * hide asset actions based on offline and readOnly fields * pr changes * chore: doc comments --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
56cde0438c
commit
a233e176e5
10 changed files with 333 additions and 105 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:immich_mobile/shared/models/asset.dart';
|
||||
import 'package:immich_mobile/shared/models/user.dart';
|
||||
|
||||
extension ListExtension<E> on List<E> {
|
||||
List<E> uniqueConsecutive({
|
||||
|
|
@ -39,3 +41,58 @@ extension IntListExtension on Iterable<int> {
|
|||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
extension AssetListExtension on Iterable<Asset> {
|
||||
/// Returns the assets that are already available in the Immich server
|
||||
Iterable<Asset> remoteOnly({
|
||||
void Function()? errorCallback,
|
||||
}) {
|
||||
final bool onlyRemote = every((e) => e.isRemote);
|
||||
if (!onlyRemote) {
|
||||
if (errorCallback != null) errorCallback();
|
||||
return where((a) => a.isRemote);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Returns the assets that are owned by the user passed to the [owner] param
|
||||
/// If [owner] is null, an empty list is returned
|
||||
Iterable<Asset> ownedOnly(
|
||||
User? owner, {
|
||||
void Function()? errorCallback,
|
||||
}) {
|
||||
if (owner == null) return [];
|
||||
final userId = owner.isarId;
|
||||
final bool onlyOwned = every((e) => e.ownerId == userId);
|
||||
if (!onlyOwned) {
|
||||
if (errorCallback != null) errorCallback();
|
||||
return where((a) => a.ownerId == userId);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Returns the assets that are present on a file system which has write permission
|
||||
/// This filters out assets on readOnly external library to which we cannot perform any write operation
|
||||
Iterable<Asset> writableOnly({
|
||||
void Function()? errorCallback,
|
||||
}) {
|
||||
final bool onlyWritable = every((e) => !e.isReadOnly);
|
||||
if (!onlyWritable) {
|
||||
if (errorCallback != null) errorCallback();
|
||||
return where((a) => !a.isReadOnly);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Filters out offline assets and returns those that are still accessible by the Immich server
|
||||
Iterable<Asset> nonOfflineOnly({
|
||||
void Function()? errorCallback,
|
||||
}) {
|
||||
final bool onlyLive = every((e) => !e.isOffline);
|
||||
if (!onlyLive) {
|
||||
if (errorCallback != null) errorCallback();
|
||||
return where((a) => !a.isOffline);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue