TF-3767 Clean up recent searches whenever re-login and exceeds limit

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2025-06-11 12:59:13 +07:00
committed by Dat H. Pham
parent a02435c9f5
commit 6fef6190e0
13 changed files with 136 additions and 61 deletions
@@ -1,13 +1,19 @@
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/cleanup/domain/model/cleanup_rule.dart';
class RecentSearchCleanupRule extends CleanupRule {
final int storageLimit;
final AccountId accountId;
final UserName userName;
RecentSearchCleanupRule(
{this.storageLimit = 10}
this.accountId,
this.userName,
{this.storageLimit = 10}
) : super();
@override
List<Object?> get props => [storageLimit];
List<Object?> get props => [accountId, userName, storageLimit];
}
@@ -1,6 +1,8 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class CleanupRecentSearchCacheLoading extends LoadingState {}
class CleanupRecentSearchCacheSuccess extends UIState {}
class CleanupRecentSearchCacheFailure extends FeatureFailure {
@@ -1,4 +1,5 @@
import 'package:core/core.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:tmail_ui_user/features/cleanup/domain/model/recent_search_cleanup_rule.dart';
import 'package:tmail_ui_user/features/cleanup/domain/repository/cleanup_repository.dart';
@@ -9,13 +10,13 @@ class CleanupRecentSearchCacheInteractor {
CleanupRecentSearchCacheInteractor(this.cleanupRepository);
Future<Either<Failure, Success>> execute(RecentSearchCleanupRule cleanupRule) async {
Stream<Either<Failure, Success>> execute(RecentSearchCleanupRule cleanupRule) async* {
try {
yield Right<Failure, Success>(CleanupRecentSearchCacheLoading());
await cleanupRepository.cleanRecentSearchCache(cleanupRule);
log('CleanupRecentSearchCacheInteractor::execute(): SUCCESS');
return Right<Failure, Success>(CleanupRecentSearchCacheSuccess());
yield Right<Failure, Success>(CleanupRecentSearchCacheSuccess());
} catch (e) {
return Left(CleanupRecentSearchCacheFailure(e));
yield Left(CleanupRecentSearchCacheFailure(e));
}
}
}