nc-photos/lib/use_case/list_share.dart

33 lines
1 KiB
Dart
Raw Normal View History

import 'package:logging/logging.dart';
2021-08-07 22:34:44 +02:00
import 'package:nc_photos/account.dart';
import 'package:nc_photos/debug_util.dart';
import 'package:nc_photos/di_container.dart';
2021-08-07 22:34:44 +02:00
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
2021-08-07 22:34:44 +02:00
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/use_case/find_file.dart';
2021-08-07 22:34:44 +02:00
/// List all shares from a given file
class ListShare {
ListShare(this._c) : assert(require(_c));
static bool require(DiContainer c) =>
DiContainer.has(c, DiType.shareRepo) && DiContainer.has(c, DiType.appDb);
2021-08-07 22:34:44 +02:00
Future<List<Share>> call(Account account, File file) async {
try {
if (file_util.getUserDirName(file) != account.username) {
file = await FindFile(_c.appDb)(account, file.fileId!);
}
} catch (_) {
// file not found
_log.warning("[call] File not found in db: ${logFilename(file.path)}");
}
return _c.shareRepo.list(account, file);
}
2021-08-07 22:34:44 +02:00
final DiContainer _c;
static final _log = Logger("use_case.list_share.ListShare");
2021-08-07 22:34:44 +02:00
}