mirror of
https://github.com/immich-app/immich.git
synced 2025-04-06 16:16:26 +02:00
refactor(mobile): partners provider (#16299)
* refactor(mobile): partners provider * update analysis option * update analysis option
This commit is contained in:
parent
392f9f205c
commit
579321251f
5 changed files with 90 additions and 17 deletions
mobile
|
@ -65,7 +65,7 @@ custom_lint:
|
|||
allowed:
|
||||
# required / wanted
|
||||
- lib/entities/*.entity.dart
|
||||
- lib/repositories/{album,asset,backup,database,etag,exif_info,user,timeline}.repository.dart
|
||||
- lib/repositories/{album,asset,backup,database,etag,exif_info,user,timeline,partner}.repository.dart
|
||||
- lib/infrastructure/entities/*.entity.dart
|
||||
- lib/infrastructure/repositories/{store,db}.repository.dart
|
||||
- lib/providers/infrastructure/db.provider.dart
|
||||
|
@ -79,7 +79,7 @@ custom_lint:
|
|||
- lib/widgets/asset_grid/asset_grid_data_structure.dart
|
||||
- test/**.dart
|
||||
# refactor the remaining providers
|
||||
- lib/providers/{asset,authentication,db,partner,user}.provider.dart
|
||||
- lib/providers/{asset,authentication,db,user}.provider.dart
|
||||
- lib/providers/{asset_viewer/render_list,backup/backup,search/all_motion_photos,search/recently_added_asset}.provider.dart
|
||||
|
||||
- import_rule_openapi:
|
||||
|
|
8
mobile/lib/interfaces/partner.interface.dart
Normal file
8
mobile/lib/interfaces/partner.interface.dart
Normal file
|
@ -0,0 +1,8 @@
|
|||
import 'package:immich_mobile/entities/user.entity.dart';
|
||||
|
||||
abstract class IPartnerRepository {
|
||||
Future<List<User>> getSharedWith();
|
||||
Future<List<User>> getSharedBy();
|
||||
Stream<List<User>> watchSharedWith();
|
||||
Stream<List<User>> watchSharedBy();
|
||||
}
|
|
@ -5,19 +5,18 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||
import 'package:immich_mobile/providers/album/suggested_shared_users.provider.dart';
|
||||
import 'package:immich_mobile/services/partner.service.dart';
|
||||
import 'package:immich_mobile/entities/user.entity.dart';
|
||||
import 'package:immich_mobile/providers/db.provider.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
|
||||
class PartnerSharedWithNotifier extends StateNotifier<List<User>> {
|
||||
PartnerSharedWithNotifier(Isar db, this._ps) : super([]) {
|
||||
final PartnerService _partnerService;
|
||||
|
||||
PartnerSharedWithNotifier(this._partnerService) : super([]) {
|
||||
Function eq = const ListEquality<User>().equals;
|
||||
final query = db.users.filter().isPartnerSharedWithEqualTo(true).sortById();
|
||||
query.findAll().then((partners) {
|
||||
_partnerService.getSharedWith().then((partners) {
|
||||
if (!eq(state, partners)) {
|
||||
state = partners;
|
||||
}
|
||||
}).then((_) {
|
||||
query.watch().listen((partners) {
|
||||
_partnerService.watchSharedWith().listen((partners) {
|
||||
if (!eq(state, partners)) {
|
||||
state = partners;
|
||||
}
|
||||
|
@ -26,30 +25,28 @@ class PartnerSharedWithNotifier extends StateNotifier<List<User>> {
|
|||
}
|
||||
|
||||
Future<bool> updatePartner(User partner, {required bool inTimeline}) {
|
||||
return _ps.updatePartner(partner, inTimeline: inTimeline);
|
||||
return _partnerService.updatePartner(partner, inTimeline: inTimeline);
|
||||
}
|
||||
|
||||
final PartnerService _ps;
|
||||
}
|
||||
|
||||
final partnerSharedWithProvider =
|
||||
StateNotifierProvider<PartnerSharedWithNotifier, List<User>>((ref) {
|
||||
return PartnerSharedWithNotifier(
|
||||
ref.watch(dbProvider),
|
||||
ref.watch(partnerServiceProvider),
|
||||
);
|
||||
});
|
||||
|
||||
class PartnerSharedByNotifier extends StateNotifier<List<User>> {
|
||||
PartnerSharedByNotifier(Isar db) : super([]) {
|
||||
final PartnerService _partnerService;
|
||||
|
||||
PartnerSharedByNotifier(this._partnerService) : super([]) {
|
||||
Function eq = const ListEquality<User>().equals;
|
||||
final query = db.users.filter().isPartnerSharedByEqualTo(true).sortById();
|
||||
query.findAll().then((partners) {
|
||||
_partnerService.getSharedBy().then((partners) {
|
||||
if (!eq(state, partners)) {
|
||||
state = partners;
|
||||
}
|
||||
}).then((_) {
|
||||
streamSub = query.watch().listen((partners) {
|
||||
streamSub = _partnerService.watchSharedBy().listen((partners) {
|
||||
if (!eq(state, partners)) {
|
||||
state = partners;
|
||||
}
|
||||
|
@ -68,7 +65,7 @@ class PartnerSharedByNotifier extends StateNotifier<List<User>> {
|
|||
|
||||
final partnerSharedByProvider =
|
||||
StateNotifierProvider<PartnerSharedByNotifier, List<User>>((ref) {
|
||||
return PartnerSharedByNotifier(ref.watch(dbProvider));
|
||||
return PartnerSharedByNotifier(ref.watch(partnerServiceProvider));
|
||||
});
|
||||
|
||||
final partnerAvailableProvider =
|
||||
|
|
47
mobile/lib/repositories/partner.repository.dart
Normal file
47
mobile/lib/repositories/partner.repository.dart
Normal file
|
@ -0,0 +1,47 @@
|
|||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/entities/user.entity.dart';
|
||||
import 'package:immich_mobile/interfaces/partner.interface.dart';
|
||||
import 'package:immich_mobile/providers/db.provider.dart';
|
||||
import 'package:immich_mobile/repositories/database.repository.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
|
||||
final partnerRepositoryProvider = Provider(
|
||||
(ref) => PartnerRepository(ref.watch(dbProvider)),
|
||||
);
|
||||
|
||||
class PartnerRepository extends DatabaseRepository
|
||||
implements IPartnerRepository {
|
||||
PartnerRepository(super.db);
|
||||
|
||||
@override
|
||||
Future<List<User>> getSharedBy() {
|
||||
return db.users
|
||||
.filter()
|
||||
.isPartnerSharedByEqualTo(true)
|
||||
.sortById()
|
||||
.findAll();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<User>> getSharedWith() {
|
||||
return db.users
|
||||
.filter()
|
||||
.isPartnerSharedWithEqualTo(true)
|
||||
.sortById()
|
||||
.findAll();
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<User>> watchSharedBy() {
|
||||
return db.users.filter().isPartnerSharedByEqualTo(true).sortById().watch();
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<User>> watchSharedWith() {
|
||||
return db.users
|
||||
.filter()
|
||||
.isPartnerSharedWithEqualTo(true)
|
||||
.sortById()
|
||||
.watch();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/entities/user.entity.dart';
|
||||
import 'package:immich_mobile/interfaces/partner.interface.dart';
|
||||
import 'package:immich_mobile/interfaces/partner_api.interface.dart';
|
||||
import 'package:immich_mobile/interfaces/user.interface.dart';
|
||||
import 'package:immich_mobile/repositories/partner.repository.dart';
|
||||
import 'package:immich_mobile/repositories/partner_api.repository.dart';
|
||||
import 'package:immich_mobile/repositories/user.repository.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
@ -10,19 +12,38 @@ final partnerServiceProvider = Provider(
|
|||
(ref) => PartnerService(
|
||||
ref.watch(partnerApiRepositoryProvider),
|
||||
ref.watch(userRepositoryProvider),
|
||||
ref.watch(partnerRepositoryProvider),
|
||||
),
|
||||
);
|
||||
|
||||
class PartnerService {
|
||||
final IPartnerApiRepository _partnerApiRepository;
|
||||
final IPartnerRepository _partnerRepository;
|
||||
final IUserRepository _userRepository;
|
||||
final Logger _log = Logger("PartnerService");
|
||||
|
||||
PartnerService(
|
||||
this._partnerApiRepository,
|
||||
this._userRepository,
|
||||
this._partnerRepository,
|
||||
);
|
||||
|
||||
Future<List<User>> getSharedWith() async {
|
||||
return _partnerRepository.getSharedWith();
|
||||
}
|
||||
|
||||
Future<List<User>> getSharedBy() async {
|
||||
return _partnerRepository.getSharedBy();
|
||||
}
|
||||
|
||||
Stream<List<User>> watchSharedWith() {
|
||||
return _partnerRepository.watchSharedWith();
|
||||
}
|
||||
|
||||
Stream<List<User>> watchSharedBy() {
|
||||
return _partnerRepository.watchSharedBy();
|
||||
}
|
||||
|
||||
Future<bool> removePartner(User partner) async {
|
||||
try {
|
||||
await _partnerApiRepository.delete(partner.id);
|
||||
|
|
Loading…
Add table
Reference in a new issue