2021-10-18 12:46:06 +02:00
|
|
|
import 'package:nc_photos/account.dart';
|
|
|
|
import 'package:nc_photos/entity/album.dart';
|
|
|
|
import 'package:nc_photos/entity/file.dart';
|
|
|
|
import 'package:nc_photos/entity/share.dart';
|
|
|
|
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
2021-10-23 20:59:25 +02:00
|
|
|
import 'package:nc_photos/use_case/list_dir_share.dart';
|
2021-10-18 12:46:06 +02:00
|
|
|
import 'package:nc_photos/use_case/ls.dart';
|
|
|
|
|
|
|
|
class ListSharedAlbumItem {
|
|
|
|
const ListSharedAlbumItem(this.share, this.album);
|
|
|
|
|
|
|
|
final Share share;
|
|
|
|
final Album album;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ListSharedAlbum {
|
|
|
|
const ListSharedAlbum(this.shareRepo, this.fileRepo, this.albumRepo);
|
|
|
|
|
|
|
|
/// List albums that are currently shared by you
|
|
|
|
///
|
|
|
|
/// If [whereShareWith] is not null, only shares sharing with [whereShareWith]
|
|
|
|
/// will be returned.
|
|
|
|
Future<List<ListSharedAlbumItem>> call(
|
|
|
|
Account account, {
|
|
|
|
String? whereShareWith,
|
|
|
|
}) async {
|
2021-10-23 20:59:25 +02:00
|
|
|
final shareItems = await ListDirShare(shareRepo)(
|
2021-10-18 12:46:06 +02:00
|
|
|
account, File(path: remote_storage_util.getRemoteAlbumsDir(account)));
|
|
|
|
final files = await Ls(fileRepo)(
|
|
|
|
account,
|
|
|
|
File(path: remote_storage_util.getRemoteAlbumsDir(account)),
|
|
|
|
);
|
|
|
|
|
|
|
|
final products = <ListSharedAlbumItem>[];
|
2021-10-23 20:59:25 +02:00
|
|
|
for (final si in shareItems) {
|
2021-10-18 12:46:06 +02:00
|
|
|
// find the file
|
|
|
|
final albumFile =
|
2021-10-23 20:59:25 +02:00
|
|
|
files.firstWhere((element) => element.compareServerIdentity(si.file));
|
2021-10-18 12:46:06 +02:00
|
|
|
final album = await albumRepo.get(
|
|
|
|
account,
|
|
|
|
albumFile,
|
|
|
|
);
|
2021-10-23 20:59:25 +02:00
|
|
|
for (final s in si.shares) {
|
2021-10-18 12:46:06 +02:00
|
|
|
if (whereShareWith != null && s.shareWith != whereShareWith) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
products.add(ListSharedAlbumItem(s, album));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return products;
|
|
|
|
}
|
|
|
|
|
|
|
|
final ShareRepo shareRepo;
|
|
|
|
final FileRepo fileRepo;
|
|
|
|
final AlbumRepo albumRepo;
|
|
|
|
}
|