Use TupleKey(ObjectKey-AccountId-UserName) to store data to hive
(cherry picked from commit e0ace535d5f3af71eb13598d92524caf2c6d9bbf)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user