Fix: Update EmailDeliveryState to Keychain

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit ac72825c7bb5840a8d779d0d1a0a336c75ade232)
This commit is contained in:
dab246
2024-01-11 01:29:34 +07:00
committed by Dat Vu
parent 360d5a542b
commit 987b018bb7
15 changed files with 88 additions and 5 deletions
@@ -1,4 +1,5 @@
import 'package:core/core.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/state.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
@@ -7,13 +8,19 @@ import 'package:tmail_ui_user/features/mailbox/data/local/state_cache_manager.da
import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart';
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
import 'package:tmail_ui_user/main/utils/ios_sharing_manager.dart';
class StateDataSourceImpl extends StateDataSource {
final StateCacheManager _stateCacheManager;
final IOSSharingManager _iosSharingManager;
final ExceptionThrower _exceptionThrower;
StateDataSourceImpl(this._stateCacheManager, this._exceptionThrower);
StateDataSourceImpl(
this._stateCacheManager,
this._iosSharingManager,
this._exceptionThrower
);
@override
Future<State?> getState(AccountId accountId, UserName userName, StateType stateType) {
@@ -25,7 +32,14 @@ class StateDataSourceImpl extends StateDataSource {
@override
Future<void> saveState(AccountId accountId, UserName userName, StateCache stateCache) {
return Future.sync(() async {
return await _stateCacheManager.saveState(accountId, userName, stateCache);
await _stateCacheManager.saveState(accountId, userName, stateCache);
if (PlatformInfo.isIOS && stateCache.type == StateType.email) {
final emailDeliveryStateKeychain = await _iosSharingManager.getEmailDeliveryStateFromKeychain(accountId);
if (emailDeliveryStateKeychain == null || emailDeliveryStateKeychain.isEmpty) {
await _iosSharingManager.updateEmailDeliveryStateInKeyChain(accountId, stateCache.state);
}
}
return Future.value(null);
}).catchError(_exceptionThrower.throwException);
}
}