From af6f6ee08827287ba99c762345034d6eb20e8063 Mon Sep 17 00:00:00 2001 From: KhaledNjim Date: Wed, 4 Sep 2024 00:10:27 +0100 Subject: [PATCH] LA-1352 sync deleted recieved shares with local db --- domain/lib/domain.dart | 1 + .../get_all_received_shares_interactor.dart | 10 +++++++- ...ed_received_share_from_local_database.dart | 24 +++++++++++++++++++ lib/presentation/di/module/app_module.dart | 7 +++++- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 domain/lib/src/usecases/received/remove_deleted_received_share_from_local_database.dart diff --git a/domain/lib/domain.dart b/domain/lib/domain.dart index cc57b3343..0b35ea86a 100644 --- a/domain/lib/domain.dart +++ b/domain/lib/domain.dart @@ -512,3 +512,4 @@ export 'src/usecases/workgroup/get_all_workgroups_interactor.dart'; export 'src/usecases/workgroup/get_all_workgroups_offline_interactor.dart'; export 'src/usecases/workgroup/workgroup_exception.dart'; export 'src/usecases/workgroup/workgroup_view_state.dart'; +export 'src/usecases/received/remove_deleted_received_share_from_local_database.dart'; \ No newline at end of file diff --git a/domain/lib/src/usecases/received/get_all_received_shares_interactor.dart b/domain/lib/src/usecases/received/get_all_received_shares_interactor.dart index 8d15e2d5d..49140f6ec 100644 --- a/domain/lib/src/usecases/received/get_all_received_shares_interactor.dart +++ b/domain/lib/src/usecases/received/get_all_received_shares_interactor.dart @@ -38,11 +38,16 @@ import 'package:domain/src/repository/received/received_share_repository.dart'; import 'package:domain/src/state/failure.dart'; import 'package:domain/src/state/success.dart'; import 'package:domain/src/usecases/received/received_share_view_state.dart'; +import 'package:collection/collection.dart'; +import 'package:domain/src/usecases/received/remove_deleted_received_share_from_local_database.dart'; class GetAllReceivedSharesInteractor { final ReceivedShareRepository _receivedShareRepository; + final RemoveDeletedReceivedShareFromLocalDatabaseInteractor + _removeDeletedReceivedShareFromLocalDatabase; - GetAllReceivedSharesInteractor(this._receivedShareRepository); + GetAllReceivedSharesInteractor(this._receivedShareRepository, + this._removeDeletedReceivedShareFromLocalDatabase); Future> execute(String recipient) async { try { @@ -51,6 +56,9 @@ class GetAllReceivedSharesInteractor { .getAllReceivedShareOfflineByRecipient(recipient)); final combinedReceivedShares = List.empty(growable: true); + _removeDeletedReceivedShareFromLocalDatabase.execute( + receivedShares, recipient); + if (receivedShares.isNotEmpty) { for (final received in receivedShares) { final localReceivedShare = await _receivedShareRepository diff --git a/domain/lib/src/usecases/received/remove_deleted_received_share_from_local_database.dart b/domain/lib/src/usecases/received/remove_deleted_received_share_from_local_database.dart new file mode 100644 index 000000000..b02f7565d --- /dev/null +++ b/domain/lib/src/usecases/received/remove_deleted_received_share_from_local_database.dart @@ -0,0 +1,24 @@ +import 'package:domain/domain.dart'; +import 'package:collection/collection.dart'; + +class RemoveDeletedReceivedShareFromLocalDatabaseInteractor { + final ReceivedShareRepository _receivedShareRepository; + + RemoveDeletedReceivedShareFromLocalDatabaseInteractor( + this._receivedShareRepository); + + Future execute( + List receivedShares, String recipient) async { + var localRecievedShares = await _receivedShareRepository + .getAllReceivedShareOfflineByRecipient(recipient); + + for (final localReceived in localRecievedShares) { + final receivedShare = receivedShares.firstWhereOrNull( + (received) => received.shareId == localReceived.shareId); + if (receivedShare == null) { + await _receivedShareRepository.disableOffline( + localReceived.shareId, localReceived.localPath ?? ''); + } + } + } +} diff --git a/lib/presentation/di/module/app_module.dart b/lib/presentation/di/module/app_module.dart index c7e41ede8..35ee40bea 100644 --- a/lib/presentation/di/module/app_module.dart +++ b/lib/presentation/di/module/app_module.dart @@ -356,7 +356,12 @@ class AppModule { getIt.registerFactory(() => GetSharedSpacesRootNodeInfoInteractor(getIt())); getIt.registerFactory(() => DownloadMultipleFileIOSInteractor(getIt())); getIt.registerFactory(() => GetAuthorizedInteractor(getIt(), getIt())); - getIt.registerFactory(() => GetAllReceivedSharesInteractor(getIt())); + getIt.registerFactory(() => + RemoveDeletedReceivedShareFromLocalDatabaseInteractor( + getIt())); + getIt.registerFactory(() => GetAllReceivedSharesInteractor( + getIt(), + getIt())); getIt.registerFactory(() => CopyToMySpaceInteractor(getIt())); getIt.registerFactory(() => CopyMultipleFilesToMySpaceInteractor(getIt())); getIt.registerFactory(() => SearchDocumentInteractor());