TF-1913 Fix thread view keeps reloading
(cherry picked from commit fc7ecd17f685b82bac98d808af450000e0f02c47)
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import 'package:core/utils/app_logger.dart';
|
import 'package:core/utils/app_logger.dart';
|
||||||
import 'package:core/utils/file_utils.dart';
|
import 'package:core/utils/file_utils.dart';
|
||||||
import 'package:core/utils/platform_info.dart';
|
import 'package:core/utils/platform_info.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/session/session.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/caching/clients/detailed_email_hive_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/clients/detailed_email_hive_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/clients/opened_email_hive_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/clients/opened_email_hive_cache_client.dart';
|
||||||
@@ -85,9 +87,16 @@ class CachingManager {
|
|||||||
], eagerError: true);
|
], eagerError: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> clearEmailCache() {
|
Future<void> clearEmailCacheAndStateCacheByTupleKey(AccountId accountId, Session session) {
|
||||||
return Future.wait([
|
return Future.wait([
|
||||||
_stateCacheClient.deleteItem(StateType.email.value),
|
_stateCacheClient.deleteItem(StateType.email.getTupleKeyStored(accountId, session.username)),
|
||||||
|
_emailCacheClient.clearAllData(),
|
||||||
|
], eagerError: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> clearEmailCacheAndAllStateCache() {
|
||||||
|
return Future.wait([
|
||||||
|
_stateCacheClient.clearAllData(),
|
||||||
_emailCacheClient.clearAllData(),
|
_emailCacheClient.clearAllData(),
|
||||||
], eagerError: true);
|
], eagerError: true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class StateDataSourceImpl extends StateDataSource {
|
|||||||
@override
|
@override
|
||||||
Future<State?> getState(AccountId accountId, UserName userName, StateType stateType) {
|
Future<State?> getState(AccountId accountId, UserName userName, StateType stateType) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final stateKey = TupleKey(stateType.value, accountId.asString, userName.value).encodeKey;
|
final stateKey = TupleKey(stateType.name, accountId.asString, userName.value).encodeKey;
|
||||||
final stateCache = await _stateCacheClient.getItem(stateKey);
|
final stateCache = await _stateCacheClient.getItem(stateKey);
|
||||||
return stateCache?.toState();
|
return stateCache?.toState();
|
||||||
}).catchError(_exceptionThrower.throwException);
|
}).catchError(_exceptionThrower.throwException);
|
||||||
@@ -31,7 +31,7 @@ class StateDataSourceImpl extends StateDataSource {
|
|||||||
Future<void> saveState(AccountId accountId, UserName userName, StateCache stateCache) {
|
Future<void> saveState(AccountId accountId, UserName userName, StateCache stateCache) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final stateCacheExist = await _stateCacheClient.isExistTable();
|
final stateCacheExist = await _stateCacheClient.isExistTable();
|
||||||
final stateKey = TupleKey(stateCache.type.value, accountId.asString, userName.value).encodeKey;
|
final stateKey = TupleKey(stateCache.type.name, accountId.asString, userName.value).encodeKey;
|
||||||
if (stateCacheExist) {
|
if (stateCacheExist) {
|
||||||
return await _stateCacheClient.updateItem(stateKey, stateCache);
|
return await _stateCacheClient.updateItem(stateKey, stateCache);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.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';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'state_type.g.dart';
|
part 'state_type.g.dart';
|
||||||
@@ -11,16 +15,9 @@ enum StateType {
|
|||||||
mailbox,
|
mailbox,
|
||||||
|
|
||||||
@HiveField(1)
|
@HiveField(1)
|
||||||
email
|
email;
|
||||||
}
|
|
||||||
|
|
||||||
extension StateTypeExtension on StateType {
|
String getTupleKeyStored(AccountId accountId, UserName userName) {
|
||||||
String get value {
|
return TupleKey(name, accountId.asString, userName.value).encodeKey;
|
||||||
switch(this) {
|
|
||||||
case StateType.mailbox:
|
|
||||||
return 'mailbox';
|
|
||||||
case StateType.email:
|
|
||||||
return 'email';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,7 +343,11 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
void _handleErrorGetAllOrRefreshChangesEmail(Object error, StackTrace stackTrace) async {
|
void _handleErrorGetAllOrRefreshChangesEmail(Object error, StackTrace stackTrace) async {
|
||||||
logError('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error');
|
logError('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error');
|
||||||
if (error is CannotCalculateChangesMethodResponseException) {
|
if (error is CannotCalculateChangesMethodResponseException) {
|
||||||
await cachingManager.clearEmailCache();
|
if (_accountId != null && _session != null) {
|
||||||
|
await cachingManager.clearEmailCacheAndStateCacheByTupleKey(_accountId!, _session!);
|
||||||
|
} else {
|
||||||
|
await cachingManager.clearEmailCacheAndAllStateCache();
|
||||||
|
}
|
||||||
_getAllEmailAction();
|
_getAllEmailAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user