nc-photos/app/lib/use_case/list_share.dart

44 lines
1.2 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';
2022-12-16 16:01:04 +01:00
import 'package:np_codegen/np_codegen.dart';
part 'list_share.g.dart';
2021-08-07 22:34:44 +02:00
/// List all shares from a given file
2022-12-16 16:01:04 +01:00
@npLog
2021-08-07 22:34:44 +02:00
class ListShare {
ListShare(this._c)
: assert(require(_c)),
assert(FindFile.require(_c));
static bool require(DiContainer c) => DiContainer.has(c, DiType.shareRepo);
2021-08-07 22:34:44 +02:00
Future<List<Share>> call(
Account account,
File file, {
bool? isIncludeReshare,
}) async {
try {
if (file_util.getUserDirName(file) != account.userId) {
2022-01-24 21:32:18 +01:00
file = (await FindFile(_c)(account, [file.fileId!])).first;
}
} catch (_) {
// file not found
_log.warning("[call] File not found in db: ${logFilename(file.path)}");
}
return _c.shareRepo.list(
account,
file,
isIncludeReshare: isIncludeReshare,
);
}
2021-08-07 22:34:44 +02:00
final DiContainer _c;
2021-08-07 22:34:44 +02:00
}