Add unit test for combineEmailCache method
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_database_steps.dart';
|
||||
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
|
||||
|
||||
class UpgradeHiveDatabaseStepsV16 extends UpgradeDatabaseSteps {
|
||||
class UpgradeHiveDatabaseStepsV17 extends UpgradeDatabaseSteps {
|
||||
|
||||
final CachingManager _cachingManager;
|
||||
|
||||
UpgradeHiveDatabaseStepsV16(this._cachingManager);
|
||||
UpgradeHiveDatabaseStepsV17(this._cachingManager);
|
||||
|
||||
@override
|
||||
Future<void> onUpgrade(int oldVersion, int newVersion) async {
|
||||
|
||||
@@ -13,10 +13,11 @@ import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_st
|
||||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v14.dart';
|
||||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v15.dart';
|
||||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v16.dart';
|
||||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v17.dart';
|
||||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v7.dart';
|
||||
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/cache_version.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/fcm_isolate_nam_server.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/fcm_isolate_name_server.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||
import 'package:tmail_ui_user/features/home/data/model/session_hive_obj.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/local/encryption_key_cache_manager.dart';
|
||||
@@ -82,7 +83,7 @@ class HiveCacheConfig {
|
||||
await UpgradeHiveDatabaseStepsV14(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||
await UpgradeHiveDatabaseStepsV15(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||
await UpgradeHiveDatabaseStepsV16(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||
await UpgradeHiveDatabaseStepsV16(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||
await UpgradeHiveDatabaseStepsV17(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||
|
||||
if (oldVersion != newVersion) {
|
||||
await cachingManager.storeCacheVersion(newVersion);
|
||||
|
||||
@@ -15,7 +15,6 @@ import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/get_html_content_from_attachment_state.dart';
|
||||
@@ -39,10 +38,7 @@ class EmailUtils {
|
||||
|
||||
static Properties getPropertiesForEmailChangeMethod(Session session, AccountId accountId) {
|
||||
if (CapabilityIdentifier.jamesCalendarEvent.isSupported(session, accountId)) {
|
||||
return Properties({
|
||||
...ThreadConstants.propertiesUpdatedDefault.value,
|
||||
IndividualHeaderIdentifier.headerCalendarEvent.value,
|
||||
});
|
||||
return ThreadConstants.propertiesCalendarEvent;
|
||||
} else {
|
||||
return ThreadConstants.propertiesUpdatedDefault;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ 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' as dartz;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/filter/filter.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
@@ -171,6 +172,18 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
return networkEmailResponse;
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
Future<List<Email>?> combineEmailCache({
|
||||
List<Email>? emailUpdated,
|
||||
Properties? updatedProperties,
|
||||
List<Email>? emailCacheList,
|
||||
}) =>
|
||||
_combineEmailCache(
|
||||
emailUpdated: emailUpdated,
|
||||
updatedProperties: updatedProperties,
|
||||
emailCacheList: emailCacheList,
|
||||
);
|
||||
|
||||
Future<List<Email>?> _combineEmailCache({
|
||||
List<Email>? emailUpdated,
|
||||
Properties? updatedProperties,
|
||||
@@ -197,6 +210,13 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
return combinedEmails;
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
({Email updatedEmail, Email? oldEmail}) combineUpdatedWithEmailInCache(
|
||||
Email updatedEmail,
|
||||
List<Email>? emailCacheList,
|
||||
) =>
|
||||
_combineUpdatedWithEmailInCache(updatedEmail, emailCacheList);
|
||||
|
||||
({Email updatedEmail, Email? oldEmail}) _combineUpdatedWithEmailInCache(
|
||||
Email updatedEmail,
|
||||
List<Email>? emailCacheList,
|
||||
@@ -227,16 +247,24 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
destroyed: newDestroyed);
|
||||
}
|
||||
|
||||
Future<void> _updateState(AccountId accountId, UserName userName, State newState) async {
|
||||
Future<void> _updateState(
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
jmap.State newState,
|
||||
) async {
|
||||
log('ThreadRepositoryImpl::_updateState(): [MAIL] $newState');
|
||||
await stateDataSource.saveState(accountId, userName, newState.toStateCache(StateType.email));
|
||||
await stateDataSource.saveState(
|
||||
accountId,
|
||||
userName,
|
||||
newState.toStateCache(StateType.email),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<EmailsResponse> refreshChanges(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
State currentState,
|
||||
jmap.State currentState,
|
||||
{
|
||||
Set<Comparator>? sort,
|
||||
EmailFilter? emailFilter,
|
||||
@@ -371,7 +399,7 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
Future<void> _synchronizeCacheWithChanges(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
State currentState,
|
||||
jmap.State currentState,
|
||||
{
|
||||
Properties? propertiesCreated,
|
||||
Properties? propertiesUpdated,
|
||||
@@ -381,7 +409,7 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
|
||||
EmailChangeResponse? emailChangeResponse;
|
||||
bool hasMoreChanges = true;
|
||||
State? sinceState = currentState;
|
||||
jmap.State? sinceState = currentState;
|
||||
|
||||
while(hasMoreChanges && sinceState != null) {
|
||||
log('ThreadRepositoryImpl::_synchronizeCacheWithChanges(): sinceState = $sinceState');
|
||||
|
||||
Reference in New Issue
Block a user