Use Hive CE database to replace Hive database
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
# 66. Synchronize caching
|
||||||
|
|
||||||
|
Date: 2025-06-18
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
Accepted
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
Synchronizing server and database data is quite troublesome,
|
||||||
|
when we use many protocols to receive mails (FCM, WebSocket, Memory operator).
|
||||||
|
In addition, we are using `Hive` database to store data,
|
||||||
|
it does not support multiple isolate to access the database.
|
||||||
|
This leads to inconsistent database data, sometimes corrupted and lost data.
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
To overcome this problem we need a database that can support multiple isolate.
|
||||||
|
So we need to use [Hive_CE](https://pub.dev/packages/hive_ce) to replace `Hive` database.
|
||||||
|
Hive CE is a spiritual continuation of Hive v2 with the following new features, such as:
|
||||||
|
|
||||||
|
- Isolate support through IsolatedHive
|
||||||
|
- Automatic type adapter generation using the GenerateAdapters annotation
|
||||||
|
- No more manually adding annotations to every type and field
|
||||||
|
- Generate adapters for classes outside the current package
|
||||||
|
- A HiveRegistrar extension that lets you register all your generated adapters in one call
|
||||||
|
- Extends the maximum type ID from 223 to 65439
|
||||||
|
...
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- Data is always synchronized with the latest
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
final CachingManager _cachingManager;
|
||||||
|
|
||||||
|
UpgradeHiveDatabaseStepsV16(this._cachingManager);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onUpgrade(int oldVersion, int newVersion) async {
|
||||||
|
if (oldVersion > 0 && oldVersion < newVersion && newVersion == 17) {
|
||||||
|
await _cachingManager.clearAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -87,23 +87,6 @@ class CachingManager {
|
|||||||
], eagerError: true);
|
], eagerError: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> clearData() async {
|
|
||||||
await Future.wait([
|
|
||||||
_stateCacheClient.clearAllData(),
|
|
||||||
_mailboxCacheClient.clearAllData(),
|
|
||||||
_emailCacheClient.clearAllData(),
|
|
||||||
_fcmCacheClient.clearAllData(),
|
|
||||||
_firebaseRegistrationCacheClient.clearAllData(),
|
|
||||||
_localSpamReportManager.clear(),
|
|
||||||
if (PlatformInfo.isMobile)
|
|
||||||
...[
|
|
||||||
_newEmailHiveCacheClient.clearAllData(),
|
|
||||||
_openedEmailHiveCacheClient.clearAllData(),
|
|
||||||
_sendingEmailCacheManager.clearAllSendingEmails(),
|
|
||||||
]
|
|
||||||
], eagerError: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> clearEmailAndStateCache({AccountId? accountId, UserName? userName}) {
|
Future<void> clearEmailAndStateCache({AccountId? accountId, UserName? userName}) {
|
||||||
log('CachingManager::clearEmailAndStateCache:userName = $userName');
|
log('CachingManager::clearEmailAndStateCache:userName = $userName');
|
||||||
if (accountId != null && userName != null) {
|
if (accountId != null && userName != null) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
class CacheVersion {
|
class CacheVersion {
|
||||||
static const int hiveDBVersion = 16;
|
static const int hiveDBVersion = 17;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import 'dart:ui' as flutter;
|
||||||
|
|
||||||
|
import 'package:hive_ce/hive.dart';
|
||||||
|
|
||||||
|
class FcmIsolateNameServer extends IsolateNameServer {
|
||||||
|
const FcmIsolateNameServer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
dynamic lookupPortByName(String name) =>
|
||||||
|
flutter.IsolateNameServer.lookupPortByName(name);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool registerPortWithName(dynamic port, String name) =>
|
||||||
|
flutter.IsolateNameServer.registerPortWithName(port, name);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool removePortNameMapping(String name) =>
|
||||||
|
flutter.IsolateNameServer.removePortNameMapping(name);
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ import 'dart:typed_data';
|
|||||||
|
|
||||||
import 'package:core/presentation/extensions/map_extensions.dart';
|
import 'package:core/presentation/extensions/map_extensions.dart';
|
||||||
import 'package:core/utils/app_logger.dart';
|
import 'package:core/utils/app_logger.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
|
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
||||||
|
|
||||||
@@ -14,20 +14,20 @@ abstract class HiveCacheClient<T> {
|
|||||||
|
|
||||||
Future<Uint8List?> _getEncryptionKey() => HiveCacheConfig.instance.getEncryptionKey();
|
Future<Uint8List?> _getEncryptionKey() => HiveCacheConfig.instance.getEncryptionKey();
|
||||||
|
|
||||||
Future<Box<T>> openBox() async {
|
Future<IsolatedBox<T>> openBox() async {
|
||||||
if (Hive.isBoxOpen(tableName)) {
|
if (IsolatedHive.isBoxOpen(tableName)) {
|
||||||
return Hive.box<T>(tableName);
|
return IsolatedHive.box<T>(tableName);
|
||||||
} else {
|
} else {
|
||||||
return Hive.openBox<T>(tableName);
|
return IsolatedHive.openBox<T>(tableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Box<T>> openBoxEncryption() async {
|
Future<IsolatedBox<T>> openBoxEncryption() async {
|
||||||
final encryptionKey = await _getEncryptionKey();
|
final encryptionKey = await _getEncryptionKey();
|
||||||
if (Hive.isBoxOpen(tableName)) {
|
if (IsolatedHive.isBoxOpen(tableName)) {
|
||||||
return Hive.box<T>(tableName);
|
return IsolatedHive.box<T>(tableName);
|
||||||
} else {
|
} else {
|
||||||
return Hive.openBox<T>(tableName,
|
return IsolatedHive.openBox<T>(tableName,
|
||||||
encryptionCipher:
|
encryptionCipher:
|
||||||
encryptionKey != null ? HiveAesCipher(encryptionKey) : null);
|
encryptionKey != null ? HiveAesCipher(encryptionKey) : null);
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,8 @@ abstract class HiveCacheClient<T> {
|
|||||||
Future<List<T>> getAll() {
|
Future<List<T>> getAll() {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
||||||
return boxItem.values.toList();
|
final items = await boxItem.values;
|
||||||
|
return items.toList();
|
||||||
}).catchError((error) {
|
}).catchError((error) {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
@@ -75,7 +76,8 @@ abstract class HiveCacheClient<T> {
|
|||||||
Future<List<T>> getListByNestedKey(String nestedKey) {
|
Future<List<T>> getListByNestedKey(String nestedKey) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
||||||
final listItem = boxItem.toMap()
|
final mapItems = await boxItem.toMap();
|
||||||
|
final listItem = mapItems
|
||||||
.where((key, value) => _matchedNestedKey(key, nestedKey))
|
.where((key, value) => _matchedNestedKey(key, nestedKey))
|
||||||
.values
|
.values
|
||||||
.toList();
|
.toList();
|
||||||
@@ -89,7 +91,8 @@ abstract class HiveCacheClient<T> {
|
|||||||
Future<List<T>> getValuesByListKey(List<String> listKeys) {
|
Future<List<T>> getValuesByListKey(List<String> listKeys) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
||||||
return boxItem.toMap()
|
final mapItems = await boxItem.toMap();
|
||||||
|
return mapItems
|
||||||
.where((key, value) => listKeys.contains(key))
|
.where((key, value) => listKeys.contains(key))
|
||||||
.values
|
.values
|
||||||
.toList();
|
.toList();
|
||||||
@@ -154,7 +157,7 @@ abstract class HiveCacheClient<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteBox() {
|
Future<void> deleteBox() {
|
||||||
return Hive.deleteBoxFromDisk(tableName);
|
return IsolatedHive.deleteBoxFromDisk(tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> clearAllData() {
|
Future<void> clearAllData() {
|
||||||
@@ -171,7 +174,8 @@ abstract class HiveCacheClient<T> {
|
|||||||
Future<void> clearAllDataContainKey(String nestedKey) {
|
Future<void> clearAllDataContainKey(String nestedKey) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
||||||
final listKeys = boxItem.toMap()
|
final mapItems = await boxItem.toMap();
|
||||||
|
final listKeys = mapItems
|
||||||
.where((key, value) => _matchedNestedKey(key, nestedKey))
|
.where((key, value) => _matchedNestedKey(key, nestedKey))
|
||||||
.keys;
|
.keys;
|
||||||
log('$runtimeType::clearAllDataContainKey:listKeys: ${listKeys.length}');
|
log('$runtimeType::clearAllDataContainKey:listKeys: ${listKeys.length}');
|
||||||
@@ -182,8 +186,8 @@ abstract class HiveCacheClient<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeBox() async {
|
Future<void> closeBox() async {
|
||||||
if (Hive.isBoxOpen(tableName)) {
|
if (IsolatedHive.isBoxOpen(tableName)) {
|
||||||
await Hive.box<T>(tableName).close();
|
await IsolatedHive.box<T>(tableName).close();
|
||||||
}
|
}
|
||||||
return Future.value();
|
return Future.value();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import 'dart:typed_data';
|
|||||||
|
|
||||||
import 'package:core/utils/app_logger.dart';
|
import 'package:core/utils/app_logger.dart';
|
||||||
import 'package:core/utils/platform_info.dart';
|
import 'package:core/utils/platform_info.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:path_provider/path_provider.dart' as path_provider;
|
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v10.dart';
|
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v10.dart';
|
||||||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v11.dart';
|
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v11.dart';
|
||||||
@@ -16,6 +16,7 @@ import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_st
|
|||||||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v7.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/caching_manager.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/config/cache_version.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/utils/caching_constants.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/home/data/model/session_hive_obj.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/local/encryption_key_cache_manager.dart';
|
import 'package:tmail_ui_user/features/login/data/local/encryption_key_cache_manager.dart';
|
||||||
@@ -55,14 +56,17 @@ class HiveCacheConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initializeDatabase({String? databasePath}) async {
|
Future<void> initializeDatabase({String? databasePath}) async {
|
||||||
if (databasePath != null) {
|
if (databasePath == null && PlatformInfo.isMobile) {
|
||||||
Hive.init(databasePath);
|
Directory directory = await path_provider.getApplicationDocumentsDirectory();
|
||||||
} else {
|
databasePath = directory.path;
|
||||||
if (PlatformInfo.isMobile) {
|
|
||||||
Directory directory = await path_provider.getApplicationDocumentsDirectory();
|
|
||||||
Hive.init(directory.path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (databasePath == null) return;
|
||||||
|
|
||||||
|
await IsolatedHive.init(
|
||||||
|
databasePath,
|
||||||
|
isolateNameServer: const FcmIsolateNameServer(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onUpgradeDatabase(CachingManager cachingManager) async {
|
Future<void> onUpgradeDatabase(CachingManager cachingManager) async {
|
||||||
@@ -78,6 +82,7 @@ class HiveCacheConfig {
|
|||||||
await UpgradeHiveDatabaseStepsV14(cachingManager).onUpgrade(oldVersion, newVersion);
|
await UpgradeHiveDatabaseStepsV14(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||||
await UpgradeHiveDatabaseStepsV15(cachingManager).onUpgrade(oldVersion, newVersion);
|
await UpgradeHiveDatabaseStepsV15(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||||
await UpgradeHiveDatabaseStepsV16(cachingManager).onUpgrade(oldVersion, newVersion);
|
await UpgradeHiveDatabaseStepsV16(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||||
|
await UpgradeHiveDatabaseStepsV16(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||||
|
|
||||||
if (oldVersion != newVersion) {
|
if (oldVersion != newVersion) {
|
||||||
await cachingManager.storeCacheVersion(newVersion);
|
await cachingManager.storeCacheVersion(newVersion);
|
||||||
@@ -201,12 +206,12 @@ class HiveCacheConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void registerCacheAdapter<T>(TypeAdapter<T> typeAdapter, int typeId) {
|
void registerCacheAdapter<T>(TypeAdapter<T> typeAdapter, int typeId) {
|
||||||
if (!Hive.isAdapterRegistered(typeId)) {
|
if (!IsolatedHive.isAdapterRegistered(typeId)) {
|
||||||
Hive.registerAdapter<T>(typeAdapter);
|
IsolatedHive.registerAdapter<T>(typeAdapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeHive() async {
|
Future<void> closeHive() async {
|
||||||
return await Hive.close();
|
return await IsolatedHive.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'session_hive_obj.g.dart';
|
part 'session_hive_obj.g.dart';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'account_cache.g.dart';
|
part 'account_cache.g.dart';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'authentication_info_cache.g.dart';
|
part 'authentication_info_cache.g.dart';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'encryption_key_cache.g.dart';
|
part 'encryption_key_cache.g.dart';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'oidc_configuration_cache.g.dart';
|
part 'oidc_configuration_cache.g.dart';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/extensions/date_time_extension.dart';
|
import 'package:jmap_dart_client/jmap/core/extensions/date_time_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/model/recent_login_url.dart';
|
import 'package:tmail_ui_user/features/login/domain/model/recent_login_url.dart';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/extensions/date_time_extension.dart';
|
import 'package:jmap_dart_client/jmap/core/extensions/date_time_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/model/recent_login_username.dart';
|
import 'package:tmail_ui_user/features/login/domain/model/recent_login_username.dart';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'token_oidc_cache.g.dart';
|
part 'token_oidc_cache.g.dart';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_rights_cache.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_rights_cache.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'mailbox_rights_cache.g.dart';
|
part 'mailbox_rights_cache.g.dart';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||||
import 'package:model/extensions/account_id_extensions.dart';
|
import 'package:model/extensions/account_id_extensions.dart';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/extensions/date_time_extension.dart';
|
import 'package:jmap_dart_client/jmap/core/extensions/date_time_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/recent_search.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/recent_search.dart';
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ abstract class WorkerQueue<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleTaskExecuteCompleted(dynamic value) {
|
void _handleTaskExecuteCompleted(dynamic value) {
|
||||||
log('WorkerQueue<$workerName>::_handleTaskExecuteCompleted(): $value');
|
log('WorkerQueue<$workerName>::_handleTaskExecuteCompleted():');
|
||||||
completer?.complete();
|
completer?.complete();
|
||||||
_releaseCompleter();
|
_releaseCompleter();
|
||||||
if (queue.isNotEmpty) {
|
if (queue.isNotEmpty) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class NewEmailCacheManager {
|
|||||||
DetailedEmailHiveCache detailedEmailCache
|
DetailedEmailHiveCache detailedEmailCache
|
||||||
) async {
|
) async {
|
||||||
final listDetailedEmails = await getAllDetailedEmails(accountId, userName);
|
final listDetailedEmails = await getAllDetailedEmails(accountId, userName);
|
||||||
log('NewEmailCacheManager::storeDetailedNewEmail():listDetailedEmails: $listDetailedEmails');
|
log('NewEmailCacheManager::storeDetailedNewEmail(): length of listDetailedEmails is ${listDetailedEmails.length}');
|
||||||
if (listDetailedEmails.length >= CachingConstants.maxNumberNewEmailsForOffline) {
|
if (listDetailedEmails.length >= CachingConstants.maxNumberNewEmailsForOffline) {
|
||||||
final lastElementsListEmail = listDetailedEmails.sublist(CachingConstants.maxNumberNewEmailsForOffline - 1);
|
final lastElementsListEmail = listDetailedEmails.sublist(CachingConstants.maxNumberNewEmailsForOffline - 1);
|
||||||
for (var email in lastElementsListEmail) {
|
for (var email in lastElementsListEmail) {
|
||||||
@@ -34,10 +34,8 @@ class NewEmailCacheManager {
|
|||||||
}
|
}
|
||||||
await removeDetailedEmail(accountId, userName, email.emailId);
|
await removeDetailedEmail(accountId, userName, email.emailId);
|
||||||
}
|
}
|
||||||
log('NewEmailCacheManager::storeDetailedNewEmail(): DELETE COMPLETED');
|
|
||||||
}
|
}
|
||||||
await insertDetailedEmail(accountId, userName, detailedEmailCache);
|
await insertDetailedEmail(accountId, userName, detailedEmailCache);
|
||||||
log('NewEmailCacheManager::storeDetailedNewEmail(): INSERT COMPLETED');
|
|
||||||
return detailedEmailCache;
|
return detailedEmailCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'attachment_hive_cache.g.dart';
|
part 'attachment_hive_cache.g.dart';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
import 'package:tmail_ui_user/features/offline_mode/model/email_header_hive_cache.dart';
|
import 'package:tmail_ui_user/features/offline_mode/model/email_header_hive_cache.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'email_header_hive_cache.g.dart';
|
part 'email_header_hive_cache.g.dart';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'sending_email_hive_cache.g.dart';
|
part 'sending_email_hive_cache.g.dart';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'firebase_registration_cache.g.dart';
|
part 'firebase_registration_cache.g.dart';
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ class WebSocketController extends PushBaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _enableWebSocketPush() {
|
void _enableWebSocketPush() {
|
||||||
|
log('WebSocketController::_enableWebSocketPush:');
|
||||||
_webSocketChannel?.sink.add(jsonEncode(WebSocketPushEnableRequest.toJson(
|
_webSocketChannel?.sink.add(jsonEncode(WebSocketPushEnableRequest.toJson(
|
||||||
dataTypes: [TypeName.emailType, TypeName.mailboxType]
|
dataTypes: [TypeName.emailType, TypeName.mailboxType]
|
||||||
)));
|
)));
|
||||||
@@ -197,6 +198,7 @@ class WebSocketController extends PushBaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _listenToWebSocket() {
|
void _listenToWebSocket() {
|
||||||
|
log('WebSocketController::_listenToWebSocket:');
|
||||||
_webSocketSubscription = _webSocketChannel?.stream.listen(
|
_webSocketSubscription = _webSocketChannel?.stream.listen(
|
||||||
(data) {
|
(data) {
|
||||||
log('WebSocketController::_listenToWebSocket(): $data');
|
log('WebSocketController::_listenToWebSocket(): $data');
|
||||||
@@ -225,6 +227,7 @@ class WebSocketController extends PushBaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _initStateChangeDeouncerTimer() {
|
void _initStateChangeDeouncerTimer() {
|
||||||
|
log('WebSocketController::_initStateChangeDeouncerTimer:');
|
||||||
_stateChangeDebouncer = Debouncer<StateChange?>(
|
_stateChangeDebouncer = Debouncer<StateChange?>(
|
||||||
const Duration(milliseconds: FcmUtils.durationMessageComing),
|
const Duration(milliseconds: FcmUtils.durationMessageComing),
|
||||||
initialValue: null,
|
initialValue: null,
|
||||||
|
|||||||
@@ -56,16 +56,12 @@ extension EmailCacheExtension on EmailCache {
|
|||||||
|
|
||||||
bool expireTimeCaching(EmailCleanupRule cleanupRule) {
|
bool expireTimeCaching(EmailCleanupRule cleanupRule) {
|
||||||
final currentTime = DateTime.now();
|
final currentTime = DateTime.now();
|
||||||
log('EmailCacheExtension::expireTimeCaching():currentTime: $currentTime | receivedAt: $receivedAt');
|
|
||||||
if (receivedAt != null) {
|
if (receivedAt != null) {
|
||||||
final countDay = currentTime.daysBetween(receivedAt!.toLocal());
|
final countDay = currentTime.daysBetween(receivedAt!.toLocal());
|
||||||
log('EmailCacheExtension::expireTimeCaching():countDay: $countDay | cleanupRule.cachingEmailPeriod.countDay: ${cleanupRule.cachingEmailPeriod.countDay}');
|
|
||||||
if (countDay >= cleanupRule.cachingEmailPeriod.countDay) {
|
if (countDay >= cleanupRule.cachingEmailPeriod.countDay) {
|
||||||
log('EmailCacheExtension::expireTimeCaching():true');
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log('EmailCacheExtension::expireTimeCaching():false');
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'email_address_hive_cache.g.dart';
|
part 'email_address_hive_cache.g.dart';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/data/model/email_address_hive_cache.dart';
|
import 'package:tmail_ui_user/features/thread/data/model/email_address_hive_cache.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ class LocalizationService extends Translations {
|
|||||||
static Locale getLocaleFromLanguage({String? langCode}) {
|
static Locale getLocaleFromLanguage({String? langCode}) {
|
||||||
try {
|
try {
|
||||||
final languageCacheManager = getBinding<LanguageCacheManager>();
|
final languageCacheManager = getBinding<LanguageCacheManager>();
|
||||||
log('LocalizationService::_getLocaleFromLanguage:languageCacheManager: $languageCacheManager');
|
|
||||||
final localeStored = languageCacheManager?.getStoredLanguage();
|
final localeStored = languageCacheManager?.getStoredLanguage();
|
||||||
log('LocalizationService::_getLocaleFromLanguage():localeStored: $localeStored');
|
log('LocalizationService::_getLocaleFromLanguage():localeStored: $localeStored');
|
||||||
final localeSelected = supportedLocales.firstWhereOrNull(
|
final localeSelected = supportedLocales.firstWhereOrNull(
|
||||||
|
|||||||
+20
-3
@@ -1224,13 +1224,22 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "2.1.0"
|
||||||
hive:
|
hive:
|
||||||
|
dependency: "direct overridden"
|
||||||
|
description:
|
||||||
|
path: "overrides/hive"
|
||||||
|
ref: "18f92b53295e9eb77ebd4830d905a72cd404a126"
|
||||||
|
resolved-ref: "18f92b53295e9eb77ebd4830d905a72cd404a126"
|
||||||
|
url: "https://github.com/IO-Design-Team/hive_ce"
|
||||||
|
source: git
|
||||||
|
version: "0.0.0"
|
||||||
|
hive_ce:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: hive
|
name: hive_ce
|
||||||
sha256: "8dcf6db979d7933da8217edcec84e9df1bdb4e4edc7fc77dbd5aa74356d6d941"
|
sha256: "708bb39050998707c5d422752159f91944d3c81ab42d80e1bd0ee37d8e130658"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.3"
|
version: "2.11.3"
|
||||||
hive_generator:
|
hive_generator:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@@ -1344,6 +1353,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.4"
|
version: "1.0.4"
|
||||||
|
isolate_channel:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: isolate_channel
|
||||||
|
sha256: f3d36f783b301e6b312c3450eeb2656b0e7d1db81331af2a151d9083a3f6b18d
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.2+1"
|
||||||
jmap_dart_client:
|
jmap_dart_client:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
+9
-1
@@ -154,7 +154,7 @@ dependencies:
|
|||||||
|
|
||||||
share_plus: 7.2.1
|
share_plus: 7.2.1
|
||||||
|
|
||||||
hive: 2.2.3
|
hive_ce: 2.11.3
|
||||||
|
|
||||||
pointer_interceptor: 0.10.1+2
|
pointer_interceptor: 0.10.1+2
|
||||||
|
|
||||||
@@ -309,6 +309,14 @@ dependency_overrides:
|
|||||||
url: https://github.com/linagora/flutter_file_picker.git
|
url: https://github.com/linagora/flutter_file_picker.git
|
||||||
ref: v0.8.5-twake-mail
|
ref: v0.8.5-twake-mail
|
||||||
|
|
||||||
|
# TODO: Due conflict version of hive_ce_generator with other dependencies
|
||||||
|
# So we will remove it when found the appropriate version
|
||||||
|
hive:
|
||||||
|
git:
|
||||||
|
url: https://github.com/IO-Design-Team/hive_ce
|
||||||
|
ref: 18f92b53295e9eb77ebd4830d905a72cd404a126
|
||||||
|
path: overrides/hive
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'package:hive/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/clients/account_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/clients/account_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
|
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
|
||||||
|
|
||||||
@@ -83,12 +83,12 @@ class MemoryAccountCacheClient implements AccountCacheClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Box<AccountCache>> openBox() {
|
Future<IsolatedBox<AccountCache>> openBox() {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Box<AccountCache>> openBoxEncryption() {
|
Future<IsolatedBox<AccountCache>> openBoxEncryption() {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user