TF-1604: Add requiredCapabilities support TeamMailbox for GetEmailMethod
(cherry picked from commit 3922303e63a8e910511361019a54ea13801e3f92)
This commit is contained in:
@@ -3,6 +3,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/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/extensions/fcm_subscription_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/fcm_subscription.dart';
|
||||
@@ -25,6 +26,7 @@ class FCMRepositoryImpl extends FCMRepository {
|
||||
|
||||
@override
|
||||
Future<EmailsResponse> getEmailChangesToPushNotification(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
jmap.State currentState,
|
||||
{
|
||||
@@ -38,6 +40,7 @@ class FCMRepositoryImpl extends FCMRepository {
|
||||
|
||||
while (hasMoreChanges && sinceState != null) {
|
||||
final changesResponse = await _threadDataSource.getChanges(
|
||||
session,
|
||||
accountId,
|
||||
sinceState,
|
||||
propertiesCreated: propertiesCreated,
|
||||
|
||||
@@ -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/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/fcm_subscription.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/model/email_response.dart';
|
||||
@@ -9,6 +10,7 @@ import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
|
||||
abstract class FCMRepository {
|
||||
Future<EmailsResponse> getEmailChangesToPushNotification(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
jmap.State currentState,
|
||||
{
|
||||
|
||||
+3
@@ -3,6 +3,7 @@ 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/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:model/extensions/email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
@@ -14,6 +15,7 @@ class GetEmailChangesToPushNotificationInteractor {
|
||||
GetEmailChangesToPushNotificationInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
jmap.State currentState,
|
||||
{
|
||||
@@ -25,6 +27,7 @@ class GetEmailChangesToPushNotificationInteractor {
|
||||
yield Right<Failure, Success>(GetEmailChangesToPushNotificationLoading());
|
||||
|
||||
final emailsResponse = await _fcmRepository.getEmailChangesToPushNotification(
|
||||
session,
|
||||
accountId,
|
||||
currentState,
|
||||
propertiesCreated: propertiesCreated,
|
||||
|
||||
@@ -1,6 +1,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:tmail_ui_user/features/base/action/ui_action.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
|
||||
@@ -20,16 +21,18 @@ class SynchronizeEmailOnForegroundAction extends FcmStateChangeAction {
|
||||
|
||||
class PushNotificationAction extends FcmStateChangeAction {
|
||||
|
||||
final Session session;
|
||||
final AccountId accountId;
|
||||
|
||||
PushNotificationAction(
|
||||
TypeName typeName,
|
||||
jmap.State newState,
|
||||
this.session,
|
||||
this.accountId
|
||||
) : super(typeName, newState);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [typeName, newState, accountId];
|
||||
List<Object?> get props => [typeName, newState, accountId, session];
|
||||
}
|
||||
|
||||
class StoreEmailStateToRefreshAction extends FcmStateChangeAction {
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
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/push/state_change.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
@@ -37,6 +38,7 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
class FcmController extends BaseController {
|
||||
|
||||
AccountId? _currentAccountId;
|
||||
Session? _currentSession;
|
||||
RemoteMessage? _remoteMessageBackground;
|
||||
|
||||
GetAuthenticatedAccountInteractor? _getAuthenticatedAccountInteractor;
|
||||
@@ -50,7 +52,8 @@ class FcmController extends BaseController {
|
||||
|
||||
static FcmController get instance => _instance;
|
||||
|
||||
void initialize({AccountId? accountId}) {
|
||||
void initialize({Session? session, AccountId? accountId}) {
|
||||
_currentSession = session;
|
||||
_currentAccountId = accountId;
|
||||
FcmTokenHandler.instance.initialize();
|
||||
}
|
||||
@@ -86,10 +89,10 @@ class FcmController extends BaseController {
|
||||
|
||||
void _handleForegroundMessageAction(RemoteMessage newRemoteMessage) {
|
||||
log('FcmController::_handleForegroundMessageAction():remoteMessage: ${newRemoteMessage.data}');
|
||||
if (_currentAccountId != null) {
|
||||
if (_currentAccountId != null && _currentSession != null) {
|
||||
final stateChange = _convertRemoteMessageToStateChange(newRemoteMessage);
|
||||
final mapTypeState = stateChange.getMapTypeState(_currentAccountId!);
|
||||
_mappingTypeStateToAction(mapTypeState, _currentAccountId!);
|
||||
_mappingTypeStateToAction(_currentSession!, mapTypeState, _currentAccountId!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +108,7 @@ class FcmController extends BaseController {
|
||||
}
|
||||
|
||||
void _mappingTypeStateToAction(
|
||||
Session session,
|
||||
Map<String, dynamic> mapTypeState,
|
||||
AccountId accountId, {
|
||||
bool isForeground = true,
|
||||
@@ -116,7 +120,7 @@ class FcmController extends BaseController {
|
||||
|
||||
final listEmailActions = listTypeName
|
||||
.where((typeName) => typeName == TypeName.emailType || typeName == TypeName.emailDelivery)
|
||||
.map((typeName) => toFcmAction(typeName, accountId, mapTypeState, isForeground))
|
||||
.map((typeName) => toFcmAction(session, typeName, accountId, mapTypeState, isForeground))
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
|
||||
@@ -128,7 +132,7 @@ class FcmController extends BaseController {
|
||||
|
||||
final listMailboxActions = listTypeName
|
||||
.where((typeName) => typeName == TypeName.mailboxType)
|
||||
.map((typeName) => toFcmAction(typeName, accountId, mapTypeState, isForeground))
|
||||
.map((typeName) => toFcmAction(session, typeName, accountId, mapTypeState, isForeground))
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
|
||||
@@ -140,6 +144,7 @@ class FcmController extends BaseController {
|
||||
}
|
||||
|
||||
FcmAction? toFcmAction(
|
||||
Session session,
|
||||
TypeName typeName,
|
||||
AccountId accountId,
|
||||
Map<String, dynamic> mapTypeState,
|
||||
@@ -154,7 +159,7 @@ class FcmController extends BaseController {
|
||||
}
|
||||
} else if (typeName == TypeName.emailDelivery) {
|
||||
if (!isForeground) {
|
||||
return PushNotificationAction(typeName, newState, accountId);
|
||||
return PushNotificationAction(typeName, newState, session, accountId);
|
||||
}
|
||||
} else if (typeName == TypeName.mailboxType) {
|
||||
if (isForeground) {
|
||||
@@ -243,10 +248,10 @@ class FcmController extends BaseController {
|
||||
|
||||
void _pushActionFromRemoteMessageBackground() {
|
||||
log('FcmController::_pushActionFromRemoteMessageBackground():');
|
||||
if (_remoteMessageBackground != null && _currentAccountId != null) {
|
||||
if (_remoteMessageBackground != null && _currentAccountId != null && _currentSession != null) {
|
||||
final stateChange = _convertRemoteMessageToStateChange(_remoteMessageBackground!);
|
||||
final mapTypeState = stateChange.getMapTypeState(_currentAccountId!);
|
||||
_mappingTypeStateToAction(mapTypeState, _currentAccountId!, isForeground: false);
|
||||
_mappingTypeStateToAction(_currentSession!, mapTypeState, _currentAccountId!, isForeground: false);
|
||||
}
|
||||
_clearRemoteMessageBackground();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/build_utils.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:model/email/presentation_email.dart';
|
||||
import 'package:model/notification/notification_payload.dart';
|
||||
@@ -41,6 +42,7 @@ class EmailChangeListener extends ChangeListener {
|
||||
|
||||
jmap.State? _newState;
|
||||
AccountId? _accountId;
|
||||
Session? _session;
|
||||
|
||||
EmailChangeListener._internal() {
|
||||
try {
|
||||
@@ -66,7 +68,7 @@ class EmailChangeListener extends ChangeListener {
|
||||
if (action is SynchronizeEmailOnForegroundAction) {
|
||||
_synchronizeEmailOnForegroundAction(action.newState);
|
||||
} else if (action is PushNotificationAction) {
|
||||
_pushNotificationAction(action.newState, action.accountId);
|
||||
_pushNotificationAction(action.newState, action.accountId, action.session);
|
||||
} else if (action is StoreEmailStateToRefreshAction) {
|
||||
_handleStoreEmailStateToRefreshAction(action.newState);
|
||||
}
|
||||
@@ -80,7 +82,7 @@ class EmailChangeListener extends ChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
void _pushNotificationAction(jmap.State newState, AccountId accountId) {
|
||||
void _pushNotificationAction(jmap.State newState, AccountId accountId, Session session) {
|
||||
_newState = newState;
|
||||
_accountId = accountId;
|
||||
log('EmailChangeListener::_pushNotificationAction():newState: $newState');
|
||||
@@ -116,8 +118,9 @@ class EmailChangeListener extends ChangeListener {
|
||||
}
|
||||
|
||||
void _getEmailChangesAction(jmap.State state) {
|
||||
if (_getEmailChangesToPushNotificationInteractor != null && _accountId != null) {
|
||||
if (_getEmailChangesToPushNotificationInteractor != null && _accountId != null && _session != null) {
|
||||
consumeState(_getEmailChangesToPushNotificationInteractor!.execute(
|
||||
_session!,
|
||||
_accountId!,
|
||||
state,
|
||||
propertiesCreated: ThreadConstants.propertiesDefault,
|
||||
|
||||
Reference in New Issue
Block a user