TF-1613 Implement handleSuccessViewState and handleFailureViewState for all controller
(cherry picked from commit 35e727e795bb3c44cc9c47e02542b5bdc3955fdd)
This commit is contained in:
@@ -96,6 +96,7 @@ abstract class BaseController extends GetxController
|
||||
viewState.value.fold(
|
||||
(failure) {
|
||||
if (_handleCommonException(failure)) {
|
||||
handleFinallyCommonException();
|
||||
return;
|
||||
}
|
||||
handleFailureViewState(failure);
|
||||
@@ -113,6 +114,7 @@ abstract class BaseController extends GetxController
|
||||
void onError(Object error, StackTrace stackTrace) {
|
||||
logError('BaseController::onError():error: $error | stackTrace: $stackTrace');
|
||||
if (_handleCommonError(error)) {
|
||||
handleFinallyCommonException();
|
||||
return;
|
||||
}
|
||||
handleErrorViewState(error, stackTrace);
|
||||
@@ -142,7 +144,6 @@ abstract class BaseController extends GetxController
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).badCredentials);
|
||||
}
|
||||
|
||||
checkAuthenticationTypeWhenLogout();
|
||||
return true;
|
||||
}
|
||||
@@ -152,6 +153,10 @@ abstract class BaseController extends GetxController
|
||||
|
||||
void handleErrorViewState(Object error, StackTrace stackTrace) {}
|
||||
|
||||
void handleFinallyCommonException() {
|
||||
clearState();
|
||||
}
|
||||
|
||||
void handleFailureViewState(Failure failure) {
|
||||
logError('BaseController::handleFailureViewState(): $failure');
|
||||
if (failure is LogoutOidcFailure) {
|
||||
@@ -249,27 +254,18 @@ abstract class BaseController extends GetxController
|
||||
}
|
||||
}
|
||||
|
||||
bool fcmEnabled(Session? session, AccountId? accountId) {
|
||||
bool fcmEnabled = false;
|
||||
try {
|
||||
requireCapability(session!, accountId!, [FirebaseCapability.fcmIdentifier]);
|
||||
if (AppConfig.fcmAvailable) {
|
||||
fcmEnabled = true;
|
||||
} else {
|
||||
fcmEnabled = false;
|
||||
}
|
||||
} catch (e) {
|
||||
logError('BaseController::fcmEnabled(): exception: $e');
|
||||
}
|
||||
return fcmEnabled;
|
||||
}
|
||||
bool _isFcmActivated(Session session, AccountId accountId) =>
|
||||
[FirebaseCapability.fcmIdentifier].isSupported(session, accountId) && AppConfig.fcmAvailable;
|
||||
|
||||
void goToLogin({LoginArguments? arguments}) {
|
||||
pushAndPopAll(AppRoutes.login, arguments: arguments);
|
||||
}
|
||||
|
||||
void logout(Session? session, AccountId? accountId) {
|
||||
_isFcmEnabled = fcmEnabled(session, accountId);
|
||||
if (session == null || accountId == null) {
|
||||
return;
|
||||
}
|
||||
_isFcmEnabled = _isFcmActivated(session, accountId);
|
||||
final authenticationType = authorizationInterceptors.authenticationType;
|
||||
if (authenticationType == AuthenticationType.oidc) {
|
||||
consumeState(logoutOidcInteractor.execute());
|
||||
|
||||
@@ -112,9 +112,9 @@ abstract class BaseMailboxController extends BaseController {
|
||||
if (personalMailboxTree.value.updateExpandedNode(selectedMailboxNode, newExpandMode) != null) {
|
||||
log('toggleMailboxFolder() refresh folderMailboxTree');
|
||||
personalMailboxTree.refresh();
|
||||
final _childrenItems = personalMailboxTree.value.root.childrenItems ?? [];
|
||||
final childrenItems = personalMailboxTree.value.root.childrenItems ?? [];
|
||||
_triggerScrollWhenExpandMailboxFolder(
|
||||
_childrenItems,
|
||||
childrenItems,
|
||||
selectedMailboxNode,
|
||||
scrollController);
|
||||
}
|
||||
@@ -122,9 +122,9 @@ abstract class BaseMailboxController extends BaseController {
|
||||
if (teamMailboxesTree.value.updateExpandedNode(selectedMailboxNode, newExpandMode) != null) {
|
||||
log('toggleMailboxFolder() refresh teamMailboxesTree');
|
||||
teamMailboxesTree.refresh();
|
||||
final _childrenItems = teamMailboxesTree.value.root.childrenItems ?? [];
|
||||
final childrenItems = teamMailboxesTree.value.root.childrenItems ?? [];
|
||||
_triggerScrollWhenExpandMailboxFolder(
|
||||
_childrenItems,
|
||||
childrenItems,
|
||||
selectedMailboxNode,
|
||||
scrollController);
|
||||
}
|
||||
@@ -135,13 +135,13 @@ abstract class BaseMailboxController extends BaseController {
|
||||
MailboxNode selectedMailboxNode,
|
||||
ScrollController scrollController) async {
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
final _lastItem = childrenItems.last;
|
||||
final lastItem = childrenItems.last;
|
||||
|
||||
if (selectedMailboxNode.expandMode == ExpandMode.COLLAPSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_lastItem.mailboxNameAsString.contains(selectedMailboxNode.mailboxNameAsString)) {
|
||||
if (lastItem.mailboxNameAsString.contains(selectedMailboxNode.mailboxNameAsString)) {
|
||||
scrollController.animateTo(
|
||||
scrollController.position.maxScrollExtent,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:core/presentation/extensions/uri_extension.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:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
@@ -35,30 +34,29 @@ abstract class ReloadableController extends BaseController {
|
||||
);
|
||||
|
||||
@override
|
||||
void onData(Either<Failure, Success> newState) {
|
||||
super.onData(newState);
|
||||
viewState.value.fold(
|
||||
(failure) {
|
||||
if (failure is GetCredentialFailure) {
|
||||
goToLogin(arguments: LoginArguments(LoginFormType.credentialForm));
|
||||
} else if (failure is GetSessionFailure) {
|
||||
_handleGetSessionFailure();
|
||||
} else if (failure is GetStoredTokenOidcFailure) {
|
||||
goToLogin(arguments: LoginArguments(LoginFormType.ssoForm));
|
||||
} else if (failure is GetAuthenticatedAccountFailure || failure is NoAuthenticatedAccountFailure) {
|
||||
goToLogin(arguments: LoginArguments(LoginFormType.credentialForm));
|
||||
}
|
||||
},
|
||||
(success) {
|
||||
if (success is GetCredentialViewState) {
|
||||
_handleGetCredentialSuccess(success);
|
||||
} else if (success is GetSessionSuccess) {
|
||||
_handleGetSessionSuccess(success);
|
||||
} else if (success is GetStoredTokenOidcSuccess) {
|
||||
_handleGetStoredTokenOIDCSuccess(success);
|
||||
}
|
||||
}
|
||||
);
|
||||
void handleFailureViewState(Failure failure) {
|
||||
super.handleFailureViewState(failure);
|
||||
if (failure is GetCredentialFailure) {
|
||||
goToLogin(arguments: LoginArguments(LoginFormType.credentialForm));
|
||||
} else if (failure is GetSessionFailure) {
|
||||
_handleGetSessionFailure();
|
||||
} else if (failure is GetStoredTokenOidcFailure) {
|
||||
goToLogin(arguments: LoginArguments(LoginFormType.ssoForm));
|
||||
} else if (failure is GetAuthenticatedAccountFailure || failure is NoAuthenticatedAccountFailure) {
|
||||
goToLogin(arguments: LoginArguments(LoginFormType.credentialForm));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSuccessViewState(Success success) {
|
||||
super.handleSuccessViewState(success);
|
||||
if (success is GetCredentialViewState) {
|
||||
_handleGetCredentialSuccess(success);
|
||||
} else if (success is GetSessionSuccess) {
|
||||
_handleGetSessionSuccess(success);
|
||||
} else if (success is GetStoredTokenOidcSuccess) {
|
||||
_handleGetStoredTokenOIDCSuccess(success);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -91,7 +89,7 @@ abstract class ReloadableController extends BaseController {
|
||||
}
|
||||
|
||||
void _getSessionAction() {
|
||||
consumeState(_getSessionInteractor.execute().asStream());
|
||||
consumeState(_getSessionInteractor.execute());
|
||||
}
|
||||
|
||||
void _handleGetSessionFailure() async {
|
||||
|
||||
Reference in New Issue
Block a user