Use TupleKey(ObjectKey-AccountId-UserName) to store data to hive
(cherry picked from commit e0ace535d5f3af71eb13598d92524caf2c6d9bbf)
This commit is contained in:
@@ -7,7 +7,9 @@ import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.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/authentication_type.dart';
|
||||
import 'package:model/extensions/session_extension.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/get_authenticated_account_state.dart';
|
||||
@@ -74,11 +76,11 @@ abstract class ReloadableController extends BaseController {
|
||||
_dynamicUrlInterceptors.setJmapUrl(credentialViewState.baseUrl.origin);
|
||||
_dynamicUrlInterceptors.changeBaseUrl(credentialViewState.baseUrl.origin);
|
||||
authorizationInterceptors.setBasicAuthorization(
|
||||
credentialViewState.userName.userName,
|
||||
credentialViewState.userName.value,
|
||||
credentialViewState.password.value,
|
||||
);
|
||||
authorizationIsolateInterceptors.setBasicAuthorization(
|
||||
credentialViewState.userName.userName,
|
||||
credentialViewState.userName.value,
|
||||
credentialViewState.password.value,
|
||||
);
|
||||
}
|
||||
@@ -108,15 +110,17 @@ abstract class ReloadableController extends BaseController {
|
||||
}
|
||||
|
||||
void _handleGetSessionSuccess(GetSessionSuccess success) {
|
||||
final session = success.session;
|
||||
final personalAccount = session.personalAccount;
|
||||
final jmapUrl = _dynamicUrlInterceptors.jmapUrl;
|
||||
final apiUrl = jmapUrl != null
|
||||
? success.session.apiUrl.toQualifiedUrl(baseUrl: Uri.parse(jmapUrl)).toString()
|
||||
: success.session.apiUrl.toString();
|
||||
? session.apiUrl.toQualifiedUrl(baseUrl: Uri.parse(jmapUrl)).toString()
|
||||
: session.apiUrl.toString();
|
||||
log('ReloadableController::_handleGetSessionSuccess():apiUrl: $apiUrl');
|
||||
if (apiUrl.isNotEmpty) {
|
||||
_dynamicUrlInterceptors.changeBaseUrl(apiUrl);
|
||||
updateAuthenticationAccount(success.session, success.session.accounts.keys.first);
|
||||
handleReloaded(success.session);
|
||||
updateAuthenticationAccount(session, personalAccount.accountId, session.username);
|
||||
handleReloaded(session);
|
||||
} else {
|
||||
_handleGetSessionFailure();
|
||||
}
|
||||
@@ -149,14 +153,14 @@ abstract class ReloadableController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
void updateAuthenticationAccount(Session session, AccountId accountId) {
|
||||
void updateAuthenticationAccount(Session session, AccountId accountId, UserName userName) {
|
||||
final jmapUrl = _dynamicUrlInterceptors.jmapUrl;
|
||||
final apiUrl = jmapUrl != null
|
||||
? session.apiUrl.toQualifiedUrl(baseUrl: Uri.parse(jmapUrl)).toString()
|
||||
: session.apiUrl.toString();
|
||||
log('ReloadableController::updateAuthenticationAccount():apiUrl: $apiUrl');
|
||||
if (apiUrl.isNotEmpty) {
|
||||
consumeState(_updateAuthenticationAccountInteractor.execute(accountId, apiUrl));
|
||||
consumeState(_updateAuthenticationAccountInteractor.execute(accountId, apiUrl, userName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/extensions/map_extensions.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
||||
@@ -79,14 +79,11 @@ abstract class HiveCacheClient<T> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<T>> getListByCollectionId(String collectionId) {
|
||||
Future<List<T>> getListByTupleKey(String accountId, String userName) {
|
||||
return Future.sync(() async {
|
||||
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
||||
return boxItem.toMap()
|
||||
.where((key, value) {
|
||||
final tupleKey = TupleKey.fromString(key as String);
|
||||
return tupleKey.parts.length >= 2 && tupleKey.parts[1] == collectionId;
|
||||
})
|
||||
.where((key, value) => _matchedKey(key, accountId, userName))
|
||||
.values
|
||||
.toList();
|
||||
}).catchError((error) {
|
||||
@@ -94,6 +91,12 @@ abstract class HiveCacheClient<T> {
|
||||
});
|
||||
}
|
||||
|
||||
bool _matchedKey(String key, String accountId, String userName) {
|
||||
final keyDecoded = CacheUtils.decodeKey(key);
|
||||
final tupleKey = TupleKey.fromString(keyDecoded);
|
||||
return tupleKey.parts.length >= 3 && tupleKey.parts[1] == accountId && tupleKey.parts[2] == userName;
|
||||
}
|
||||
|
||||
Future<void> updateItem(String key, T newObject) {
|
||||
return Future.sync(() async {
|
||||
final boxItem = encryption
|
||||
|
||||
@@ -1,4 +1,22 @@
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
|
||||
class CacheUtils {
|
||||
static String encodeKey(String key) {
|
||||
final keyEncoded = base64.encode(utf8.encode(key));
|
||||
log('CacheUtils::encodeKey():keyHashed: $keyEncoded');
|
||||
return keyEncoded;
|
||||
}
|
||||
|
||||
static String decodeKey(String keyEncoded) {
|
||||
final keyDecoded = utf8.decode(base64.decode(keyEncoded));
|
||||
log('CacheUtils::decodeKey():keyDecoded: $keyDecoded');
|
||||
return keyDecoded;
|
||||
}
|
||||
}
|
||||
|
||||
class TupleKey {
|
||||
final List<String> parts;
|
||||
|
||||
@@ -26,4 +44,6 @@ class TupleKey {
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hashAll(parts);
|
||||
|
||||
String get encodeKey => CacheUtils.encodeKey(toString());
|
||||
}
|
||||
@@ -18,8 +18,8 @@ class SaveEmailAsDraftsInteractor {
|
||||
yield Right<Failure, Success>(SaveEmailAsDraftsLoading());
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -25,8 +25,8 @@ class SendEmailInteractor {
|
||||
yield Right<Failure, Success>(SendingEmailState());
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -20,8 +20,8 @@ class UpdateEmailDraftsInteractor {
|
||||
yield Right<Failure, Success>(UpdatingEmailDrafts());
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -171,7 +171,7 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<jmap.State?> getEmailState(AccountId accountId) {
|
||||
return _stateDataSource.getState(accountId, StateType.email);
|
||||
Future<jmap.State?> getEmailState(Session session, AccountId accountId) {
|
||||
return _stateDataSource.getState(accountId, session.username, StateType.email);
|
||||
}
|
||||
}
|
||||
@@ -85,5 +85,5 @@ abstract class EmailRepository {
|
||||
|
||||
Future<bool> deleteEmailPermanently(Session session, AccountId accountId, EmailId emailId);
|
||||
|
||||
Future<jmap.State?> getEmailState(AccountId accountId);
|
||||
Future<jmap.State?> getEmailState(Session session, AccountId accountId);
|
||||
}
|
||||
@@ -18,8 +18,8 @@ class DeleteEmailPermanentlyInteractor {
|
||||
yield Right<Failure, Success>(StartDeleteEmailPermanently());
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@ class DeleteMultipleEmailsPermanentlyInteractor {
|
||||
yield Right<Failure, Success>(LoadingDeleteMultipleEmailsPermanentlyAll());
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -4,10 +4,10 @@ import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/account/user_name.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachments_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/oidc_configuration_extensions.dart';
|
||||
@@ -95,13 +103,13 @@ class DownloadAttachmentsInteractor {
|
||||
await Future.wait([
|
||||
_authenticationOIDCRepository.persistTokenOIDC(newTokenOIDC),
|
||||
_accountRepository.deleteCurrentAccount(accountCurrent.id),
|
||||
_accountRepository.setCurrentAccount(Account(
|
||||
_accountRepository.setCurrentAccount(PersonalAccount(
|
||||
newTokenOIDC.tokenIdHash,
|
||||
AuthenticationType.oidc,
|
||||
isSelected: true,
|
||||
accountId: accountId,
|
||||
apiUrl: accountCurrent.apiUrl
|
||||
))
|
||||
apiUrl: accountCurrent.apiUrl,
|
||||
userName: accountCurrent.userName))
|
||||
]);
|
||||
|
||||
_authorizationInterceptors.setTokenAndAuthorityOidc(
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/export_attachment_state.dart';
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.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/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/get_stored_state_email_state.dart';
|
||||
|
||||
@@ -10,9 +11,9 @@ class GetStoredEmailStateInteractor {
|
||||
|
||||
GetStoredEmailStateInteractor(this._emailRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId) async* {
|
||||
try {
|
||||
final state = await _emailRepository.getEmailState(accountId);
|
||||
final state = await _emailRepository.getEmailState(session, accountId);
|
||||
if (state != null) {
|
||||
yield Right<Failure, Success>(GetStoredEmailStateSuccess(state));
|
||||
} else {
|
||||
|
||||
@@ -17,8 +17,8 @@ class MarkAsEmailReadInteractor {
|
||||
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId, Email email, ReadActions readAction) async* {
|
||||
try {
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState( session,accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -14,7 +14,7 @@ class MarkAsStarEmailInteractor {
|
||||
|
||||
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId, Email email, MarkStarAction markStarAction) async* {
|
||||
try {
|
||||
final currentEmailState = await emailRepository.getEmailState(accountId);
|
||||
final currentEmailState = await emailRepository.getEmailState(session, accountId);
|
||||
final result = await emailRepository.markAsStar(session, accountId, [email], markStarAction);
|
||||
if (result.isNotEmpty) {
|
||||
final updatedEmail = email.updatedEmail(newKeywords: result.first.keywords);
|
||||
|
||||
@@ -18,8 +18,8 @@ class MoveToMailboxInteractor {
|
||||
yield Right(LoadingMoveToMailbox());
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/data/network/config/dynamic_url_interceptors.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:model/email/email_content.dart';
|
||||
import 'package:model/email/email_content_type.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
|
||||
@@ -45,7 +51,7 @@ class HomeController extends BaseController {
|
||||
this._cleanupRecentLoginUsernameCacheInteractor,
|
||||
);
|
||||
|
||||
Account? currentAccount;
|
||||
PersonalAccount? currentAccount;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -150,11 +156,11 @@ class HomeController extends BaseController {
|
||||
_dynamicUrlInterceptors.setJmapUrl(credentialViewState.baseUrl.origin);
|
||||
_dynamicUrlInterceptors.changeBaseUrl(credentialViewState.baseUrl.origin);
|
||||
authorizationInterceptors.setBasicAuthorization(
|
||||
credentialViewState.userName.userName,
|
||||
credentialViewState.userName.value,
|
||||
credentialViewState.password.value,
|
||||
);
|
||||
authorizationIsolateInterceptors.setBasicAuthorization(
|
||||
credentialViewState.userName.userName,
|
||||
credentialViewState.userName.value,
|
||||
credentialViewState.password.value,
|
||||
);
|
||||
pushAndPop(AppRoutes.session, arguments: _dynamicUrlInterceptors.baseUrl);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
|
||||
abstract class AccountDatasource {
|
||||
Future<Account> getCurrentAccount();
|
||||
Future<PersonalAccount> getCurrentAccount();
|
||||
|
||||
Future<void> setCurrentAccount(Account newCurrentAccount);
|
||||
Future<void> setCurrentAccount(PersonalAccount newCurrentAccount);
|
||||
|
||||
Future<void> deleteCurrentAccount(String accountId);
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/user/user_profile.dart';
|
||||
|
||||
abstract class AuthenticationDataSource {
|
||||
Future<UserProfile> authenticationUser(Uri baseUrl, UserName userName, Password password);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/user/user_profile.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/authentication_datasource.dart';
|
||||
|
||||
class AuthenticationDataSourceImpl extends AuthenticationDataSource {
|
||||
@@ -8,7 +10,7 @@ class AuthenticationDataSourceImpl extends AuthenticationDataSource {
|
||||
@override
|
||||
Future<UserProfile> authenticationUser(Uri baseUrl, UserName userName, Password password) {
|
||||
return Future.sync(() {
|
||||
return UserProfile(userName.userName);
|
||||
return UserProfile(userName.value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/account_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||
@@ -11,14 +11,14 @@ class HiveAccountDatasourceImpl extends AccountDatasource {
|
||||
HiveAccountDatasourceImpl(this._accountCacheManager, this._exceptionThrower);
|
||||
|
||||
@override
|
||||
Future<Account> getCurrentAccount() {
|
||||
Future<PersonalAccount> getCurrentAccount() {
|
||||
return Future.sync(() async {
|
||||
return await _accountCacheManager.getSelectedAccount();
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setCurrentAccount(Account newCurrentAccount) {
|
||||
Future<void> setCurrentAccount(PersonalAccount newCurrentAccount) {
|
||||
return Future.sync(() async {
|
||||
return await _accountCacheManager.setSelectedAccount(newCurrentAccount);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
|
||||
|
||||
extension AccountCacheExtension on AccountCache {
|
||||
@@ -15,14 +16,14 @@ extension AccountCacheExtension on AccountCache {
|
||||
}
|
||||
}
|
||||
|
||||
Account toAccount() {
|
||||
PersonalAccount toAccount() {
|
||||
final authenticationType = fromAuthenticationTypeString();
|
||||
return Account(
|
||||
return PersonalAccount(
|
||||
id,
|
||||
authenticationType,
|
||||
isSelected: isSelected,
|
||||
accountId: accountId != null ? AccountId(Id(accountId!)) : null,
|
||||
apiUrl: apiUrl
|
||||
);
|
||||
apiUrl: apiUrl,
|
||||
userName: userName != null ? UserName(userName!) : null);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
|
||||
|
||||
extension AccountExtensions on Account {
|
||||
extension PersonalAccountExtension on PersonalAccount {
|
||||
AccountCache toCache() {
|
||||
return AccountCache(
|
||||
id,
|
||||
authenticationType.asString(),
|
||||
isSelected: isSelected,
|
||||
accountId: accountId?.id.value,
|
||||
apiUrl: apiUrl
|
||||
);
|
||||
apiUrl: apiUrl,
|
||||
userName: userName?.value);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/caching/account_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/account_cache_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/account_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/personal_account_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
|
||||
class AccountCacheManager {
|
||||
@@ -10,7 +10,7 @@ class AccountCacheManager {
|
||||
|
||||
AccountCacheManager(this._accountCacheClient);
|
||||
|
||||
Future<Account> getSelectedAccount() async {
|
||||
Future<PersonalAccount> getSelectedAccount() async {
|
||||
try {
|
||||
final allAccounts = await _accountCacheClient.getAll();
|
||||
return allAccounts.firstWhere((account) => account.isSelected)
|
||||
@@ -21,7 +21,7 @@ class AccountCacheManager {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setSelectedAccount(Account account) {
|
||||
Future<void> setSelectedAccount(PersonalAccount account) {
|
||||
log('AccountCacheManager::setSelectedAccount(): $_accountCacheClient');
|
||||
return _accountCacheClient.insertItem(account.id, account.toCache());
|
||||
}
|
||||
|
||||
@@ -21,13 +21,17 @@ class AccountCache extends HiveObject with EquatableMixin {
|
||||
@HiveField(4)
|
||||
final String? apiUrl;
|
||||
|
||||
@HiveField(5)
|
||||
final String? userName;
|
||||
|
||||
AccountCache(
|
||||
this.id,
|
||||
this.authenticationType,
|
||||
{
|
||||
required this.isSelected,
|
||||
this.accountId,
|
||||
this.apiUrl
|
||||
this.apiUrl,
|
||||
this.userName
|
||||
}
|
||||
);
|
||||
|
||||
@@ -37,6 +41,7 @@ class AccountCache extends HiveObject with EquatableMixin {
|
||||
authenticationType,
|
||||
isSelected,
|
||||
accountId,
|
||||
apiUrl
|
||||
apiUrl,
|
||||
userName
|
||||
];
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:model/oidc/token.dart';
|
||||
@@ -93,13 +93,13 @@ class AuthorizationInterceptors extends InterceptorsWrapper {
|
||||
await Future.wait([
|
||||
_tokenOidcCacheManager.persistOneTokenOidc(newToken),
|
||||
_accountCacheManager.deleteSelectedAccount(_token!.tokenIdHash),
|
||||
_accountCacheManager.setSelectedAccount(Account(
|
||||
_accountCacheManager.setSelectedAccount(PersonalAccount(
|
||||
newToken.tokenIdHash,
|
||||
AuthenticationType.oidc,
|
||||
isSelected: true,
|
||||
accountId: accountCurrent.accountId,
|
||||
apiUrl: accountCurrent.apiUrl
|
||||
)),
|
||||
apiUrl: accountCurrent.apiUrl,
|
||||
userName: accountCurrent.userName))
|
||||
]);
|
||||
|
||||
log('AuthorizationInterceptors::onError(): refreshToken: $newToken');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/account_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
|
||||
@@ -10,12 +10,12 @@ class AccountRepositoryImpl extends AccountRepository {
|
||||
AccountRepositoryImpl(this._accountDatasource);
|
||||
|
||||
@override
|
||||
Future<Account> getCurrentAccount() {
|
||||
Future<PersonalAccount> getCurrentAccount() {
|
||||
return _accountDatasource.getCurrentAccount();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setCurrentAccount(Account newCurrentAccount) {
|
||||
Future<void> setCurrentAccount(PersonalAccount newCurrentAccount) {
|
||||
log('AccountRepositoryImpl::setCurrentAccount(): $newCurrentAccount');
|
||||
return _accountDatasource.setCurrentAccount(newCurrentAccount);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/user/user_profile.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/authentication_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_repository.dart';
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
|
||||
abstract class AccountRepository {
|
||||
Future<Account> getCurrentAccount();
|
||||
Future<PersonalAccount> getCurrentAccount();
|
||||
|
||||
Future<void> setCurrentAccount(Account newCurrentAccount);
|
||||
Future<void> setCurrentAccount(PersonalAccount newCurrentAccount);
|
||||
|
||||
Future<void> deleteCurrentAccount(String accountId);
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'package:model/model.dart';
|
||||
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/user/user_profile.dart';
|
||||
|
||||
abstract class AuthenticationRepository {
|
||||
Future<UserProfile> authenticationUser(Uri baseUrl, UserName userName, Password password);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
|
||||
class NoAuthenticatedAccountFailure extends FeatureFailure {
|
||||
|
||||
@@ -11,7 +11,7 @@ class NoAuthenticatedAccountFailure extends FeatureFailure {
|
||||
}
|
||||
|
||||
class GetAuthenticatedAccountSuccess extends UIState {
|
||||
final Account account;
|
||||
final PersonalAccount account;
|
||||
|
||||
GetAuthenticatedAccountSuccess(this.account);
|
||||
|
||||
@@ -20,9 +20,7 @@ class GetAuthenticatedAccountSuccess extends UIState {
|
||||
}
|
||||
|
||||
class GetAuthenticatedAccountFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
GetAuthenticatedAccountFailure(this.exception);
|
||||
GetAuthenticatedAccountFailure(dynamic exception) : super(exception: exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [exception];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/account/user_name.dart';
|
||||
|
||||
class GetCredentialViewState extends UIState {
|
||||
final Uri baseUrl;
|
||||
@@ -14,9 +15,8 @@ class GetCredentialViewState extends UIState {
|
||||
}
|
||||
|
||||
class GetCredentialFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
GetCredentialFailure(this.exception);
|
||||
GetCredentialFailure(dynamic exception) : super(exception: exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [exception];
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_repository.dart';
|
||||
@@ -24,10 +29,9 @@ class AuthenticationInteractor {
|
||||
final user = await authenticationRepository.authenticationUser(baseUrl, userName, password);
|
||||
await Future.wait([
|
||||
credentialRepository.saveBaseUrl(baseUrl),
|
||||
credentialRepository.storeAuthenticationInfo(
|
||||
AuthenticationInfoCache(userName.userName, password.value)),
|
||||
_accountRepository.setCurrentAccount(Account(
|
||||
userName.userName,
|
||||
credentialRepository.storeAuthenticationInfo(AuthenticationInfoCache(userName.value, password.value)),
|
||||
_accountRepository.setCurrentAccount(PersonalAccount(
|
||||
userName.value,
|
||||
AuthenticationType.basic,
|
||||
isSelected: true
|
||||
))
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dart:core';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/uri_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
@@ -19,9 +21,9 @@ class GetCredentialInteractor {
|
||||
final authenticationInfo = await credentialRepository.getAuthenticationInfoStored();
|
||||
if (isCredentialValid(baseUrl) && authenticationInfo != null) {
|
||||
return Right(GetCredentialViewState(
|
||||
baseUrl,
|
||||
UserName(authenticationInfo.username),
|
||||
Password(authenticationInfo.password)));
|
||||
baseUrl,
|
||||
UserName(authenticationInfo.username),
|
||||
Password(authenticationInfo.password)));
|
||||
} else {
|
||||
return Left(GetCredentialFailure(BadCredentials()));
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/oidc_configuration_extensions.dart';
|
||||
@@ -31,10 +31,10 @@ class GetTokenOIDCInteractor {
|
||||
config.scopes);
|
||||
await Future.wait([
|
||||
_credentialRepository.saveBaseUrl(baseUrl),
|
||||
_accountRepository.setCurrentAccount(Account(
|
||||
tokenOIDC.tokenIdHash,
|
||||
AuthenticationType.oidc,
|
||||
isSelected: true)),
|
||||
_accountRepository.setCurrentAccount(PersonalAccount(
|
||||
tokenOIDC.tokenIdHash,
|
||||
AuthenticationType.oidc,
|
||||
isSelected: true)),
|
||||
authenticationOIDCRepository.persistTokenOIDC(tokenOIDC),
|
||||
authenticationOIDCRepository.persistAuthorityOidc(config.authority),
|
||||
]);
|
||||
|
||||
@@ -2,7 +2,8 @@ import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/extensions/account_extension.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/extensions/personal_account_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/update_authentication_account_state.dart';
|
||||
|
||||
@@ -11,14 +12,15 @@ class UpdateAuthenticationAccountInteractor {
|
||||
|
||||
UpdateAuthenticationAccountInteractor(this._accountRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, String apiUrl) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, String apiUrl, UserName userName) async* {
|
||||
try{
|
||||
yield Right(UpdateAuthenticationAccountLoading());
|
||||
final currentAccount = await _accountRepository.getCurrentAccount();
|
||||
await _accountRepository.setCurrentAccount(
|
||||
currentAccount.fromAccountId(
|
||||
currentAccount.fromAccount(
|
||||
accountId: accountId,
|
||||
apiUrl: apiUrl
|
||||
apiUrl: apiUrl,
|
||||
userName: userName
|
||||
)
|
||||
);
|
||||
yield Right(UpdateAuthenticationAccountSuccess());
|
||||
|
||||
@@ -10,8 +10,8 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
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/account/user_name.dart';
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:model/oidc/request/oidc_request.dart';
|
||||
import 'package:model/oidc/response/oidc_response.dart';
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_change_response.dart';
|
||||
@@ -22,11 +23,11 @@ import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_multiple_m
|
||||
abstract class MailboxDataSource {
|
||||
Future<MailboxResponse> getAllMailbox(Session session, AccountId accountId, {Properties? properties});
|
||||
|
||||
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId);
|
||||
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId, UserName userName);
|
||||
|
||||
Future<MailboxChangeResponse> getChanges(Session session, AccountId accountId, State sinceState);
|
||||
|
||||
Future<void> update(AccountId accountId, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed});
|
||||
Future<void> update(AccountId accountId, UserName userName, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed});
|
||||
|
||||
Future<Mailbox?> createNewMailbox(Session session, AccountId accountId, CreateNewMailboxRequest newMailboxRequest);
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
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';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
|
||||
|
||||
abstract class StateDataSource {
|
||||
Future<State?> getState(AccountId accountId, StateType stateType);
|
||||
Future<State?> getState(AccountId accountId, UserName userName, StateType stateType);
|
||||
|
||||
Future<void> saveState(AccountId accountId, StateCache stateCache);
|
||||
Future<void> saveState(AccountId accountId, UserName userName, StateCache stateCache);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart';
|
||||
@@ -40,16 +41,16 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> update(AccountId accountId, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
|
||||
Future<void> update(AccountId accountId, UserName userName, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
|
||||
return Future.sync(() async {
|
||||
return await _mailboxCacheManager.update(accountId, updated: updated, created: created, destroyed: destroyed);
|
||||
return await _mailboxCacheManager.update(accountId, userName, updated: updated, created: created, destroyed: destroyed);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId) {
|
||||
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId, UserName userName) {
|
||||
return Future.sync(() async {
|
||||
final listMailboxes = await _mailboxCacheManager.getAllMailbox(accountId);
|
||||
final listMailboxes = await _mailboxCacheManager.getAllMailbox(accountId, userName);
|
||||
return listMailboxes;
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart';
|
||||
@@ -46,12 +47,12 @@ class MailboxDataSourceImpl extends MailboxDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> update(AccountId accountId, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
|
||||
Future<void> update(AccountId accountId, UserName userName, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId) {
|
||||
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId, UserName userName) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
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';
|
||||
import 'package:model/extensions/account_id_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/caching/state_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
||||
@@ -18,19 +19,19 @@ class StateDataSourceImpl extends StateDataSource {
|
||||
StateDataSourceImpl(this._stateCacheClient, this._exceptionThrower);
|
||||
|
||||
@override
|
||||
Future<State?> getState(AccountId accountId, StateType stateType) {
|
||||
Future<State?> getState(AccountId accountId, UserName userName, StateType stateType) {
|
||||
return Future.sync(() async {
|
||||
final stateKey = TupleKey(stateType.value, accountId.asString).toString();
|
||||
final stateKey = TupleKey(stateType.value, accountId.asString, userName.value).encodeKey;
|
||||
final stateCache = await _stateCacheClient.getItem(stateKey);
|
||||
return stateCache?.toState();
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveState(AccountId accountId, StateCache stateCache) {
|
||||
Future<void> saveState(AccountId accountId, UserName userName, StateCache stateCache) {
|
||||
return Future.sync(() async {
|
||||
final stateCacheExist = await _stateCacheClient.isExistTable();
|
||||
final stateKey = TupleKey(stateCache.type.value, accountId.asString).toString();
|
||||
final stateKey = TupleKey(stateCache.type.value, accountId.asString, userName.value).encodeKey;
|
||||
if (stateCacheExist) {
|
||||
return await _stateCacheClient.updateItem(stateKey, stateCache);
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
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/extensions/account_id_extensions.dart';
|
||||
import 'package:model/extensions/mailbox_id_extension.dart';
|
||||
@@ -8,10 +9,10 @@ import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_extension
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart';
|
||||
|
||||
extension ListMailboxExtension on List<Mailbox> {
|
||||
Map<String, MailboxCache> toMapCache(AccountId accountId) {
|
||||
Map<String, MailboxCache> toMapCache(AccountId accountId, UserName userName) {
|
||||
return {
|
||||
for (var mailbox in this)
|
||||
TupleKey(mailbox.id!.asString, accountId.asString).toString() : mailbox.toMailboxCache()
|
||||
TupleKey(mailbox.id!.asString, accountId.asString, userName.value).encodeKey : mailbox.toMailboxCache()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
|
||||
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/extensions/account_id_extensions.dart';
|
||||
import 'package:model/extensions/mailbox_id_extension.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
||||
|
||||
extension ListMailboxIdExtension on List<MailboxId> {
|
||||
List<String> toCacheKeyList(AccountId accountId) => map((id) => TupleKey(id.asString, accountId.asString).toString()).toList();
|
||||
List<String> toCacheKeyList(AccountId accountId, UserName userName) =>
|
||||
map((id) => TupleKey(id.asString, accountId.asString, userName.value).encodeKey).toList();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
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/extensions/account_id_extensions.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
@@ -15,22 +16,23 @@ class MailboxCacheManager {
|
||||
|
||||
MailboxCacheManager(this._mailboxCacheClient);
|
||||
|
||||
Future<List<Mailbox>> getAllMailbox(AccountId accountId) async {
|
||||
final mailboxCacheList = await _mailboxCacheClient.getListByCollectionId(accountId.asString);
|
||||
Future<List<Mailbox>> getAllMailbox(AccountId accountId, UserName userName) async {
|
||||
final mailboxCacheList = await _mailboxCacheClient.getListByTupleKey(accountId.asString, userName.value);
|
||||
return mailboxCacheList.toMailboxList();
|
||||
}
|
||||
|
||||
Future<void> update(
|
||||
AccountId accountId, {
|
||||
AccountId accountId,
|
||||
UserName userName, {
|
||||
List<Mailbox>? updated,
|
||||
List<Mailbox>? created,
|
||||
List<MailboxId>? destroyed
|
||||
}) async {
|
||||
final mailboxCacheExist = await _mailboxCacheClient.isExistTable();
|
||||
if (mailboxCacheExist) {
|
||||
final updatedCacheMailboxes = updated?.toMapCache(accountId) ?? {};
|
||||
final createdCacheMailboxes = created?.toMapCache(accountId) ?? {};
|
||||
final destroyedCacheMailboxes = destroyed?.toCacheKeyList(accountId) ?? [];
|
||||
final updatedCacheMailboxes = updated?.toMapCache(accountId, userName) ?? {};
|
||||
final createdCacheMailboxes = created?.toMapCache(accountId, userName) ?? {};
|
||||
final destroyedCacheMailboxes = destroyed?.toCacheKeyList(accountId, userName) ?? [];
|
||||
|
||||
await Future.wait([
|
||||
_mailboxCacheClient.updateMultipleItem(updatedCacheMailboxes),
|
||||
@@ -38,14 +40,14 @@ class MailboxCacheManager {
|
||||
_mailboxCacheClient.deleteMultipleItem(destroyedCacheMailboxes)
|
||||
]);
|
||||
} else {
|
||||
final createdCacheMailboxes = created?.toMapCache(accountId) ?? {};
|
||||
final createdCacheMailboxes = created?.toMapCache(accountId, userName) ?? {};
|
||||
await _mailboxCacheClient.insertMultipleItem(createdCacheMailboxes);
|
||||
}
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
Future<Mailbox> getSpamMailbox(AccountId accountId) async {
|
||||
final mailboxCachedList = await _mailboxCacheClient.getListByCollectionId(accountId.asString);
|
||||
Future<Mailbox> getSpamMailbox(AccountId accountId, UserName userName) async {
|
||||
final mailboxCachedList = await _mailboxCacheClient.getListByTupleKey(accountId.asString, userName.value);
|
||||
final listSpamMailboxCached = mailboxCachedList
|
||||
.toMailboxList()
|
||||
.where((mailbox) => mailbox.role == PresentationMailbox.roleSpam)
|
||||
|
||||
@@ -39,8 +39,8 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
@override
|
||||
Stream<MailboxResponse> getAllMailbox(Session session, AccountId accountId, {Properties? properties}) async* {
|
||||
final localMailboxResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||
stateDataSource.getState(accountId, StateType.mailbox)
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username),
|
||||
stateDataSource.getState(accountId, session.username, StateType.mailbox)
|
||||
]).then((List response) {
|
||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||
});
|
||||
@@ -65,26 +65,27 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.update(
|
||||
accountId,
|
||||
session.username,
|
||||
updated: newMailboxUpdated,
|
||||
created: changesResponse.created,
|
||||
destroyed: changesResponse.destroyed),
|
||||
if (changesResponse.newStateMailbox != null)
|
||||
stateDataSource.saveState(accountId, changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)),
|
||||
stateDataSource.saveState(accountId, session.username, changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)),
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
final mailboxResponse = await mapDataSource[DataSourceType.network]!.getAllMailbox(session, accountId);
|
||||
|
||||
await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.update(accountId, created: mailboxResponse.mailboxes),
|
||||
mapDataSource[DataSourceType.local]!.update(accountId, session.username, created: mailboxResponse.mailboxes),
|
||||
if (mailboxResponse.state != null)
|
||||
stateDataSource.saveState(accountId, mailboxResponse.state!.toStateCache(StateType.mailbox)),
|
||||
stateDataSource.saveState(accountId, session.username, mailboxResponse.state!.toStateCache(StateType.mailbox)),
|
||||
]);
|
||||
}
|
||||
|
||||
final newMailboxResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||
stateDataSource.getState(accountId, StateType.mailbox)
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username),
|
||||
stateDataSource.getState(accountId, session.username, StateType.mailbox)
|
||||
]).then((List response) {
|
||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||
});
|
||||
@@ -118,7 +119,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
|
||||
@override
|
||||
Stream<MailboxResponse> refresh(Session session, AccountId accountId, State currentState) async* {
|
||||
final localMailboxList = await mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId);
|
||||
final localMailboxList = await mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username);
|
||||
|
||||
bool hasMoreChanges = true;
|
||||
State? sinceState = currentState;
|
||||
@@ -137,17 +138,18 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.update(
|
||||
accountId,
|
||||
session.username,
|
||||
updated: newMailboxUpdated,
|
||||
created: changesResponse.created,
|
||||
destroyed: changesResponse.destroyed),
|
||||
if (changesResponse.newStateMailbox != null)
|
||||
stateDataSource.saveState(accountId, changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)),
|
||||
stateDataSource.saveState(accountId, session.username, changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)),
|
||||
]);
|
||||
}
|
||||
|
||||
final newMailboxResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||
stateDataSource.getState(accountId, StateType.mailbox)
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username),
|
||||
stateDataSource.getState(accountId, session.username, StateType.mailbox)
|
||||
]).then((List response) {
|
||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||
});
|
||||
@@ -191,8 +193,8 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<State?> getMailboxState(AccountId accountId) {
|
||||
return stateDataSource.getState(accountId, StateType.mailbox);
|
||||
Future<State?> getMailboxState(Session session, AccountId accountId) {
|
||||
return stateDataSource.getState(accountId, session.username, StateType.mailbox);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -38,7 +38,7 @@ abstract class MailboxRepository {
|
||||
|
||||
Future<bool> moveMailbox(Session session, AccountId accountId, MoveMailboxRequest request);
|
||||
|
||||
Future<State?> getMailboxState(AccountId accountId);
|
||||
Future<State?> getMailboxState(Session session, AccountId accountId);
|
||||
|
||||
Future<bool> subscribeMailbox(Session session, AccountId accountId, SubscribeMailboxRequest request);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class CreateNewMailboxInteractor {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingCreateNewMailbox());
|
||||
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(accountId);
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(session, accountId);
|
||||
final newMailbox = await _mailboxRepository.createNewMailbox(session, accountId, newMailboxRequest);
|
||||
if (newMailbox != null) {
|
||||
yield Right<Failure, Success>(CreateNewMailboxSuccess(
|
||||
|
||||
@@ -22,7 +22,7 @@ class DeleteMultipleMailboxInteractor {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingDeleteMultipleMailboxAll());
|
||||
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(accountId);
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(session, accountId);
|
||||
|
||||
final listResult = await Future.wait(
|
||||
mapMailboxIdToDelete.keys.map((mailboxId) {
|
||||
|
||||
@@ -28,8 +28,8 @@ class MarkAsMailboxReadInteractor {
|
||||
onProgressController.add(Right(MarkAsMailboxReadLoading()));
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -15,7 +15,7 @@ class MoveMailboxInteractor {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingMoveMailbox());
|
||||
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(accountId);
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(session, accountId);
|
||||
final result = await _mailboxRepository.moveMailbox(session, accountId, request);
|
||||
if (result) {
|
||||
yield Right<Failure, Success>(MoveMailboxSuccess(
|
||||
|
||||
@@ -15,7 +15,7 @@ class RenameMailboxInteractor {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingRenameMailbox());
|
||||
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(accountId);
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(session, accountId);
|
||||
|
||||
final result = await _mailboxRepository.renameMailbox(session, accountId, request);
|
||||
if (result) {
|
||||
|
||||
@@ -16,7 +16,7 @@ class SubscribeMailboxInteractor {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingSubscribeMailbox());
|
||||
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(accountId);
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(session, accountId);
|
||||
|
||||
final result = await _mailboxRepository.subscribeMailbox(session, accountId, request);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class SubscribeMultipleMailboxInteractor {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingSubscribeMultipleMailbox());
|
||||
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(accountId);
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState(session, accountId);
|
||||
final listResult = await _mailboxRepository.subscribeMultipleMailbox(session, accountId, subscribeRequest);
|
||||
|
||||
final matchedSize = listResult.length == subscribeRequest.mailboxIdsSubscribe.length;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/spam_report_state.dart';
|
||||
@@ -28,5 +29,5 @@ abstract class SpamReportDataSource {
|
||||
|
||||
Future<void> deleteSpamReportState();
|
||||
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId);
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName);
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/spam_report_datasource.dart';
|
||||
@@ -70,7 +71,7 @@ class SharePreferenceSpamReportDataSourceImpl extends SpamReportDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,6 +2,7 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart';
|
||||
@@ -37,9 +38,9 @@ class SpamReportCacheDataSourceImpl extends SpamReportDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName) {
|
||||
return Future.sync(() async {
|
||||
return await _mailboxCacheManager.getSpamMailbox(accountId);
|
||||
return await _mailboxCacheManager.getSpamMailbox(accountId, userName);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/spam_report_datasource.dart';
|
||||
@@ -66,7 +67,7 @@ class SpamReportDataSourceImpl extends SpamReportDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -62,7 +63,7 @@ class SharePreferenceSpamReportDataSource extends SpamReportDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:core/data/model/source_type/data_source_type.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/spam_report_datasource.dart';
|
||||
@@ -61,7 +62,7 @@ class SpamReportRepositoryImpl extends SpamReportRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
return mapDataSource[DataSourceType.cache]!.getSpamMailboxCached(accountId);
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName) {
|
||||
return mapDataSource[DataSourceType.cache]!.getSpamMailboxCached(accountId, userName);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/spam_report_state.dart';
|
||||
@@ -28,5 +29,5 @@ abstract class SpamReportRepository {
|
||||
|
||||
Future<void> deleteSpamReportState();
|
||||
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId);
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName);
|
||||
}
|
||||
+3
-2
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/spam_report_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_number_of_unread_spam_emails_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_spam_mailbox_cached_state.dart';
|
||||
@@ -13,7 +14,7 @@ class GetSpamMailboxCachedInteractor {
|
||||
|
||||
GetSpamMailboxCachedInteractor(this._spamReportRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetSpamMailboxCachedLoading());
|
||||
|
||||
@@ -22,7 +23,7 @@ class GetSpamMailboxCachedInteractor {
|
||||
final checkTimeCondition = timeLast.inHours > MailboxDashboardConstant.spamReportBannerDisplayTimeOut;
|
||||
|
||||
if (checkTimeCondition) {
|
||||
final spamMailbox = await _spamReportRepository.getSpamMailboxCached(accountId);
|
||||
final spamMailbox = await _spamReportRepository.getSpamMailboxCached(accountId, userName);
|
||||
final countUnreadSpamMailbox = spamMailbox.unreadEmails?.value.value.toInt() ?? 0;
|
||||
if (countUnreadSpamMailbox > 0) {
|
||||
yield Right<Failure, Success>(GetSpamMailboxCachedSuccess(spamMailbox));
|
||||
|
||||
@@ -16,8 +16,8 @@ class RemoveEmailDraftsInteractor {
|
||||
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId, EmailId emailId) async* {
|
||||
try {
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
+13
-12
@@ -405,9 +405,10 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
log('MailboxDashBoardController::_getSessionCurrent(): arguments = $arguments');
|
||||
if (arguments is Session) {
|
||||
sessionCurrent = arguments;
|
||||
accountId.value = sessionCurrent?.accounts.keys.first;
|
||||
final personalAccount = sessionCurrent!.personalAccount;
|
||||
accountId.value = personalAccount.accountId;
|
||||
_getUserProfile();
|
||||
updateAuthenticationAccount(sessionCurrent!, accountId.value!);
|
||||
updateAuthenticationAccount(sessionCurrent!, accountId.value!, sessionCurrent!.username);
|
||||
injectAutoCompleteBindings(sessionCurrent, accountId.value);
|
||||
injectRuleFilterBindings(sessionCurrent, accountId.value);
|
||||
injectVacationBindings(sessionCurrent, accountId.value);
|
||||
@@ -1428,11 +1429,11 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
} catch (e) {
|
||||
logError('MailboxDashBoardController::_handleRefreshActionWhenBackToApp(): $e');
|
||||
}
|
||||
if (_getEmailStateToRefreshInteractor != null && accountId.value != null) {
|
||||
consumeState(_getEmailStateToRefreshInteractor!.execute(accountId.value!));
|
||||
if (_getEmailStateToRefreshInteractor != null && accountId.value != null && sessionCurrent != null) {
|
||||
consumeState(_getEmailStateToRefreshInteractor!.execute(accountId.value!, sessionCurrent!.username));
|
||||
}
|
||||
if (_getMailboxStateToRefreshInteractor != null && accountId.value != null) {
|
||||
consumeState(_getMailboxStateToRefreshInteractor!.execute(accountId.value!));
|
||||
if (_getMailboxStateToRefreshInteractor != null && accountId.value != null && sessionCurrent != null) {
|
||||
consumeState(_getMailboxStateToRefreshInteractor!.execute(accountId.value!, sessionCurrent!.username));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1443,8 +1444,8 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
} catch (e) {
|
||||
logError('MailboxDashBoardController::_deleteEmailStateToRefreshAction(): $e');
|
||||
}
|
||||
if (_deleteEmailStateToRefreshInteractor != null && accountId.value != null) {
|
||||
consumeState(_deleteEmailStateToRefreshInteractor!.execute(accountId.value!));
|
||||
if (_deleteEmailStateToRefreshInteractor != null && accountId.value != null && sessionCurrent != null) {
|
||||
consumeState(_deleteEmailStateToRefreshInteractor!.execute(accountId.value!, sessionCurrent!.username));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1455,8 +1456,8 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
} catch (e) {
|
||||
logError('MailboxDashBoardController::_deleteMailboxStateToRefreshAction(): $e');
|
||||
}
|
||||
if (_deleteMailboxStateToRefreshInteractor != null && accountId.value != null) {
|
||||
consumeState(_deleteMailboxStateToRefreshInteractor!.execute(accountId.value!));
|
||||
if (_deleteMailboxStateToRefreshInteractor != null && accountId.value != null && sessionCurrent != null) {
|
||||
consumeState(_deleteMailboxStateToRefreshInteractor!.execute(accountId.value!, sessionCurrent!.username));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1579,8 +1580,8 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
}
|
||||
|
||||
void refreshSpamReportBanner() {
|
||||
if (spamReportController.enableSpamReport && accountId.value != null) {
|
||||
spamReportController.getSpamMailboxCached(accountId.value!);
|
||||
if (spamReportController.enableSpamReport && sessionCurrent != null && accountId.value != null) {
|
||||
spamReportController.getSpamMailboxCached(accountId.value!, sessionCurrent!.username);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:model/extensions/mailbox_extension.dart';
|
||||
@@ -92,8 +93,8 @@ class SpamReportController extends BaseController {
|
||||
mailboxFilterCondition: MailboxFilterCondition(role: Role('Spam'))));
|
||||
}
|
||||
|
||||
void getSpamMailboxCached(AccountId accountId) {
|
||||
consumeState(_getSpamMailboxCachedInteractor.execute(accountId));
|
||||
void getSpamMailboxCached(AccountId accountId, UserName userName) {
|
||||
consumeState(_getSpamMailboxCachedInteractor.execute(accountId, userName));
|
||||
}
|
||||
|
||||
void _storeLastTimeDismissedSpamReportedAction() {
|
||||
|
||||
@@ -3,15 +3,16 @@ import 'package:fcm/model/firebase_subscription.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/model/fcm_subscription.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
|
||||
|
||||
abstract class FCMDatasource {
|
||||
Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState);
|
||||
Future<void> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState);
|
||||
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName);
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName);
|
||||
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName);
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName);
|
||||
|
||||
Future<void> storeSubscription(FCMSubscriptionCache fcmSubscriptionCache);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:fcm/model/firebase_subscription.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/model/fcm_subscription.dart';
|
||||
@@ -16,23 +17,23 @@ class CacheFCMDatasourceImpl extends FCMDatasource {
|
||||
CacheFCMDatasourceImpl(this._firebaseCacheManager, this._exceptionThrower);
|
||||
|
||||
@override
|
||||
Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
|
||||
Future<void> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.storeStateToRefresh(accountId, typeName, newState);
|
||||
return await _firebaseCacheManager.storeStateToRefresh(accountId, userName, typeName, newState);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId,UserName userName, TypeName typeName) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.getStateToRefresh(accountId, typeName);
|
||||
return await _firebaseCacheManager.getStateToRefresh(accountId, userName, typeName);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.deleteStateToRefresh(accountId, typeName);
|
||||
return await _firebaseCacheManager.deleteStateToRefresh(accountId, userName, typeName);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:fcm/model/firebase_subscription.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/model/fcm_subscription.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/network/fcm_api.dart';
|
||||
@@ -24,17 +25,17 @@ class FcmDatasourceImpl extends FCMDatasource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
Future<bool> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
|
||||
Future<bool> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:fcm/model/type_name.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/fcm_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/subscription_cache_client.dart';
|
||||
@@ -14,13 +15,13 @@ class FCMCacheManager {
|
||||
|
||||
FCMCacheManager(this._fcmCacheClient,this._fcmSubscriptionCacheClient);
|
||||
|
||||
Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString();
|
||||
Future<void> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState) {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString, userName.value).encodeKey;
|
||||
return _fcmCacheClient.insertItem(stateKeyCache, newState.value);
|
||||
}
|
||||
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) async {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString();
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) async {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString, userName.value).encodeKey;
|
||||
final stateValue = await _fcmCacheClient.getItem(stateKeyCache);
|
||||
if (stateValue != null) {
|
||||
return jmap.State(stateValue);
|
||||
@@ -33,8 +34,8 @@ class FCMCacheManager {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString();
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString, userName.value).encodeKey;
|
||||
return _fcmCacheClient.deleteItem(stateKeyCache);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:model/extensions/list_email_extension.dart';
|
||||
@@ -75,18 +76,18 @@ class FCMRepositoryImpl extends FCMRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
|
||||
return _fcmDatasource[DataSourceType.local]!.storeStateToRefresh(accountId, typeName, newState);
|
||||
Future<void> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState) {
|
||||
return _fcmDatasource[DataSourceType.local]!.storeStateToRefresh(accountId, userName, typeName, newState);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
return _fcmDatasource[DataSourceType.local]!.getStateToRefresh(accountId, typeName);
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
return _fcmDatasource[DataSourceType.local]!.getStateToRefresh(accountId, userName, typeName);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
return _fcmDatasource[DataSourceType.local]!.deleteStateToRefresh(accountId, typeName);
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
return _fcmDatasource[DataSourceType.local]!.deleteStateToRefresh(accountId, userName, typeName);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -117,7 +118,7 @@ class FCMRepositoryImpl extends FCMRepository {
|
||||
|
||||
@override
|
||||
Future<List<PresentationMailbox>> getMailboxesNotPutNotifications(Session session, AccountId accountId) async {
|
||||
final mailboxesCache = await _mapMailboxDataSource[DataSourceType.local]!.getAllMailboxCache(accountId);
|
||||
final mailboxesCache = await _mapMailboxDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username);
|
||||
final mailboxesCacheNotPutNotifications = mailboxesCache
|
||||
.map((mailbox) => mailbox.toPresentationMailbox())
|
||||
.where((presentationMailbox) => presentationMailbox.pushNotificationDeactivated)
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/fcm_subscription.dart';
|
||||
@@ -21,11 +22,11 @@ abstract class FCMRepository {
|
||||
}
|
||||
);
|
||||
|
||||
Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState);
|
||||
Future<void> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState);
|
||||
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName);
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName);
|
||||
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName);
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName);
|
||||
|
||||
Future<void> storeSubscription(FCMSubscription fcmSubscription);
|
||||
|
||||
|
||||
+4
-2
@@ -2,6 +2,7 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
|
||||
class GetEmailChangesToPushNotificationLoading extends UIState {}
|
||||
@@ -10,11 +11,12 @@ class GetEmailChangesToPushNotificationSuccess extends UIState {
|
||||
|
||||
final List<PresentationEmail> emailList;
|
||||
final AccountId accountId;
|
||||
final UserName userName;
|
||||
|
||||
GetEmailChangesToPushNotificationSuccess(this.accountId, this.emailList);
|
||||
GetEmailChangesToPushNotificationSuccess(this.accountId, this.userName, this.emailList);
|
||||
|
||||
@override
|
||||
List<Object> get props => [accountId, emailList];
|
||||
List<Object> get props => [accountId, userName, emailList];
|
||||
}
|
||||
|
||||
class GetEmailChangesToPushNotificationFailure extends FeatureFailure {
|
||||
|
||||
+3
-2
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/delete_email_state_to_refresh_state.dart';
|
||||
|
||||
@@ -11,10 +12,10 @@ class DeleteEmailStateToRefreshInteractor {
|
||||
|
||||
DeleteEmailStateToRefreshInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(DeleteEmailStateToRefreshLoading());
|
||||
await _fcmRepository.deleteStateToRefresh(accountId, TypeName.emailType);
|
||||
await _fcmRepository.deleteStateToRefresh(accountId, userName, TypeName.emailType);
|
||||
yield Right<Failure, Success>(DeleteEmailStateToRefreshSuccess());
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(DeleteEmailStateToRefreshFailure(e));
|
||||
|
||||
+3
-2
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/delete_mailbox_state_to_refresh_state.dart';
|
||||
|
||||
@@ -11,10 +12,10 @@ class DeleteMailboxStateToRefreshInteractor {
|
||||
|
||||
DeleteMailboxStateToRefreshInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(DeleteMailboxStateToRefreshLoading());
|
||||
await _fcmRepository.deleteStateToRefresh(accountId, TypeName.mailboxType);
|
||||
await _fcmRepository.deleteStateToRefresh(accountId, userName, TypeName.mailboxType);
|
||||
yield Right<Failure, Success>(DeleteMailboxStateToRefreshSuccess());
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(DeleteMailboxStateToRefreshFailure(e));
|
||||
|
||||
+3
-1
@@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/extensions/email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_changes_to_push_notification_state.dart';
|
||||
@@ -17,6 +18,7 @@ class GetEmailChangesToPushNotificationInteractor {
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
jmap.State currentState,
|
||||
{
|
||||
Properties? propertiesCreated,
|
||||
@@ -37,7 +39,7 @@ class GetEmailChangesToPushNotificationInteractor {
|
||||
?.map((email) => email.toPresentationEmail())
|
||||
.toList() ?? List.empty();
|
||||
|
||||
yield Right<Failure, Success>(GetEmailChangesToPushNotificationSuccess(accountId, presentationEmailList));
|
||||
yield Right<Failure, Success>(GetEmailChangesToPushNotificationSuccess(accountId, userName, presentationEmailList));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetEmailChangesToPushNotificationFailure(e));
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ class GetEmailChangesToRemoveNotificationInteractor {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetEmailChangesToRemoveNotificationLoading());
|
||||
|
||||
final currentState = await _emailRepository.getEmailState(accountId);
|
||||
final currentState = await _emailRepository.getEmailState(session, accountId);
|
||||
log('GetEmailChangesToRemoveNotificationInteractor::execute():currentState: $currentState');
|
||||
if (currentState != null) {
|
||||
final emailIds = await _fcmRepository.getEmailChangesToRemoveNotification(
|
||||
|
||||
+3
-2
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_state_to_refresh_state.dart';
|
||||
|
||||
@@ -11,10 +12,10 @@ class GetEmailStateToRefreshInteractor {
|
||||
|
||||
GetEmailStateToRefreshInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetEmailStateToRefreshLoading());
|
||||
final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.emailType);
|
||||
final storedState = await _fcmRepository.getStateToRefresh(accountId, userName, TypeName.emailType);
|
||||
yield Right<Failure, Success>(GetEmailStateToRefreshSuccess(storedState));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetEmailStateToRefreshFailure(e));
|
||||
|
||||
+3
-2
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/get_mailbox_state_to_refresh_state.dart';
|
||||
|
||||
@@ -11,10 +12,10 @@ class GetMailboxStateToRefreshInteractor {
|
||||
|
||||
GetMailboxStateToRefreshInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetMailboxStateToRefreshLoading());
|
||||
final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.mailboxType);
|
||||
final storedState = await _fcmRepository.getStateToRefresh(accountId, userName, TypeName.mailboxType);
|
||||
yield Right<Failure, Success>(GetMailboxStateToRefreshSuccess(storedState));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetMailboxStateToRefreshFailure(e));
|
||||
|
||||
+3
-2
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/get_stored_email_delivery_state.dart';
|
||||
|
||||
@@ -11,10 +12,10 @@ class GetStoredEmailDeliveryStateInteractor {
|
||||
|
||||
GetStoredEmailDeliveryStateInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetStoredEmailDeliveryStateLoading());
|
||||
final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.emailDelivery);
|
||||
final storedState = await _fcmRepository.getStateToRefresh(accountId, userName, TypeName.emailDelivery);
|
||||
yield Right<Failure, Success>(GetStoredEmailDeliveryStateSuccess(storedState));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetStoredEmailDeliveryStateFailure(e));
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/store_email_delivery_state.dart';
|
||||
|
||||
@@ -12,10 +13,10 @@ class StoreEmailDeliveryStateInteractor {
|
||||
|
||||
StoreEmailDeliveryStateInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, jmap.State newState) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName, jmap.State newState) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StoreEmailDeliveryStateLoading());
|
||||
await _fcmRepository.storeStateToRefresh(accountId, TypeName.emailDelivery, newState);
|
||||
await _fcmRepository.storeStateToRefresh(accountId, userName, TypeName.emailDelivery, newState);
|
||||
yield Right<Failure, Success>(StoreEmailDeliveryStateSuccess());
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(StoreEmailDeliveryStateFailure(e));
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/store_email_state_to_refresh_state.dart';
|
||||
|
||||
@@ -12,10 +13,10 @@ class StoreEmailStateToRefreshInteractor {
|
||||
|
||||
StoreEmailStateToRefreshInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, jmap.State newState) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName, jmap.State newState) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StoreEmailStateToRefreshLoading());
|
||||
await _fcmRepository.storeStateToRefresh(accountId, TypeName.emailType, newState);
|
||||
await _fcmRepository.storeStateToRefresh(accountId, userName, TypeName.emailType, newState);
|
||||
yield Right<Failure, Success>(StoreEmailStateToRefreshSuccess());
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(StoreEmailStateToRefreshFailure(e));
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/store_mailbox_state_to_refresh_state.dart';
|
||||
|
||||
@@ -12,10 +13,10 @@ class StoreMailboxStateToRefreshInteractor {
|
||||
|
||||
StoreMailboxStateToRefreshInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, jmap.State newState) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName, jmap.State newState) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StoreMailboxStateToRefreshLoading());
|
||||
await _fcmRepository.storeStateToRefresh(accountId, TypeName.mailboxType, newState);
|
||||
await _fcmRepository.storeStateToRefresh(accountId, userName, TypeName.mailboxType, newState);
|
||||
yield Right<Failure, Success>(StoreMailboxStateToRefreshSuccess());
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(StoreMailboxStateToRefreshFailure(e));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/base/action/ui_action.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
|
||||
@@ -25,27 +26,31 @@ class PushNotificationAction extends FcmStateChangeAction {
|
||||
|
||||
final Session? session;
|
||||
final AccountId accountId;
|
||||
final UserName userName;
|
||||
|
||||
PushNotificationAction(
|
||||
TypeName typeName,
|
||||
jmap.State newState,
|
||||
this.session,
|
||||
this.accountId
|
||||
this.accountId,
|
||||
this.userName
|
||||
) : super(typeName, newState);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [typeName, newState, accountId, session];
|
||||
List<Object?> get props => [typeName, newState, accountId, session, userName];
|
||||
}
|
||||
|
||||
class StoreEmailStateToRefreshAction extends FcmStateChangeAction {
|
||||
|
||||
final AccountId accountId;
|
||||
final UserName userName;
|
||||
final Session? session;
|
||||
|
||||
StoreEmailStateToRefreshAction(
|
||||
TypeName typeName,
|
||||
jmap.State newState,
|
||||
this.accountId,
|
||||
this.userName,
|
||||
this.session
|
||||
) : super(typeName, newState);
|
||||
|
||||
@@ -70,13 +75,15 @@ class SynchronizeMailboxOnForegroundAction extends FcmStateChangeAction {
|
||||
class StoreMailboxStateToRefreshAction extends FcmStateChangeAction {
|
||||
|
||||
final AccountId accountId;
|
||||
final UserName userName;
|
||||
|
||||
StoreMailboxStateToRefreshAction(
|
||||
TypeName typeName,
|
||||
jmap.State newState,
|
||||
this.accountId
|
||||
this.accountId,
|
||||
this.userName
|
||||
) : super(typeName, newState);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [typeName, newState, accountId];
|
||||
List<Object?> get props => [typeName, newState, accountId, userName];
|
||||
}
|
||||
+19
-12
@@ -12,6 +12,7 @@ import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/push/state_change.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
@@ -42,6 +43,7 @@ class FcmMessageController extends FcmBaseController {
|
||||
|
||||
AccountId? _currentAccountId;
|
||||
Session? _currentSession;
|
||||
UserName? _userName;
|
||||
RemoteMessage? _remoteMessageBackground;
|
||||
|
||||
GetAuthenticatedAccountInteractor? _getAuthenticatedAccountInteractor;
|
||||
@@ -60,6 +62,7 @@ class FcmMessageController extends FcmBaseController {
|
||||
void initializeFromAccountId(AccountId accountId, Session session) {
|
||||
_currentAccountId = accountId;
|
||||
_currentSession = session;
|
||||
_userName = session.username;
|
||||
FcmTokenController.instance.initialize();
|
||||
}
|
||||
|
||||
@@ -96,10 +99,10 @@ class FcmMessageController extends FcmBaseController {
|
||||
|
||||
void _handleForegroundMessageAction(RemoteMessage newRemoteMessage) {
|
||||
log('FcmMessageController::_handleForegroundMessageAction():remoteMessage: ${newRemoteMessage.data} | _currentAccountId: $_currentAccountId');
|
||||
if (_currentAccountId != null) {
|
||||
if (_currentAccountId != null && _userName != null) {
|
||||
final stateChange = _convertRemoteMessageToStateChange(newRemoteMessage);
|
||||
final mapTypeState = stateChange.getMapTypeState(_currentAccountId!);
|
||||
_mappingTypeStateToAction(mapTypeState, _currentAccountId!, session: _currentSession);
|
||||
_mappingTypeStateToAction(mapTypeState, _currentAccountId!, _userName!, session: _currentSession);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +119,8 @@ class FcmMessageController extends FcmBaseController {
|
||||
|
||||
void _mappingTypeStateToAction(
|
||||
Map<String, dynamic> mapTypeState,
|
||||
AccountId accountId, {
|
||||
AccountId accountId,
|
||||
UserName userName, {
|
||||
bool isForeground = true,
|
||||
Session? session
|
||||
}) {
|
||||
@@ -127,7 +131,7 @@ class FcmMessageController extends FcmBaseController {
|
||||
|
||||
final listEmailActions = listTypeName
|
||||
.where((typeName) => typeName == TypeName.emailType || typeName == TypeName.emailDelivery)
|
||||
.map((typeName) => toFcmAction(typeName, accountId, mapTypeState, isForeground, session: session))
|
||||
.map((typeName) => toFcmAction(typeName, accountId, userName, mapTypeState, isForeground, session: session))
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
|
||||
@@ -139,7 +143,7 @@ class FcmMessageController extends FcmBaseController {
|
||||
|
||||
final listMailboxActions = listTypeName
|
||||
.where((typeName) => typeName == TypeName.mailboxType)
|
||||
.map((typeName) => toFcmAction(typeName, accountId, mapTypeState, isForeground))
|
||||
.map((typeName) => toFcmAction(typeName, accountId, userName, mapTypeState, isForeground))
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
|
||||
@@ -153,6 +157,7 @@ class FcmMessageController extends FcmBaseController {
|
||||
FcmAction? toFcmAction(
|
||||
TypeName typeName,
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
Map<String, dynamic> mapTypeState,
|
||||
isForeground,
|
||||
{
|
||||
@@ -164,17 +169,17 @@ class FcmMessageController extends FcmBaseController {
|
||||
if (isForeground) {
|
||||
return SynchronizeEmailOnForegroundAction(typeName, newState, accountId, session);
|
||||
} else {
|
||||
return StoreEmailStateToRefreshAction(typeName, newState, accountId, session);
|
||||
return StoreEmailStateToRefreshAction(typeName, newState, accountId, userName, session);
|
||||
}
|
||||
} else if (typeName == TypeName.emailDelivery) {
|
||||
if (!isForeground) {
|
||||
return PushNotificationAction(typeName, newState, session, accountId);
|
||||
return PushNotificationAction(typeName, newState, session, accountId, userName);
|
||||
}
|
||||
} else if (typeName == TypeName.mailboxType) {
|
||||
if (isForeground) {
|
||||
return SynchronizeMailboxOnForegroundAction(typeName, newState, accountId);
|
||||
} else {
|
||||
return StoreMailboxStateToRefreshAction(typeName, newState, accountId);
|
||||
return StoreMailboxStateToRefreshAction(typeName, newState, accountId, userName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -219,10 +224,11 @@ class FcmMessageController extends FcmBaseController {
|
||||
|
||||
void _handleGetAuthenticatedAccountSuccess(GetAuthenticatedAccountSuccess success) {
|
||||
_currentAccountId = success.account.accountId;
|
||||
_userName = success.account.userName;
|
||||
if (!FcmUtils.instance.isMobileAndroid) {
|
||||
_dynamicUrlInterceptors?.changeBaseUrl(success.account.apiUrl);
|
||||
}
|
||||
log('FcmMessageController::_handleGetAuthenticatedAccountSuccess():_currentAccountId: $_currentAccountId');
|
||||
log('FcmMessageController::_handleGetAuthenticatedAccountSuccess():_currentAccountId: $_currentAccountId | _userName: $_userName');
|
||||
}
|
||||
|
||||
void _handleGetAccountByOidcSuccess(GetStoredTokenOidcSuccess storedTokenOidcSuccess) {
|
||||
@@ -245,7 +251,7 @@ class FcmMessageController extends FcmBaseController {
|
||||
log('FcmMessageController::_handleGetAccountByBasicAuthSuccess():');
|
||||
_dynamicUrlInterceptors?.setJmapUrl(credentialViewState.baseUrl.toString());
|
||||
_authorizationInterceptors?.setBasicAuthorization(
|
||||
credentialViewState.userName.userName,
|
||||
credentialViewState.userName.value,
|
||||
credentialViewState.password.value,
|
||||
);
|
||||
if (FcmUtils.instance.isMobileAndroid) {
|
||||
@@ -267,6 +273,7 @@ class FcmMessageController extends FcmBaseController {
|
||||
|
||||
void _handleGetSessionSuccess(GetSessionSuccess success) {
|
||||
_currentSession = success.session;
|
||||
_userName = success.session.username;
|
||||
final jmapUrl = _dynamicUrlInterceptors?.jmapUrl;
|
||||
final apiUrl = jmapUrl != null
|
||||
? success.session.apiUrl.toQualifiedUrl(baseUrl: Uri.parse(jmapUrl)).toString()
|
||||
@@ -283,10 +290,10 @@ class FcmMessageController extends FcmBaseController {
|
||||
|
||||
void _pushActionFromRemoteMessageBackground() {
|
||||
log('FcmMessageController::_pushActionFromRemoteMessageBackground():_remoteMessageBackground: $_remoteMessageBackground | _currentAccountId: $_currentAccountId | _currentSession: $_currentSession');
|
||||
if (_remoteMessageBackground != null && _currentAccountId != null) {
|
||||
if (_remoteMessageBackground != null && _currentAccountId != null && _userName != null) {
|
||||
final stateChange = _convertRemoteMessageToStateChange(_remoteMessageBackground!);
|
||||
final mapTypeState = stateChange.getMapTypeState(_currentAccountId!);
|
||||
_mappingTypeStateToAction(mapTypeState, _currentAccountId!, isForeground: false, session: _currentSession);
|
||||
_mappingTypeStateToAction(mapTypeState, _currentAccountId!, _userName!, isForeground: false, session: _currentSession);
|
||||
}
|
||||
_clearRemoteMessageBackground();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/email/email_property.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
@@ -54,6 +55,7 @@ class EmailChangeListener extends ChangeListener {
|
||||
jmap.State? _newStateEmailDelivery;
|
||||
AccountId? _accountId;
|
||||
Session? _session;
|
||||
UserName? _userName;
|
||||
List<PresentationEmail> _emailsAvailablePushNotification = [];
|
||||
|
||||
EmailChangeListener._internal() {
|
||||
@@ -85,12 +87,12 @@ class EmailChangeListener extends ChangeListener {
|
||||
}
|
||||
_synchronizeEmailOnForegroundAction(action.newState);
|
||||
} else if (action is PushNotificationAction) {
|
||||
_pushNotificationAction(action.newState, action.accountId, action.session);
|
||||
_pushNotificationAction(action.newState, action.accountId, action.userName, action.session);
|
||||
} else if (action is StoreEmailStateToRefreshAction) {
|
||||
if (FcmUtils.instance.isMobileAndroid) {
|
||||
_handleRemoveNotificationWhenEmailMarkAsRead(action.newState, action.accountId, action.session);
|
||||
}
|
||||
_handleStoreEmailStateToRefreshAction(action.accountId, action.newState);
|
||||
_handleStoreEmailStateToRefreshAction(action.accountId, action.userName, action.newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,19 +104,20 @@ class EmailChangeListener extends ChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
void _pushNotificationAction(jmap.State newState, AccountId accountId, Session? session) {
|
||||
void _pushNotificationAction(jmap.State newState, AccountId accountId, UserName userName, Session? session) {
|
||||
_newStateEmailDelivery = newState;
|
||||
_accountId = accountId;
|
||||
_session = session;
|
||||
_userName = userName;
|
||||
log('EmailChangeListener::_pushNotificationAction():newState: $newState');
|
||||
|
||||
if (BuildUtils.isWeb) {
|
||||
_storeEmailDeliveryStateAction(accountId, _newStateEmailDelivery!);
|
||||
_storeEmailDeliveryStateAction(accountId, userName, _newStateEmailDelivery!);
|
||||
} else {
|
||||
if (Platform.isAndroid) {
|
||||
_getStoredEmailDeliveryState(accountId);
|
||||
_getStoredEmailDeliveryState(accountId, userName);
|
||||
} else if (Platform.isIOS) {
|
||||
_storeEmailDeliveryStateAction(accountId, _newStateEmailDelivery!);
|
||||
_storeEmailDeliveryStateAction(accountId, userName, _newStateEmailDelivery!);
|
||||
_showLocalNotificationForIOS(_newStateEmailDelivery!, accountId);
|
||||
} else {
|
||||
logError('EmailChangeListener::_pushNotificationAction(): NOT SUPPORTED PLATFORM');
|
||||
@@ -122,25 +125,29 @@ class EmailChangeListener extends ChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
void _getStoredEmailDeliveryState(AccountId accountId) {
|
||||
void _getStoredEmailDeliveryState(AccountId accountId, UserName userName) {
|
||||
if (_getStoredEmailDeliveryStateInteractor != null) {
|
||||
consumeState(_getStoredEmailDeliveryStateInteractor!.execute(accountId));
|
||||
consumeState(_getStoredEmailDeliveryStateInteractor!.execute(accountId, userName));
|
||||
}
|
||||
}
|
||||
|
||||
void _getStoredEmailState() {
|
||||
if (_getStoredEmailStateInteractor != null && _accountId != null) {
|
||||
consumeState(_getStoredEmailStateInteractor!.execute(_accountId!));
|
||||
if (_getStoredEmailStateInteractor != null && _session != null && _accountId != null) {
|
||||
consumeState(_getStoredEmailStateInteractor!.execute(_session!, _accountId!));
|
||||
} else {
|
||||
logError('EmailChangeListener::_getStoredEmailState(): _getStoredEmailStateInteractor is null');
|
||||
}
|
||||
}
|
||||
|
||||
void _getEmailChangesAction(jmap.State state) {
|
||||
if (_getEmailChangesToPushNotificationInteractor != null && _accountId != null && _session != null) {
|
||||
if (_getEmailChangesToPushNotificationInteractor != null &&
|
||||
_accountId != null &&
|
||||
_session != null &&
|
||||
_userName != null) {
|
||||
consumeState(_getEmailChangesToPushNotificationInteractor!.execute(
|
||||
_session!,
|
||||
_accountId!,
|
||||
_userName!,
|
||||
state,
|
||||
propertiesCreated: ThreadConstants.propertiesDefault,
|
||||
propertiesUpdated: ThreadConstants.propertiesUpdatedDefault,
|
||||
@@ -148,9 +155,9 @@ class EmailChangeListener extends ChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
void _storeEmailDeliveryStateAction(AccountId accountId, jmap.State state) {
|
||||
void _storeEmailDeliveryStateAction(AccountId accountId, UserName userName, jmap.State state) {
|
||||
if (_storeEmailDeliveryStateInteractor != null) {
|
||||
consumeState(_storeEmailDeliveryStateInteractor!.execute(accountId, state));
|
||||
consumeState(_storeEmailDeliveryStateInteractor!.execute(accountId, userName, state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +211,7 @@ class EmailChangeListener extends ChangeListener {
|
||||
_getEmailChangesAction(success.state);
|
||||
} else if (success is GetEmailChangesToPushNotificationSuccess) {
|
||||
if (_newStateEmailDelivery != null) {
|
||||
_storeEmailDeliveryStateAction(success.accountId, _newStateEmailDelivery!);
|
||||
_storeEmailDeliveryStateAction(success.accountId, success.userName, _newStateEmailDelivery!);
|
||||
|
||||
if (FcmUtils.instance.isMobileAndroid) {
|
||||
_handleListEmailToPushNotification(success.emailList);
|
||||
@@ -244,10 +251,10 @@ class EmailChangeListener extends ChangeListener {
|
||||
_emailsAvailablePushNotification.clear();
|
||||
}
|
||||
|
||||
void _handleStoreEmailStateToRefreshAction(AccountId accountId, jmap.State newState) {
|
||||
void _handleStoreEmailStateToRefreshAction(AccountId accountId, UserName userName, jmap.State newState) {
|
||||
log('EmailChangeListener::_handleStoreEmailStateToRefreshAction():newState: $newState');
|
||||
if (_storeEmailStateToRefreshInteractor != null) {
|
||||
consumeState(_storeEmailStateToRefreshInteractor!.execute(accountId, newState));
|
||||
consumeState(_storeEmailStateToRefreshInteractor!.execute(accountId, userName, newState));
|
||||
} else {
|
||||
logError('EmailChangeListener::_handleStoreEmailStateToRefreshAction():_storeEmailStateToRefreshInteractor is null');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/base/action/ui_action.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/action/mailbox_ui_action.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
@@ -37,7 +38,7 @@ class MailboxChangeListener extends ChangeListener {
|
||||
if (action is SynchronizeMailboxOnForegroundAction) {
|
||||
_synchronizeMailboxOnForegroundAction(action.newState);
|
||||
} else if (action is StoreMailboxStateToRefreshAction) {
|
||||
_handleStoreMailboxStateToRefreshAction(action.accountId, action.newState);
|
||||
_handleStoreMailboxStateToRefreshAction(action.accountId, action.userName, action.newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,10 +60,10 @@ class MailboxChangeListener extends ChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
void _handleStoreMailboxStateToRefreshAction(AccountId accountId, jmap.State newState) {
|
||||
void _handleStoreMailboxStateToRefreshAction(AccountId accountId, UserName userName, jmap.State newState) {
|
||||
log('MailboxChangeListener::_handleStoreMailboxStateToRefreshAction():newState: $newState');
|
||||
if (_storeMailboxStateToRefreshInteractor != null) {
|
||||
consumeState(_storeMailboxStateToRefreshInteractor!.execute(accountId, newState));
|
||||
consumeState(_storeMailboxStateToRefreshInteractor!.execute(accountId, userName, newState));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
@@ -36,9 +37,18 @@ abstract class ThreadDataSource {
|
||||
}
|
||||
);
|
||||
|
||||
Future<List<Email>> getAllEmailCache(AccountId accountId, {MailboxId? inMailboxId, Set<Comparator>? sort, FilterMessageOption? filterOption, UnsignedInt? limit});
|
||||
Future<List<Email>> getAllEmailCache(
|
||||
AccountId accountId,
|
||||
UserName userName,
|
||||
{
|
||||
MailboxId? inMailboxId,
|
||||
Set<Comparator>? sort,
|
||||
FilterMessageOption? filterOption,
|
||||
UnsignedInt? limit
|
||||
}
|
||||
);
|
||||
|
||||
Future<void> update(AccountId accountId, {List<Email>? updated, List<Email>? created, List<EmailId>? destroyed});
|
||||
Future<void> update(AccountId accountId, UserName userName, {List<Email>? updated, List<Email>? created, List<EmailId>? destroyed});
|
||||
|
||||
Future<List<EmailId>> emptyTrashFolder(
|
||||
Session session,
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
@@ -53,7 +54,8 @@ class LocalThreadDataSourceImpl extends ThreadDataSource {
|
||||
|
||||
@override
|
||||
Future<List<Email>> getAllEmailCache(
|
||||
AccountId accountId, {
|
||||
AccountId accountId,
|
||||
UserName userName, {
|
||||
MailboxId? inMailboxId,
|
||||
Set<Comparator>? sort,
|
||||
FilterMessageOption? filterOption,
|
||||
@@ -62,6 +64,7 @@ class LocalThreadDataSourceImpl extends ThreadDataSource {
|
||||
return Future.sync(() async {
|
||||
return await _emailCacheManager.getAllEmail(
|
||||
accountId,
|
||||
userName,
|
||||
inMailboxId: inMailboxId,
|
||||
sort: sort,
|
||||
filterOption: filterOption ?? FilterMessageOption.all,
|
||||
@@ -71,7 +74,8 @@ class LocalThreadDataSourceImpl extends ThreadDataSource {
|
||||
|
||||
@override
|
||||
Future<void> update(
|
||||
AccountId accountId, {
|
||||
AccountId accountId,
|
||||
UserName userName, {
|
||||
List<Email>? updated,
|
||||
List<Email>? created,
|
||||
List<EmailId>? destroyed
|
||||
@@ -79,6 +83,7 @@ class LocalThreadDataSourceImpl extends ThreadDataSource {
|
||||
return Future.sync(() async {
|
||||
return await _emailCacheManager.update(
|
||||
accountId,
|
||||
userName,
|
||||
updated: updated,
|
||||
created: created,
|
||||
destroyed: destroyed);
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
@@ -74,12 +75,12 @@ class ThreadDataSourceImpl extends ThreadDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Email>> getAllEmailCache(AccountId accountId, {MailboxId? inMailboxId, Set<Comparator>? sort, FilterMessageOption? filterOption, UnsignedInt? limit}) {
|
||||
Future<List<Email>> getAllEmailCache(AccountId accountId, UserName userName, {MailboxId? inMailboxId, Set<Comparator>? sort, FilterMessageOption? filterOption, UnsignedInt? limit}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> update(AccountId accountId, {List<Email>? updated, List<Email>? created, List<EmailId>? destroyed}) {
|
||||
Future<void> update(AccountId accountId, UserName userName, {List<Email>? updated, List<Email>? created, List<EmailId>? destroyed}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
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/email/email.dart';
|
||||
import 'package:model/extensions/account_id_extensions.dart';
|
||||
import 'package:model/extensions/email_id_extensions.dart';
|
||||
@@ -8,10 +9,10 @@ import 'package:tmail_ui_user/features/thread/data/extensions/email_extension.da
|
||||
import 'package:tmail_ui_user/features/thread/data/model/email_cache.dart';
|
||||
|
||||
extension ListEmailExtension on List<Email> {
|
||||
Map<String, EmailCache> toMapCache(AccountId accountId) {
|
||||
Map<String, EmailCache> toMapCache(AccountId accountId, UserName userName) {
|
||||
return {
|
||||
for (var email in this)
|
||||
TupleKey(email.id!.asString, accountId.asString).toString() : email.toEmailCache()
|
||||
TupleKey(email.id!.asString, accountId.asString, userName.value).encodeKey : email.toEmailCache()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
|
||||
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/email/email.dart';
|
||||
import 'package:model/extensions/account_id_extensions.dart';
|
||||
import 'package:model/extensions/email_id_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
||||
|
||||
extension ListEmailIdExtension on List<EmailId> {
|
||||
List<String> toCacheKeyList(AccountId accountId) => map((id) => TupleKey(id.asString, accountId.asString).toString()).toList();
|
||||
List<String> toCacheKeyList(AccountId accountId, UserName userName) =>
|
||||
map((id) => TupleKey(id.asString, accountId.asString, userName.value).encodeKey).toList();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
@@ -20,13 +21,14 @@ class EmailCacheManager {
|
||||
EmailCacheManager(this._emailCacheClient);
|
||||
|
||||
Future<List<Email>> getAllEmail(
|
||||
AccountId accountId, {
|
||||
AccountId accountId,
|
||||
UserName userName, {
|
||||
MailboxId? inMailboxId,
|
||||
Set<Comparator>? sort,
|
||||
UnsignedInt? limit,
|
||||
FilterMessageOption filterOption = FilterMessageOption.all
|
||||
}) async {
|
||||
final emailCacheList = await _emailCacheClient.getListByCollectionId(accountId.asString);
|
||||
final emailCacheList = await _emailCacheClient.getListByTupleKey(accountId.asString, userName.value);
|
||||
final emailList = emailCacheList
|
||||
.toEmailList()
|
||||
.where((email) => _filterEmailByMailbox(email, filterOption, inMailboxId))
|
||||
@@ -53,16 +55,17 @@ class EmailCacheManager {
|
||||
}
|
||||
|
||||
Future<void> update(
|
||||
AccountId accountId, {
|
||||
AccountId accountId,
|
||||
UserName userName, {
|
||||
List<Email>? updated,
|
||||
List<Email>? created,
|
||||
List<EmailId>? destroyed
|
||||
}) async {
|
||||
final emailCacheExist = await _emailCacheClient.isExistTable();
|
||||
if (emailCacheExist) {
|
||||
final updatedCacheEmails = updated?.toMapCache(accountId) ?? {};
|
||||
final createdCacheEmails = created?.toMapCache(accountId) ?? {};
|
||||
final destroyedCacheEmails = destroyed?.toCacheKeyList(accountId) ?? [];
|
||||
final updatedCacheEmails = updated?.toMapCache(accountId, userName) ?? {};
|
||||
final createdCacheEmails = created?.toMapCache(accountId, userName) ?? {};
|
||||
final destroyedCacheEmails = destroyed?.toCacheKeyList(accountId, userName) ?? [];
|
||||
|
||||
await Future.wait([
|
||||
_emailCacheClient.updateMultipleItem(updatedCacheEmails),
|
||||
@@ -70,7 +73,7 @@ class EmailCacheManager {
|
||||
_emailCacheClient.deleteMultipleItem(destroyedCacheEmails)
|
||||
]);
|
||||
} else {
|
||||
final createdCacheEmails = created?.toMapCache(accountId) ?? {};
|
||||
final createdCacheEmails = created?.toMapCache(accountId, userName) ?? {};
|
||||
await _emailCacheClient.insertMultipleItem(createdCacheEmails);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_filter_condition.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
@@ -46,12 +47,13 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
log('ThreadRepositoryImpl::getAllEmail(): filter = ${emailFilter?.mailboxId}');
|
||||
final localEmailResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllEmailCache(
|
||||
accountId,
|
||||
inMailboxId: emailFilter?.mailboxId,
|
||||
sort: sort,
|
||||
limit: limit,
|
||||
filterOption: emailFilter?.filterOption),
|
||||
stateDataSource.getState(accountId, StateType.email)
|
||||
accountId,
|
||||
session.username,
|
||||
inMailboxId: emailFilter?.mailboxId,
|
||||
sort: sort,
|
||||
limit: limit,
|
||||
filterOption: emailFilter?.filterOption),
|
||||
stateDataSource.getState(accountId, session.username, StateType.email)
|
||||
]).then((List response) {
|
||||
return EmailsResponse(emailList: response.first, state: response.last);
|
||||
});
|
||||
@@ -82,7 +84,7 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
}
|
||||
|
||||
if (networkEmailResponse != null) {
|
||||
await _updateEmailCache(accountId, newCreated: networkEmailResponse.emailList);
|
||||
await _updateEmailCache(accountId, session.username, newCreated: networkEmailResponse.emailList);
|
||||
}
|
||||
|
||||
if (localEmailResponse.hasState()) {
|
||||
@@ -98,7 +100,7 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
if (networkEmailResponse != null) {
|
||||
log('ThreadRepositoryImpl::getAllEmail(): filter = ${emailFilter?.mailboxId} no local state -> update from network: ${networkEmailResponse.state}');
|
||||
if (networkEmailResponse.state != null) {
|
||||
await _updateState(accountId, networkEmailResponse.state!);
|
||||
await _updateState(accountId, session.username, networkEmailResponse.state!);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,11 +108,12 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
final newEmailResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllEmailCache(
|
||||
accountId,
|
||||
session.username,
|
||||
inMailboxId: emailFilter?.mailboxId,
|
||||
sort: sort,
|
||||
limit: limit,
|
||||
filterOption: emailFilter?.filterOption),
|
||||
stateDataSource.getState(accountId, StateType.email)
|
||||
stateDataSource.getState(accountId, session.username, StateType.email)
|
||||
]).then((List response) {
|
||||
return EmailsResponse(emailList: response.first, state: response.last);
|
||||
});
|
||||
@@ -140,7 +143,7 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
filter: filter ?? EmailFilterCondition(inMailbox: mailboxId),
|
||||
properties: propertiesCreated,
|
||||
);
|
||||
await _updateEmailCache(accountId, newCreated: networkEmailResponse.emailList);
|
||||
await _updateEmailCache(accountId, session.username, newCreated: networkEmailResponse.emailList);
|
||||
|
||||
return networkEmailResponse;
|
||||
}
|
||||
@@ -179,21 +182,23 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
}
|
||||
|
||||
Future<void> _updateEmailCache(
|
||||
AccountId accountId, {
|
||||
AccountId accountId,
|
||||
UserName userName, {
|
||||
List<Email>? newUpdated,
|
||||
List<Email>? newCreated,
|
||||
List<EmailId>? newDestroyed
|
||||
}) async {
|
||||
await mapDataSource[DataSourceType.local]!.update(
|
||||
accountId,
|
||||
userName,
|
||||
updated: newUpdated,
|
||||
created: newCreated,
|
||||
destroyed: newDestroyed);
|
||||
}
|
||||
|
||||
Future<void> _updateState(AccountId accountId, State newState) async {
|
||||
Future<void> _updateState(AccountId accountId, UserName userName, State newState) async {
|
||||
log('ThreadRepositoryImpl::_updateState(): [MAIL] $newState');
|
||||
await stateDataSource.saveState(accountId, newState.toStateCache(StateType.email));
|
||||
await stateDataSource.saveState(accountId, userName, newState.toStateCache(StateType.email));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -220,11 +225,12 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
final newEmailResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllEmailCache(
|
||||
accountId,
|
||||
session.username,
|
||||
inMailboxId: emailFilter?.mailboxId,
|
||||
sort: sort,
|
||||
filterOption: emailFilter?.filterOption
|
||||
),
|
||||
stateDataSource.getState(accountId, StateType.email)
|
||||
stateDataSource.getState(accountId, session.username, StateType.email)
|
||||
]).then((List response) {
|
||||
return EmailsResponse(emailList: response.first, state: response.last);
|
||||
});
|
||||
@@ -249,7 +255,7 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
@override
|
||||
Stream<EmailsResponse> loadMoreEmails(GetEmailRequest emailRequest) async* {
|
||||
final response = await _getAllEmailsWithoutLastEmailId(emailRequest);
|
||||
await _updateEmailCache(emailRequest.accountId, newCreated: response.emailList);
|
||||
await _updateEmailCache(emailRequest.accountId, emailRequest.session.username, newCreated: response.emailList);
|
||||
yield response;
|
||||
}
|
||||
|
||||
@@ -299,7 +305,7 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
accountId,
|
||||
trashMailboxId,
|
||||
(listEmailIdDeleted) async {
|
||||
await _updateEmailCache(accountId, newDestroyed: listEmailIdDeleted);
|
||||
await _updateEmailCache(accountId, session.username, newDestroyed: listEmailIdDeleted);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -313,7 +319,7 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
Properties? propertiesUpdated,
|
||||
}
|
||||
) async {
|
||||
final localEmailList = await mapDataSource[DataSourceType.local]!.getAllEmailCache(accountId);
|
||||
final localEmailList = await mapDataSource[DataSourceType.local]!.getAllEmailCache(accountId, session.username);
|
||||
|
||||
EmailChangeResponse? emailChangeResponse;
|
||||
bool hasMoreChanges = true;
|
||||
@@ -351,12 +357,13 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
|
||||
await _updateEmailCache(
|
||||
accountId,
|
||||
session.username,
|
||||
newCreated: emailChangeResponse.created,
|
||||
newUpdated: newEmailUpdated,
|
||||
newDestroyed: emailChangeResponse.destroyed);
|
||||
|
||||
if (emailChangeResponse.newStateEmail != null) {
|
||||
await _updateState(accountId, emailChangeResponse.newStateEmail!);
|
||||
await _updateState(accountId, session.username, emailChangeResponse.newStateEmail!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ class EmptyTrashFolderInteractor {
|
||||
yield Right<Failure, Success>(LoadingState());
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -24,8 +24,8 @@ class MarkAsMultipleEmailReadInteractor {
|
||||
yield Right(LoadingMarkAsMultipleEmailReadAll());
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -21,7 +21,7 @@ class MarkAsStarMultipleEmailInteractor {
|
||||
try {
|
||||
yield Right(LoadingMarkAsStarMultipleEmailAll());
|
||||
|
||||
final currentEmailState = await _emailRepository.getEmailState(accountId);
|
||||
final currentEmailState = await _emailRepository.getEmailState(session, accountId);
|
||||
|
||||
final listEmailNeedMarkStar = emails
|
||||
.where((email) => markStarAction == MarkStarAction.unMarkStar ? email.hasStarred : !email.hasStarred)
|
||||
|
||||
@@ -24,8 +24,8 @@ class MoveMultipleEmailToMailboxInteractor {
|
||||
yield Right(LoadingMoveMultipleEmailToMailboxAll());
|
||||
|
||||
final listState = await Future.wait([
|
||||
_mailboxRepository.getMailboxState(accountId),
|
||||
_emailRepository.getEmailState(accountId),
|
||||
_mailboxRepository.getMailboxState(session, accountId),
|
||||
_emailRepository.getEmailState(session, accountId),
|
||||
], eagerError: true);
|
||||
|
||||
final currentMailboxState = listState.first;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/oidc/token.dart';
|
||||
|
||||
class AccountRequest with EquatableMixin {
|
||||
final UserName? userName;
|
||||
@@ -16,8 +19,7 @@ class AccountRequest with EquatableMixin {
|
||||
this.authenticationType = AuthenticationType.none,
|
||||
});
|
||||
|
||||
String get basicAuth =>
|
||||
'Basic ${base64Encode(utf8.encode('${userName?.userName}:${password?.value}'))}';
|
||||
String get basicAuth => 'Basic ${base64Encode(utf8.encode('${userName?.value}:${password?.value}'))}';
|
||||
|
||||
String get bearerToken => 'Bearer ${token?.token}';
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/account/account.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart';
|
||||
|
||||
class JmapAccount with EquatableMixin {
|
||||
|
||||
final AccountId accountId;
|
||||
final AccountName name;
|
||||
final bool isPersonal;
|
||||
final bool isReadOnly;
|
||||
final Map<CapabilityIdentifier, CapabilityProperties> accountCapabilities;
|
||||
|
||||
JmapAccount(
|
||||
this.accountId,
|
||||
this.name,
|
||||
this.isPersonal,
|
||||
this.isReadOnly,
|
||||
this.accountCapabilities,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object> get props => [
|
||||
accountId,
|
||||
name,
|
||||
isPersonal,
|
||||
isReadOnly,
|
||||
accountCapabilities
|
||||
];
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user