From dfa57a3923da5f5699f3c0086b09086b691cafbd Mon Sep 17 00:00:00 2001 From: KhaledNjim Date: Tue, 3 Sep 2024 15:22:57 +0100 Subject: [PATCH 1/3] LA-1352-add recipient when adding and retrieving from local database --- .../datasource/received_share_datasource.dart | 4 ++++ .../local_received_share_datasource.dart | 12 ++++++++++++ .../received_share_datasource_impl.dart | 6 ++++++ data/lib/src/extensions/user_extension.dart | 6 ++++++ .../local/received_share_database_manager.dart | 18 ++++++++++++++++-- .../received_share_repository_impl.dart | 5 +++++ .../extension/received_share_extensions.dart | 18 ++++++++++++++++++ .../received/received_share_repository.dart | 3 +++ .../get_all_received_shares_interactor.dart | 5 +++-- ...make_received_share_offline_interactor.dart | 8 ++++++-- .../received/received_share_viewmodel.dart | 12 +++++++++--- 11 files changed, 88 insertions(+), 9 deletions(-) diff --git a/data/lib/src/datasource/received_share_datasource.dart b/data/lib/src/datasource/received_share_datasource.dart index a1aa71a8f..1777deb5b 100644 --- a/data/lib/src/datasource/received_share_datasource.dart +++ b/data/lib/src/datasource/received_share_datasource.dart @@ -67,4 +67,8 @@ abstract class ReceivedShareDataSource { Future> getAllReceivedShareOffline(); Future disableOffline(ShareId shareId, String localPath); + + Future> getAllReceivedSharesForRecipient( + String recipient); + } diff --git a/data/lib/src/datasource_impl/local_received_share_datasource.dart b/data/lib/src/datasource_impl/local_received_share_datasource.dart index 78ece3181..72ed72300 100644 --- a/data/lib/src/datasource_impl/local_received_share_datasource.dart +++ b/data/lib/src/datasource_impl/local_received_share_datasource.dart @@ -116,4 +116,16 @@ class LocalReceivedShareDataSource extends ReceivedShareDataSource { throw LocalUnknownError(error); }); } + + @override + Future> getAllReceivedSharesForRecipient( + String recipient) { + return Future.sync(() async { + return await _receivedShareDatabaseManager + .getListDataForRecipient(recipient); + }).catchError((error) { + throw LocalUnknownError(error); + }); + } + } \ No newline at end of file diff --git a/data/lib/src/datasource_impl/received_share_datasource_impl.dart b/data/lib/src/datasource_impl/received_share_datasource_impl.dart index f038dd368..674120329 100644 --- a/data/lib/src/datasource_impl/received_share_datasource_impl.dart +++ b/data/lib/src/datasource_impl/received_share_datasource_impl.dart @@ -217,4 +217,10 @@ class ReceivedShareDataSourceImpl extends ReceivedShareDataSource { Future disableOffline(ShareId shareId, String localPath) { throw UnimplementedError(); } + + @override + Future> getAllReceivedSharesForRecipient(String recipient) { + // TODO: implement getAllReceivedSharesForRecipient + throw UnimplementedError(); + } } diff --git a/data/lib/src/extensions/user_extension.dart b/data/lib/src/extensions/user_extension.dart index d79d7be99..57f01bd63 100644 --- a/data/lib/src/extensions/user_extension.dart +++ b/data/lib/src/extensions/user_extension.dart @@ -50,4 +50,10 @@ extension UserExtension on User { secondFARequired ); } + + GenericUser toGenericUser() { + return GenericUser( + mail, + ); + } } \ No newline at end of file diff --git a/data/lib/src/local/received_share_database_manager.dart b/data/lib/src/local/received_share_database_manager.dart index e1416f034..db4a6d468 100644 --- a/data/lib/src/local/received_share_database_manager.dart +++ b/data/lib/src/local/received_share_database_manager.dart @@ -38,7 +38,8 @@ import 'package:domain/domain.dart'; import 'model/received_share_cache.dart'; -class ReceivedShareDatabaseManager extends LinShareDatabaseManager { +class ReceivedShareDatabaseManager + extends LinShareDatabaseManager { final DatabaseClient _databaseClient; ReceivedShareDatabaseManager(this._databaseClient); @@ -98,4 +99,17 @@ class ReceivedShareDatabaseManager extends LinShareDatabaseManager 0 ? true : false; } -} \ No newline at end of file + Future> getListDataForRecipient(String mail) async { + String todayDate = DateTime.now().toIso8601String(); + final res = await _databaseClient.getListDataWithCondition( + ReceivedShareTable.TABLE_NAME, + '${ReceivedShareTable.MAIL_RECIPIENT} !="" AND ${ReceivedShareTable.MAIL_RECIPIENT} = ? AND ${ReceivedShareTable.EXPIRATION_DATE} >= ?', + [mail, todayDate]); + return res.isNotEmpty + ? res + .map((mapObject) => + ReceivedShareCache.fromJson(mapObject).toReceivedShare()) + .toList() + : []; + } +} diff --git a/data/lib/src/repository/received/received_share_repository_impl.dart b/data/lib/src/repository/received/received_share_repository_impl.dart index 170e410ed..27d66a003 100644 --- a/data/lib/src/repository/received/received_share_repository_impl.dart +++ b/data/lib/src/repository/received/received_share_repository_impl.dart @@ -104,4 +104,9 @@ class ReceivedShareRepositoryImpl extends ReceivedShareRepository { Future disableOffline(ShareId shareId, String localPath) { return _receivedShareDataSources[DataSourceType.local]!.disableOffline(shareId, localPath); } + + @override + Future> getAllReceivedShareOfflineByRecipient(String recipient) { + return _receivedShareDataSources[DataSourceType.local]!.getAllReceivedSharesForRecipient(recipient); + } } diff --git a/domain/lib/src/extension/received_share_extensions.dart b/domain/lib/src/extension/received_share_extensions.dart index d887c8613..4ea1519ed 100644 --- a/domain/lib/src/extension/received_share_extensions.dart +++ b/domain/lib/src/extension/received_share_extensions.dart @@ -55,4 +55,22 @@ extension ReceivedShareExtensions on ReceivedShare { localPath: localPath, syncOfflineState: SyncOfflineState.completed); } + + ReceivedShare withRecipient(GenericUser recipient) { + return ReceivedShare( + shareId, + name, + creationDate, + modificationDate, + expirationDate, + description, + recipient, + mediaType, + sender, + downloaded, + size, + hasThumbnail, + localPath: localPath, + syncOfflineState: syncOfflineState); + } } diff --git a/domain/lib/src/repository/received/received_share_repository.dart b/domain/lib/src/repository/received/received_share_repository.dart index a9770bfd2..883419325 100644 --- a/domain/lib/src/repository/received/received_share_repository.dart +++ b/domain/lib/src/repository/received/received_share_repository.dart @@ -68,5 +68,8 @@ abstract class ReceivedShareRepository { Future> getAllReceivedShareOffline(); + Future> getAllReceivedShareOfflineByRecipient( + String recipient); + Future disableOffline(ShareId shareId, String localPath); } \ 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 53b67a9c2..8d15e2d5d 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 @@ -44,10 +44,11 @@ class GetAllReceivedSharesInteractor { GetAllReceivedSharesInteractor(this._receivedShareRepository); - Future> execute() async { + Future> execute(String recipient) async { try { final receivedShares = await _receivedShareRepository.getAllReceivedShares() - .onError((error, stackTrace) => _receivedShareRepository.getAllReceivedShareOffline()); + .onError((error, stackTrace) => _receivedShareRepository + .getAllReceivedShareOfflineByRecipient(recipient)); final combinedReceivedShares = List.empty(growable: true); if (receivedShares.isNotEmpty) { diff --git a/domain/lib/src/usecases/received/make_received_share_offline_interactor.dart b/domain/lib/src/usecases/received/make_received_share_offline_interactor.dart index 7195404b5..b9c60844f 100644 --- a/domain/lib/src/usecases/received/make_received_share_offline_interactor.dart +++ b/domain/lib/src/usecases/received/make_received_share_offline_interactor.dart @@ -48,7 +48,8 @@ class MakeReceivedShareOfflineInteractor { this._credentialRepository ); - Future> execute(ReceivedShare receivedShare) async { + Future> execute( + ReceivedShare receivedShare, GenericUser recipient) async { try { final downloadPreviewType = receivedShare.mediaType.isImageFile() ? DownloadPreviewType.image @@ -69,7 +70,10 @@ class MakeReceivedShareOfflineInteractor { }); if (filePath.isNotEmpty) { - final result = await _receivedShareRepository.makeAvailableOffline(receivedShare, filePath); + ReceivedShare receivedShareWithRecipient = + receivedShare.withRecipient(recipient); + final result = await _receivedShareRepository.makeAvailableOffline( + receivedShareWithRecipient, filePath); if (result) { return Right(MakeAvailableOfflineReceivedShareViewState(OfflineModeActionResult.successful, filePath)); } else { diff --git a/lib/presentation/widget/received/received_share_viewmodel.dart b/lib/presentation/widget/received/received_share_viewmodel.dart index f9cc7f2c6..95ef55937 100644 --- a/lib/presentation/widget/received/received_share_viewmodel.dart +++ b/lib/presentation/widget/received/received_share_viewmodel.dart @@ -169,7 +169,10 @@ class ReceivedShareViewModel extends BaseViewModel { ThunkAction _getAllReceivedShareAction() { return (Store store) async { store.dispatch(StartReceivedShareLoadingAction()); - await _getAllReceivedInteractor.execute().then((result) => result.fold( + final currentUser = store.state.account.user; + await _getAllReceivedInteractor + .execute(currentUser?.mail ?? '') + .then((result) => result.fold( (failure) { store.dispatch(ReceivedShareGetAllReceivedSharesAction(Left(failure))); _receivedSharesList = []; @@ -369,9 +372,10 @@ class ReceivedShareViewModel extends BaseViewModel { return (Store store) async { store.dispatch(StartReceivedShareLoadingAction()); + final currentUser = store.state.account.user; await Future.wait([ _getSorterInteractor.execute(OrderScreen.receivedShares), - _getAllReceivedInteractor.execute() + _getAllReceivedInteractor.execute(currentUser?.mail ?? '') ]).then((response) async { response[0].fold((failure) { store.dispatch(ReceivedShareGetSorterAction(Sorter.fromOrderScreen(OrderScreen.receivedShares))); @@ -614,7 +618,9 @@ class ReceivedShareViewModel extends BaseViewModel { OnlineThunkAction _makeAvailableOfflineAction(ReceivedShare receivedShare, int position) { return OnlineThunkAction((Store store) async { - await _makeReceivedShareOfflineInteractor.execute(receivedShare) + final recipient = GenericUser(store.state.account.user?.mail ?? ''); + await _makeReceivedShareOfflineInteractor + .execute(receivedShare, recipient) .then((result) => result.fold( (failure) { _receivedSharesList[position] = receivedShare.toSyncOffline(syncOfflineState: SyncOfflineState.none); From 93e1695695fb72cd4986ee7defb81bd4fa0deaa2 Mon Sep 17 00:00:00 2001 From: KhaledNjim Date: Wed, 4 Sep 2024 00:10:27 +0100 Subject: [PATCH 2/3] 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 | 21 +++++++++++++++++++ .../get_all_received_interactor_test.dart | 19 +++++++++++++---- lib/presentation/di/module/app_module.dart | 7 ++++++- .../received/received_share_viewmodel.dart | 3 +-- 6 files changed, 53 insertions(+), 8 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..ebef0caa3 --- /dev/null +++ b/domain/lib/src/usecases/received/remove_deleted_received_share_from_local_database.dart @@ -0,0 +1,21 @@ +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 localReceivedShares = await _receivedShareRepository + .getAllReceivedShareOfflineByRecipient(recipient); + final receivedShareIds = receivedShares.map((received) => received.shareId).toSet(); + for (final local in localReceivedShares) { + if (!receivedShareIds.contains(local.shareId)) { + await _receivedShareRepository.disableOffline(local.shareId, local.localPath ?? ''); + } + } + } +} diff --git a/domain/test/usecases/received/get_all_received_interactor_test.dart b/domain/test/usecases/received/get_all_received_interactor_test.dart index 4a09a514b..64825d407 100644 --- a/domain/test/usecases/received/get_all_received_interactor_test.dart +++ b/domain/test/usecases/received/get_all_received_interactor_test.dart @@ -33,7 +33,6 @@ import 'package:dartz/dartz.dart'; import 'package:domain/domain.dart'; -import 'package:domain/src/usecases/received/received_share_view_state.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; @@ -46,10 +45,18 @@ void main() { group('get_all_received_interactor', () { late MockReceivedShareRepository receivedShareRepository; late GetAllReceivedSharesInteractor getAllReceivedSharesInteractor; + late RemoveDeletedReceivedShareFromLocalDatabaseInteractor + removeDeletedReceivedShareFromLocalDatabaseInteractor; + setUp(() { receivedShareRepository = MockReceivedShareRepository(); - getAllReceivedSharesInteractor = GetAllReceivedSharesInteractor(receivedShareRepository); + removeDeletedReceivedShareFromLocalDatabaseInteractor = + RemoveDeletedReceivedShareFromLocalDatabaseInteractor( + receivedShareRepository); + getAllReceivedSharesInteractor = GetAllReceivedSharesInteractor( + receivedShareRepository, + removeDeletedReceivedShareFromLocalDatabaseInteractor); }); test('get all receives interactor should return success with receive list', () async { @@ -57,8 +64,11 @@ void main() { when(receivedShareRepository.getAllReceivedShareOffline()).thenAnswer((_) async => []); when(receivedShareRepository.getReceivedShareOffline(receivedShare1.shareId)).thenAnswer((_) async => null); when(receivedShareRepository.getReceivedShareOffline(receivedShare2.shareId)).thenAnswer((_) async => null); + when(receivedShareRepository + .getAllReceivedShareOfflineByRecipient(RECIPIENT_1.mail)) + .thenAnswer((_) async => [receivedShare1]); - final result = await getAllReceivedSharesInteractor.execute(); + final result = await getAllReceivedSharesInteractor.execute(RECIPIENT_1.mail); result.map((success) => (success as GetAllReceivedShareSuccess).receivedShares) .fold( @@ -71,7 +81,8 @@ void main() { final exception = Exception(); when(receivedShareRepository.getAllReceivedShares()).thenThrow(exception); - final result = await getAllReceivedSharesInteractor.execute(); + final result = + await getAllReceivedSharesInteractor.execute(RECIPIENT_1.mail); result.fold( (failure) => expect(failure, isA()), 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()); diff --git a/lib/presentation/widget/received/received_share_viewmodel.dart b/lib/presentation/widget/received/received_share_viewmodel.dart index 95ef55937..8da38be06 100644 --- a/lib/presentation/widget/received/received_share_viewmodel.dart +++ b/lib/presentation/widget/received/received_share_viewmodel.dart @@ -619,8 +619,7 @@ class ReceivedShareViewModel extends BaseViewModel { OnlineThunkAction _makeAvailableOfflineAction(ReceivedShare receivedShare, int position) { return OnlineThunkAction((Store store) async { final recipient = GenericUser(store.state.account.user?.mail ?? ''); - await _makeReceivedShareOfflineInteractor - .execute(receivedShare, recipient) + await _makeReceivedShareOfflineInteractor.execute(receivedShare, recipient) .then((result) => result.fold( (failure) { _receivedSharesList[position] = receivedShare.toSyncOffline(syncOfflineState: SyncOfflineState.none); From 7bd656d56dfb2035bd2315d5e08cd81de3f7c3a5 Mon Sep 17 00:00:00 2001 From: KhaledNjim Date: Sun, 10 Nov 2024 19:13:48 +0100 Subject: [PATCH 3/3] LA-1352 added unit test for getListDataForRecipient --- .../received_share_database_manager.dart | 8 ++- .../received_share_database_manager_test.dart | 66 +++++++++++++++++++ ...ed_received_share_from_local_database.dart | 20 ++++-- 3 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 data/test/local/received_share_database_manager_test.dart diff --git a/data/lib/src/local/received_share_database_manager.dart b/data/lib/src/local/received_share_database_manager.dart index db4a6d468..18e1a53b9 100644 --- a/data/lib/src/local/received_share_database_manager.dart +++ b/data/lib/src/local/received_share_database_manager.dart @@ -100,10 +100,14 @@ class ReceivedShareDatabaseManager } Future> getListDataForRecipient(String mail) async { - String todayDate = DateTime.now().toIso8601String(); + final now = DateTime.now(); + final todayDate = + DateTime(now.year, now.month, now.day, now.hour, now.minute).toIso8601String(); + final queryCondition = + '${ReceivedShareTable.MAIL_RECIPIENT} !="" AND ${ReceivedShareTable.MAIL_RECIPIENT} = ? AND ${ReceivedShareTable.EXPIRATION_DATE} >= ?'; final res = await _databaseClient.getListDataWithCondition( ReceivedShareTable.TABLE_NAME, - '${ReceivedShareTable.MAIL_RECIPIENT} !="" AND ${ReceivedShareTable.MAIL_RECIPIENT} = ? AND ${ReceivedShareTable.EXPIRATION_DATE} >= ?', + queryCondition, [mail, todayDate]); return res.isNotEmpty ? res diff --git a/data/test/local/received_share_database_manager_test.dart b/data/test/local/received_share_database_manager_test.dart new file mode 100644 index 000000000..5505a7b49 --- /dev/null +++ b/data/test/local/received_share_database_manager_test.dart @@ -0,0 +1,66 @@ +import 'package:data/data.dart'; +import 'package:data/src/local/config/received_share_table.dart'; +import 'package:data/src/local/model/received_share_cache.dart'; +import 'package:domain/domain.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:mockito/annotations.dart'; +import 'package:testshared/fixture/received_share_fixture.dart'; +import 'document_database_manager_test.mocks.dart'; + +@GenerateMocks([DatabaseClient]) +void main() { + late MockDatabaseClient mockDatabaseClient; + late ReceivedShareDatabaseManager receivedShareDatabaseManager; + late DateTime now; + late String todayDate; + setUp(() { + mockDatabaseClient = MockDatabaseClient(); + receivedShareDatabaseManager = + ReceivedShareDatabaseManager(mockDatabaseClient); + now = DateTime.now(); + todayDate = DateTime(now.year, now.month, now.day, now.hour, now.minute) + .toIso8601String(); + }); + + group('getListDataForRecipient', () { + test( + 'getListDataForRecipient returns filtered and mapped data for a specific recipient', + () async { + when(mockDatabaseClient.getListDataWithCondition( + ReceivedShareTable.TABLE_NAME, + '${ReceivedShareTable.MAIL_RECIPIENT} !="" AND ${ReceivedShareTable.MAIL_RECIPIENT} = ? AND ${ReceivedShareTable.EXPIRATION_DATE} >= ?', + [RECIPIENT_1.mail, todayDate], + )).thenAnswer((_) async => [ + receivedShare1.toReceivedShareCache().toJson(), + ]); + + final result = await receivedShareDatabaseManager + .getListDataForRecipient(RECIPIENT_1.mail); + + expect(result, isA>()); + expect(result.length, 1); + expect(result.first.shareId, receivedShare1.shareId); + }); + test( + 'getListDataForRecipient returns an empty list when no data matches the recipient', + () async { + when(mockDatabaseClient.getListDataWithCondition( + ReceivedShareTable.TABLE_NAME, + '${ReceivedShareTable.MAIL_RECIPIENT} !="" AND ${ReceivedShareTable.MAIL_RECIPIENT} = ? AND ${ReceivedShareTable.EXPIRATION_DATE} >= ?', + [RECIPIENT_1.mail, todayDate], + )).thenAnswer((_) async => []); + + final result = await receivedShareDatabaseManager + .getListDataForRecipient(RECIPIENT_1.mail); + expect(result, isA>()); + expect(result.isEmpty, true); + verify(mockDatabaseClient.getListDataWithCondition( + ReceivedShareTable.TABLE_NAME, + '${ReceivedShareTable.MAIL_RECIPIENT} !="" AND ${ReceivedShareTable.MAIL_RECIPIENT} = ? AND ${ReceivedShareTable.EXPIRATION_DATE} >= ?', + [RECIPIENT_1.mail, todayDate], + )).called(1); + }, + ); + }); +} 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 index ebef0caa3..837692e3d 100644 --- 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 @@ -1,5 +1,5 @@ +import 'dart:developer'; import 'package:domain/domain.dart'; -import 'package:collection/collection.dart'; class RemoveDeletedReceivedShareFromLocalDatabaseInteractor { final ReceivedShareRepository _receivedShareRepository; @@ -9,13 +9,19 @@ class RemoveDeletedReceivedShareFromLocalDatabaseInteractor { Future execute( List receivedShares, String recipient) async { - var localReceivedShares = await _receivedShareRepository - .getAllReceivedShareOfflineByRecipient(recipient); - final receivedShareIds = receivedShares.map((received) => received.shareId).toSet(); - for (final local in localReceivedShares) { - if (!receivedShareIds.contains(local.shareId)) { - await _receivedShareRepository.disableOffline(local.shareId, local.localPath ?? ''); + try { + var localReceivedShares = await _receivedShareRepository + .getAllReceivedShareOfflineByRecipient(recipient); + final receivedShareIds = + receivedShares.map((received) => received.shareId).toSet(); + for (final local in localReceivedShares) { + if (!receivedShareIds.contains(local.shareId)) { + await _receivedShareRepository.disableOffline( + local.shareId, local.localPath ?? ''); + } } + } catch (exception) { + log('RemoveDeletedReceivedShareFromLocalDatabaseInteractor: $exception'); } } }