Skip to content

Commit

Permalink
LA-1352 sync deleted recieved shares with local db
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledNjim committed Sep 3, 2024
1 parent 55f76ae commit af6f6ee
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions domain/lib/domain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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<Either<Failure, Success>> execute(String recipient) async {
try {
Expand All @@ -51,6 +56,9 @@ class GetAllReceivedSharesInteractor {
.getAllReceivedShareOfflineByRecipient(recipient));
final combinedReceivedShares = List<ReceivedShare>.empty(growable: true);

_removeDeletedReceivedShareFromLocalDatabase.execute(
receivedShares, recipient);

if (receivedShares.isNotEmpty) {
for (final received in receivedShares) {
final localReceivedShare = await _receivedShareRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:domain/domain.dart';
import 'package:collection/collection.dart';

class RemoveDeletedReceivedShareFromLocalDatabaseInteractor {
final ReceivedShareRepository _receivedShareRepository;

RemoveDeletedReceivedShareFromLocalDatabaseInteractor(
this._receivedShareRepository);

Future<void> execute(
List<ReceivedShare> 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 ?? '');
}
}
}
}
7 changes: 6 additions & 1 deletion lib/presentation/di/module/app_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ class AppModule {
getIt.registerFactory(() => GetSharedSpacesRootNodeInfoInteractor(getIt<SharedSpaceDocumentRepository>()));
getIt.registerFactory(() => DownloadMultipleFileIOSInteractor(getIt<DownloadFileIOSInteractor>()));
getIt.registerFactory(() => GetAuthorizedInteractor(getIt<AuthenticationRepository>(), getIt<CredentialRepository>()));
getIt.registerFactory(() => GetAllReceivedSharesInteractor(getIt<ReceivedShareRepository>()));
getIt.registerFactory(() =>
RemoveDeletedReceivedShareFromLocalDatabaseInteractor(
getIt<ReceivedShareRepository>()));
getIt.registerFactory(() => GetAllReceivedSharesInteractor(
getIt<ReceivedShareRepository>(),
getIt<RemoveDeletedReceivedShareFromLocalDatabaseInteractor>()));
getIt.registerFactory(() => CopyToMySpaceInteractor(getIt<DocumentRepository>()));
getIt.registerFactory(() => CopyMultipleFilesToMySpaceInteractor(getIt<CopyToMySpaceInteractor>()));
getIt.registerFactory(() => SearchDocumentInteractor());
Expand Down

0 comments on commit af6f6ee

Please sign in to comment.