TF-2871 Block notification on folders Sent, Outbox, Drafts, Spam and Trash
This commit is contained in:
@@ -4,13 +4,16 @@ import 'dart:convert';
|
||||
import 'package:core/utils/app_logger.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/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:model/extensions/mailbox_extension.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/local/authentication_info_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/local/oidc_configuration_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/oidc_http_client.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/local/state_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/extensions/keychain_sharing_session_extension.dart';
|
||||
@@ -24,6 +27,7 @@ class IOSSharingManager {
|
||||
final AuthenticationInfoCacheManager _authenticationInfoCacheManager;
|
||||
final OidcConfigurationCacheManager _oidcConfigurationCacheManager;
|
||||
final OIDCHttpClient _oidcHttpClient;
|
||||
final MailboxCacheManager _mailboxCacheManager;
|
||||
|
||||
IOSSharingManager(
|
||||
this._keychainSharingManager,
|
||||
@@ -32,6 +36,7 @@ class IOSSharingManager {
|
||||
this._authenticationInfoCacheManager,
|
||||
this._oidcConfigurationCacheManager,
|
||||
this._oidcHttpClient,
|
||||
this._mailboxCacheManager,
|
||||
);
|
||||
|
||||
bool _validateToSaveKeychain(PersonalAccount personalAccount) {
|
||||
@@ -79,6 +84,10 @@ class IOSSharingManager {
|
||||
|
||||
final tokenRecords = await _getTokenEndpointAndScopes();
|
||||
|
||||
final mailboxIdsBlockNotification = await _getMailboxIdsBlockNotification(
|
||||
accountId: personalAccount.accountId!,
|
||||
userName: personalAccount.userName!);
|
||||
|
||||
final keychainSharingSession = KeychainSharingSession(
|
||||
accountId: personalAccount.accountId!,
|
||||
userName: personalAccount.userName!,
|
||||
@@ -90,7 +99,7 @@ class IOSSharingManager {
|
||||
basicAuth: credentialInfo,
|
||||
tokenEndpoint: tokenRecords?.tokenEndpoint,
|
||||
oidcScopes: tokenRecords?.scopes,
|
||||
);
|
||||
mailboxIdsBlockNotification: mailboxIdsBlockNotification);
|
||||
|
||||
await _keychainSharingManager.save(keychainSharingSession);
|
||||
|
||||
@@ -184,4 +193,48 @@ class IOSSharingManager {
|
||||
final newKeychain = keychainSharingStored.updating(emailState: newEmailState);
|
||||
await _keychainSharingManager.save(newKeychain);
|
||||
}
|
||||
|
||||
Future<bool> isExistMailboxIdsBlockNotificationInKeyChain(AccountId accountId) async {
|
||||
try {
|
||||
final keychainSharingStored = await getKeychainSharingSession(accountId);
|
||||
return keychainSharingStored?.mailboxIdsBlockNotification?.isNotEmpty == true;
|
||||
} catch (e) {
|
||||
logError('IOSSharingManager::getMailboxIdsBlockNotificationInKeyChain:Exception = $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateMailboxIdsBlockNotificationInKeyChain({
|
||||
required AccountId accountId,
|
||||
required List<MailboxId> mailboxIds
|
||||
}) async {
|
||||
try {
|
||||
final keychainSharingStored = await getKeychainSharingSession(accountId);
|
||||
if (keychainSharingStored == null) {
|
||||
return;
|
||||
}
|
||||
final newKeychain = keychainSharingStored.updating(mailboxIdsBlockNotification: mailboxIds);
|
||||
await _keychainSharingManager.save(newKeychain);
|
||||
} catch (e) {
|
||||
logError('IOSSharingManager::updateMailboxIdsBlockNotificationInKeyChain: Exception = $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<MailboxId>?> _getMailboxIdsBlockNotification({
|
||||
required AccountId accountId,
|
||||
required UserName userName,
|
||||
}) async {
|
||||
try {
|
||||
final mailboxesCache = await _mailboxCacheManager.getAllMailbox(accountId, userName);
|
||||
final listMailboxIdBlockNotification = mailboxesCache
|
||||
.where((mailbox) => mailbox.pushNotificationDeactivated && mailbox.id != null)
|
||||
.map((mailbox) => mailbox.id!)
|
||||
.toList();
|
||||
log('IOSSharingManager::_getMailboxIdsBlockNotification(): CACHE_MAILBOX_LIST = $listMailboxIdBlockNotification');
|
||||
return listMailboxIdBlockNotification;
|
||||
} catch (e) {
|
||||
logError('IOSSharingManager::_getMailboxIdsBlockNotification:Exception: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user