List albums shared by me

This commit is contained in:
Ming Ming 2021-10-19 04:27:30 +08:00
parent 0478fe3840
commit 1106dfc72f

View file

@ -196,25 +196,25 @@ class ListSharingBloc extends Bloc<ListSharingBlocEvent, ListSharingBlocState> {
path: remote_storage_util.getRemoteAlbumsDir(ev.account), path: remote_storage_util.getRemoteAlbumsDir(ev.account),
)); ));
return (await Future.wait([ return (await Future.wait([
_querySharesByMe(ev), _querySharesByMe(ev, sharedAlbumFiles),
_querySharesWithMe(ev, sharedAlbumFiles), _querySharesWithMe(ev, sharedAlbumFiles),
])) ]))
.reduce((value, element) => value + element); .reduce((value, element) => value + element);
} }
Future<List<ListSharingItem>> _querySharesByMe( Future<List<ListSharingItem>> _querySharesByMe(
ListSharingBlocQuery ev) async { ListSharingBlocQuery ev, List<File> sharedAlbumFiles) async {
final shareRepo = ShareRepo(ShareRemoteDataSource()); final shareRepo = ShareRepo(ShareRemoteDataSource());
final shares = await shareRepo.listAll(ev.account); final shares = await shareRepo.listAll(ev.account);
final futures = shares.map((e) async { final futures = shares.map((s) async {
final webdavPath =
"${api_util.getWebdavRootUrlRelative(ev.account)}/${s.path}";
// include link share dirs // include link share dirs
if (e.itemType == ShareItemType.folder) { if (s.itemType == ShareItemType.folder) {
final webdavPath =
"${api_util.getWebdavRootUrlRelative(ev.account)}/${e.path}";
if (webdavPath.startsWith( if (webdavPath.startsWith(
remote_storage_util.getRemoteLinkSharesDir(ev.account))) { remote_storage_util.getRemoteLinkSharesDir(ev.account))) {
return ListSharingFile( return ListSharingFile(
e, s,
File( File(
path: webdavPath, path: webdavPath,
isCollection: true, isCollection: true,
@ -222,8 +222,23 @@ class ListSharingBloc extends Bloc<ListSharingBlocEvent, ListSharingBlocState> {
); );
} }
} }
// include shared albums
if (path.dirname(webdavPath) ==
remote_storage_util.getRemoteAlbumsDir(ev.account)) {
try {
final file = sharedAlbumFiles
.firstWhere((element) => element.fileId == s.itemSource);
return await _querySharedAlbum(ev, s, file);
} catch (e, stackTrace) {
_log.severe(
"[_querySharesWithMe] Shared album not found: ${s.itemSource}",
e,
stackTrace);
return null;
}
}
if (!file_util.isSupportedMime(e.mimeType)) { if (!file_util.isSupportedMime(s.mimeType)) {
return null; return null;
} }
// show only link shares // show only link shares
@ -231,14 +246,14 @@ class ListSharingBloc extends Bloc<ListSharingBlocEvent, ListSharingBlocState> {
return null; return null;
} }
if (ev.account.roots if (ev.account.roots
.every((r) => r.isNotEmpty && !e.path.startsWith("/$r/"))) { .every((r) => r.isNotEmpty && !s.path.startsWith("/$r/"))) {
// ignore files not under root dirs // ignore files not under root dirs
return null; return null;
} }
try { try {
final file = await FindFile()(ev.account, e.itemSource); final file = await FindFile()(ev.account, s.itemSource);
return ListSharingFile(e, file); return ListSharingFile(s, file);
} catch (_) { } catch (_) {
_log.warning("[_querySharesByMe] File not found: ${e.itemSource}"); _log.warning("[_querySharesByMe] File not found: ${e.itemSource}");
return null; return null;