fix(cnb): Cannot clear email state cache when reload page
(cherry picked from commit a901206a7879d2f670d29be52ab4a297f1eb6c72)
This commit is contained in:
@@ -98,47 +98,37 @@ class CachingManager {
|
||||
}
|
||||
|
||||
Future<void> clearEmailAndStateCache({AccountId? accountId, UserName? userName}) {
|
||||
log('CachingManager::clearEmailAndStateCache:userName = $userName');
|
||||
if (accountId != null && userName != null) {
|
||||
final emailKey = TupleKey(accountId.asString, userName.value).encodeKey;
|
||||
final stateKey = StateType.email.getTupleKeyStored(accountId, userName);
|
||||
log('CachingManager::clearEmailAndStateCache:userName=$userName');
|
||||
|
||||
return Future.wait([
|
||||
_emailCacheManager.deleteByKey(emailKey),
|
||||
_stateCacheManager.deleteByKey(stateKey),
|
||||
if (PlatformInfo.isMobile)
|
||||
clearFCMEmailStateCache(accountId: accountId, userName: userName),
|
||||
]);
|
||||
} else {
|
||||
final stateKey = StateType.email.getTupleKeyStoredWithoutAccount();
|
||||
return Future.wait([
|
||||
_emailCacheManager.clear(),
|
||||
_stateCacheManager.deleteByKey(stateKey),
|
||||
if (PlatformInfo.isMobile) clearFCMEmailStateCache(),
|
||||
]);
|
||||
}
|
||||
final hasUserContext = accountId != null && userName != null;
|
||||
|
||||
return Future.wait([
|
||||
if (hasUserContext)
|
||||
..._clearEmailAndStateWithUser(accountId, userName)
|
||||
else
|
||||
..._clearEmailAndStateWithoutUser(),
|
||||
|
||||
if (PlatformInfo.isMobile)
|
||||
clearFCMEmailStateCache(accountId: accountId, userName: userName),
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> clearDetailedEmailCache({AccountId? accountId, UserName? userName}) {
|
||||
log('CachingManager::clearDetailedEmailCache:userName = $userName');
|
||||
if (accountId != null && userName != null) {
|
||||
final emailKey = TupleKey(accountId.asString, userName.value).encodeKey;
|
||||
return Future.wait([
|
||||
_newEmailCacheManager.deleteByKey(emailKey),
|
||||
_openedEmailCacheManager.deleteByKey(emailKey),
|
||||
clearAllFileInStorage(),
|
||||
]);
|
||||
} else {
|
||||
return Future.wait([
|
||||
_newEmailCacheManager.clear(),
|
||||
_openedEmailCacheManager.clear(),
|
||||
clearAllFileInStorage(),
|
||||
]);
|
||||
}
|
||||
log('CachingManager::clearDetailedEmailCache:userName=$userName');
|
||||
|
||||
final hasUserContext = accountId != null && userName != null;
|
||||
|
||||
return Future.wait([
|
||||
if (hasUserContext)
|
||||
..._clearDetailedEmailWithUser(accountId, userName)
|
||||
else
|
||||
..._clearDetailedEmailWithoutUser(),
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> clearAllEmailAndStateCache({AccountId? accountId, UserName? userName}) {
|
||||
log('CachingManager::clearAllEmailAndStateCache:userName = $userName');
|
||||
log('CachingManager::clearAllEmailAndStateCache:userName=$userName');
|
||||
|
||||
return Future.wait([
|
||||
clearEmailAndStateCache(accountId: accountId, userName: userName),
|
||||
if (PlatformInfo.isMobile)
|
||||
@@ -148,7 +138,7 @@ class CachingManager {
|
||||
|
||||
Future<void> clearMailboxCache() {
|
||||
return Future.wait([
|
||||
_stateCacheManager.deleteByKey(
|
||||
_stateCacheManager.deleteContainKey(
|
||||
StateType.mailbox.getTupleKeyStoredWithoutAccount(),
|
||||
),
|
||||
_mailboxCacheManager.clear(),
|
||||
@@ -171,21 +161,71 @@ class CachingManager {
|
||||
await _fileUtils.removeFolder(CachingConstants.openedEmailContentFolderName);
|
||||
await _fileUtils.removeFolder(CachingConstants.newEmailsContentFolderName);
|
||||
}
|
||||
|
||||
Future<void> clearFCMEmailStateCache({AccountId? accountId, UserName? userName}) async {
|
||||
if (accountId != null && userName != null) {
|
||||
|
||||
Future<void> clearFCMEmailStateCache({
|
||||
AccountId? accountId,
|
||||
UserName? userName,
|
||||
}) async {
|
||||
final hasUserContext = accountId != null && userName != null;
|
||||
|
||||
if (hasUserContext) {
|
||||
await _fcmCacheManager.deleteByKey(
|
||||
TypeName.emailDelivery.getTupleKeyStored(accountId, userName));
|
||||
TypeName.emailDelivery.getTupleKeyStored(accountId, userName),
|
||||
);
|
||||
await _fcmCacheManager.deleteByKey(
|
||||
TypeName.emailType.getTupleKeyStored(accountId, userName));
|
||||
TypeName.emailType.getTupleKeyStored(accountId, userName),
|
||||
);
|
||||
} else {
|
||||
await _fcmCacheManager.deleteByKey(
|
||||
TypeName.emailDelivery.getTupleKeyStoredWithoutAccount());
|
||||
await _fcmCacheManager.deleteByKey(
|
||||
TypeName.emailType.getTupleKeyStoredWithoutAccount());
|
||||
await _fcmCacheManager.deleteContainKey(
|
||||
TypeName.emailDelivery.getTupleKeyStoredWithoutAccount(),
|
||||
);
|
||||
await _fcmCacheManager.deleteContainKey(
|
||||
TypeName.emailType.getTupleKeyStoredWithoutAccount(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<Future<void>> _clearEmailAndStateWithUser(
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
) {
|
||||
final emailKey = TupleKey(accountId.asString, userName.value).encodeKey;
|
||||
final stateKey = StateType.email.getTupleKeyStored(accountId, userName);
|
||||
|
||||
return [
|
||||
_emailCacheManager.deleteContainKey(emailKey),
|
||||
_stateCacheManager.deleteByKey(stateKey),
|
||||
];
|
||||
}
|
||||
|
||||
List<Future<void>> _clearEmailAndStateWithoutUser() {
|
||||
final stateKey = StateType.email.getTupleKeyStoredWithoutAccount();
|
||||
return [
|
||||
_emailCacheManager.clear(),
|
||||
_stateCacheManager.deleteContainKey(stateKey),
|
||||
];
|
||||
}
|
||||
|
||||
List<Future<void>> _clearDetailedEmailWithUser(
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
) {
|
||||
final emailKey = TupleKey(accountId.asString, userName.value).encodeKey;
|
||||
return [
|
||||
_newEmailCacheManager.deleteContainKey(emailKey),
|
||||
_openedEmailCacheManager.deleteContainKey(emailKey),
|
||||
clearAllFileInStorage(),
|
||||
];
|
||||
}
|
||||
|
||||
List<Future<void>> _clearDetailedEmailWithoutUser() {
|
||||
return [
|
||||
_newEmailCacheManager.clear(),
|
||||
_openedEmailCacheManager.clear(),
|
||||
clearAllFileInStorage(),
|
||||
];
|
||||
}
|
||||
|
||||
Future<void> clearLoginRecentData() async {
|
||||
await Future.wait([
|
||||
_recentLoginUrlCacheManager.clear(),
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/extensions/session_extension.dart';
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:model/oidc/request/oidc_request.dart';
|
||||
import 'package:model/oidc/response/oidc_response.dart';
|
||||
@@ -254,7 +255,10 @@ class LoginController extends ReloadableController {
|
||||
SmartDialog.dismiss();
|
||||
|
||||
if (PlatformInfo.isWeb && AppConfig.isForceEmailQueryEnabled) {
|
||||
await cachingManager.clearAllEmailAndStateCache();
|
||||
await cachingManager.clearAllEmailAndStateCache(
|
||||
accountId: session.safeAccountId,
|
||||
userName: session.username
|
||||
);
|
||||
}
|
||||
|
||||
popAndPush(
|
||||
|
||||
@@ -33,6 +33,9 @@ class StateCacheManager extends CacheManagerInteraction {
|
||||
|
||||
Future<void> deleteByKey(String key) => _stateCacheClient.deleteItem(key);
|
||||
|
||||
Future<void> deleteContainKey(String key) =>
|
||||
_stateCacheClient.clearAllDataContainKey(key);
|
||||
|
||||
Future<void> clear() => _stateCacheClient.clearAllData();
|
||||
|
||||
@override
|
||||
|
||||
+4
-1
@@ -612,7 +612,10 @@ class MailboxDashBoardController extends ReloadableController
|
||||
Future<void> onBeforeUnloadBrowserListener(html.Event event) async {
|
||||
log('MailboxDashBoardController::onBeforeUnloadBrowserListener:event = ${event.runtimeType} | hasComposer = ${twakeAppManager.hasComposer} | isExecutingBeforeReconnect = ${twakeAppManager.isExecutingBeforeReconnect}');
|
||||
if (PlatformInfo.isWeb) {
|
||||
await cachingManager.clearAllEmailAndStateCache();
|
||||
await cachingManager.clearAllEmailAndStateCache(
|
||||
accountId: accountId.value,
|
||||
userName: sessionCurrent?.username,
|
||||
);
|
||||
}
|
||||
|
||||
if (event is html.BeforeUnloadEvent &&
|
||||
|
||||
@@ -140,7 +140,10 @@ class ManageAccountDashBoardController extends ReloadableController
|
||||
@override
|
||||
Future<void> onBeforeUnloadBrowserListener(html.Event event) async {
|
||||
if (PlatformInfo.isWeb) {
|
||||
await cachingManager.clearAllEmailAndStateCache();
|
||||
await cachingManager.clearAllEmailAndStateCache(
|
||||
accountId: accountId.value,
|
||||
userName: sessionCurrent?.username,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class NewEmailCacheManager extends CacheManagerInteraction {
|
||||
|
||||
Future<void> clear() => _cacheClient.clearAllData();
|
||||
|
||||
Future<void> deleteByKey(String key) =>
|
||||
Future<void> deleteContainKey(String key) =>
|
||||
_cacheClient.clearAllDataContainKey(key);
|
||||
|
||||
@override
|
||||
|
||||
@@ -89,7 +89,7 @@ class OpenedEmailCacheManager extends CacheManagerInteraction {
|
||||
|
||||
Future<void> clear() => _cacheClient.clearAllData();
|
||||
|
||||
Future<void> deleteByKey(String key) =>
|
||||
Future<void> deleteContainKey(String key) =>
|
||||
_cacheClient.clearAllDataContainKey(key);
|
||||
|
||||
@override
|
||||
|
||||
@@ -91,6 +91,9 @@ class FCMCacheManager extends CacheManagerInteraction {
|
||||
|
||||
Future<void> deleteByKey(String key) => _fcmCacheClient.deleteItem(key);
|
||||
|
||||
Future<void> deleteContainKey(String key) =>
|
||||
_fcmCacheClient.clearAllDataContainKey(key);
|
||||
|
||||
@override
|
||||
Future<void> migrateHiveToIsolatedHive() async {
|
||||
await Future.wait([
|
||||
|
||||
@@ -93,7 +93,7 @@ class EmailCacheManager extends CacheManagerInteraction {
|
||||
|
||||
Future<void> clear() => _emailCacheClient.clearAllData();
|
||||
|
||||
Future<void> deleteByKey(String key) =>
|
||||
Future<void> deleteContainKey(String key) =>
|
||||
_emailCacheClient.clearAllDataContainKey(key);
|
||||
|
||||
Future<void> storeEmail(AccountId accountId, UserName userName, EmailCache emailCache) {
|
||||
|
||||
@@ -609,7 +609,10 @@ class ThreadController extends BaseController with EmailActionController {
|
||||
|
||||
Future<void> refreshAllEmail({bool forceEmailQuery = false}) async {
|
||||
if (forceEmailQuery) {
|
||||
await cachingManager.clearAllEmailAndStateCache();
|
||||
await cachingManager.clearAllEmailAndStateCache(
|
||||
accountId: mailboxDashBoardController.accountId.value,
|
||||
userName: mailboxDashBoardController.sessionCurrent?.username,
|
||||
);
|
||||
}
|
||||
|
||||
if (searchController.isSearchEmailRunning) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:ui';
|
||||
|
||||
import 'package:core/presentation/extensions/uri_extension.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get_utils/src/extensions/string_extensions.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/calendar_event_capability.dart';
|
||||
@@ -172,6 +173,15 @@ extension SessionExtension on Session {
|
||||
|
||||
AccountId get accountId => personalAccount.accountId;
|
||||
|
||||
AccountId? get safeAccountId {
|
||||
try {
|
||||
return personalAccount.accountId;
|
||||
} catch (e) {
|
||||
logError('SessionExtension::safeAccountId:Exception: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
({
|
||||
bool isAvailable,
|
||||
CalendarEventCapability? calendarEventCapability
|
||||
|
||||
Reference in New Issue
Block a user