2021-12-03 18:32:38 +01:00
|
|
|
import 'package:logging/logging.dart';
|
2021-08-07 22:34:44 +02:00
|
|
|
import 'package:nc_photos/account.dart';
|
2021-12-03 18:32:38 +01:00
|
|
|
import 'package:nc_photos/debug_util.dart';
|
2021-12-03 18:31:27 +01:00
|
|
|
import 'package:nc_photos/di_container.dart';
|
2021-08-07 22:34:44 +02:00
|
|
|
import 'package:nc_photos/entity/file.dart';
|
2021-12-03 18:32:38 +01:00
|
|
|
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';
|
2021-12-03 18:32:38 +01:00
|
|
|
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 {
|
2021-12-07 19:42:25 +01:00
|
|
|
ListShare(this._c)
|
|
|
|
: assert(require(_c)),
|
|
|
|
assert(FindFile.require(_c));
|
2021-12-03 18:31:27 +01:00
|
|
|
|
2021-12-07 19:42:25 +01:00
|
|
|
static bool require(DiContainer c) => DiContainer.has(c, DiType.shareRepo);
|
2021-08-07 22:34:44 +02:00
|
|
|
|
2021-12-07 15:28:10 +01:00
|
|
|
Future<List<Share>> call(
|
|
|
|
Account account,
|
|
|
|
File file, {
|
|
|
|
bool? isIncludeReshare,
|
|
|
|
}) async {
|
2021-12-03 18:32:38 +01:00
|
|
|
try {
|
2022-01-16 22:38:09 +01:00
|
|
|
if (file_util.getUserDirName(file) != account.homeDir) {
|
2021-12-07 19:42:25 +01:00
|
|
|
file = await FindFile(_c)(account, file.fileId!);
|
2021-12-03 18:32:38 +01:00
|
|
|
}
|
|
|
|
} catch (_) {
|
|
|
|
// file not found
|
|
|
|
_log.warning("[call] File not found in db: ${logFilename(file.path)}");
|
|
|
|
}
|
2021-12-07 15:28:10 +01:00
|
|
|
return _c.shareRepo.list(
|
|
|
|
account,
|
|
|
|
file,
|
|
|
|
isIncludeReshare: isIncludeReshare,
|
|
|
|
);
|
2021-12-03 18:32:38 +01:00
|
|
|
}
|
2021-08-07 22:34:44 +02:00
|
|
|
|
2021-12-03 18:31:27 +01:00
|
|
|
final DiContainer _c;
|
2021-12-03 18:32:38 +01:00
|
|
|
|
|
|
|
static final _log = Logger("use_case.list_share.ListShare");
|
2021-08-07 22:34:44 +02:00
|
|
|
}
|