TF-3767 Use TupleKey to save recent search for each account
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/extensions/account_id_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
||||
|
||||
class RecentSearch with EquatableMixin {
|
||||
final String value;
|
||||
@@ -11,6 +15,10 @@ class RecentSearch with EquatableMixin {
|
||||
return RecentSearch(word, DateTime.now());
|
||||
}
|
||||
|
||||
String generateTupleKey(AccountId accountId, UserName userName) {
|
||||
return TupleKey(value, accountId.asString, userName.value).encodeKey;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [value, creationDate];
|
||||
}
|
||||
@@ -1,8 +1,21 @@
|
||||
|
||||
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/mailbox_dashboard/domain/model/recent_search.dart';
|
||||
|
||||
abstract class SearchRepository {
|
||||
Future<void> saveRecentSearch(RecentSearch recentSearch);
|
||||
Future<void> saveRecentSearch(
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
RecentSearch recentSearch,
|
||||
);
|
||||
|
||||
Future<List<RecentSearch>> getAllRecentSearchLatest({int? limit, String? pattern});
|
||||
Future<List<RecentSearch>> getAllRecentSearchLatest(
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
{
|
||||
int? limit,
|
||||
String? pattern,
|
||||
}
|
||||
);
|
||||
}
|
||||
+19
-3
@@ -1,7 +1,11 @@
|
||||
import 'dart:core';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
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/mailbox_dashboard/domain/repository/search_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_all_recent_search_latest_state.dart';
|
||||
|
||||
@@ -10,9 +14,21 @@ class GetAllRecentSearchLatestInteractor {
|
||||
|
||||
GetAllRecentSearchLatestInteractor(this.searchRepository);
|
||||
|
||||
Future<Either<Failure, Success>> execute({int? limit, String? pattern}) async {
|
||||
Future<Either<Failure, Success>> execute(
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
{
|
||||
int? limit,
|
||||
String? pattern,
|
||||
}
|
||||
) async {
|
||||
try {
|
||||
final listRecent = await searchRepository.getAllRecentSearchLatest(limit: limit, pattern: pattern);
|
||||
final listRecent = await searchRepository.getAllRecentSearchLatest(
|
||||
accountId,
|
||||
userName,
|
||||
limit: limit,
|
||||
pattern: pattern,
|
||||
);
|
||||
log('GetAllRecentSearchLatestInteractor::execute(): listRecent: ${listRecent.length}');
|
||||
return Right(GetAllRecentSearchLatestSuccess(listRecent));
|
||||
} catch (exception) {
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'dart:core';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
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/mailbox_dashboard/domain/model/recent_search.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/search_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/save_recent_search_state.dart';
|
||||
@@ -11,9 +13,17 @@ class SaveRecentSearchInteractor {
|
||||
|
||||
SaveRecentSearchInteractor(this.searchRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(RecentSearch recentSearch) async* {
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
RecentSearch recentSearch,
|
||||
) async* {
|
||||
try {
|
||||
await searchRepository.saveRecentSearch(recentSearch);
|
||||
await searchRepository.saveRecentSearch(
|
||||
accountId,
|
||||
userName,
|
||||
recentSearch,
|
||||
);
|
||||
yield Right(SaveRecentSearchSuccess());
|
||||
} catch (exception) {
|
||||
yield Left(SaveRecentSearchFailure(exception));
|
||||
|
||||
Reference in New Issue
Block a user