Fix forward recipients error handling
This commit is contained in:
+20
-2
@@ -1,14 +1,16 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:model/mailbox/select_mode.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/add_recipient_in_forwarding_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/delete_recipient_in_forwarding_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/edit_local_copy_in_forwarding_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/update_forwarding_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/forward/forward_controller.dart';
|
||||
|
||||
extension HandleErrorWhenUpdateForwardFailExtension on ForwardController {
|
||||
extension HandleUpdateForwardExtension on ForwardController {
|
||||
void handleErrorWhenUpdateForwardFail(Failure failure) {
|
||||
logError(
|
||||
'HandleErrorWhenUpdateForwardFailExtension::handleErrorWhenUpdateForwardFail: $failure',
|
||||
'$runtimeType::handleErrorWhenUpdateForwardFail: $failure',
|
||||
);
|
||||
if (failure is AddRecipientsInForwardingFailure) {
|
||||
_handleAddRecipientsInForwardingFailure(failure);
|
||||
@@ -37,4 +39,20 @@ extension HandleErrorWhenUpdateForwardFailExtension on ForwardController {
|
||||
) {
|
||||
toastManager.showMessageFailure(failure);
|
||||
}
|
||||
|
||||
void handleUpdateForwardingCompleteWithSomeCaseFailure(
|
||||
UpdateForwardingCompleteWithSomeCaseFailure state,
|
||||
) {
|
||||
log(
|
||||
'$runtimeType::handleUpdateForwardingCompleteWithSomeCaseFailure: $state',
|
||||
);
|
||||
if (state is AddRecipientsInForwardingSuccessWithSomeCaseFailure) {
|
||||
recipientController.clearAll();
|
||||
} else if (state is DeleteRecipientInForwardingSuccessWithSomeCaseFailure) {
|
||||
selectionMode.value = SelectMode.INACTIVE;
|
||||
}
|
||||
updateTMailForward(state.forward);
|
||||
|
||||
toastManager.showMessageFailure(state);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import 'package:tmail_ui_user/features/manage_account/domain/state/add_recipient
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/delete_recipient_in_forwarding_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/edit_local_copy_in_forwarding_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/get_forward_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/update_forwarding_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/usecases/add_recipients_in_forwarding_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/usecases/delete_recipient_in_forwarding_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/usecases/edit_local_copy_in_forwarding_interactor.dart';
|
||||
@@ -29,7 +30,7 @@ import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_forwar
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/action/dashboard_setting_action.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/extensions/tmail_forward_extension.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/forward/controller/forward_recipient_controller.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/forward/extensions/handle_error_when_update_forward_fail_extension.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/forward/extensions/handle_update_forward_extension.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/manage_account_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/recipient_forward.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
@@ -88,9 +89,7 @@ class ForwardController extends BaseController {
|
||||
@override
|
||||
void handleSuccessViewState(Success success) {
|
||||
if (success is GetForwardSuccess) {
|
||||
currentForward.value = success.forward;
|
||||
listRecipientForward.value = currentForward.value!.listRecipientForward;
|
||||
_updateForwardWarningBannerState();
|
||||
updateTMailForward(success.forward);
|
||||
} else if (success is DeleteRecipientInForwardingSuccess) {
|
||||
_handleDeleteRecipientSuccess(success);
|
||||
} else if (success is AddRecipientsInForwardingSuccess) {
|
||||
@@ -108,6 +107,8 @@ class ForwardController extends BaseController {
|
||||
failure is DeleteRecipientInForwardingFailure ||
|
||||
failure is EditLocalCopyInForwardingFailure) {
|
||||
handleErrorWhenUpdateForwardFail(failure);
|
||||
} else if (failure is UpdateForwardingCompleteWithSomeCaseFailure) {
|
||||
handleUpdateForwardingCompleteWithSomeCaseFailure(failure);
|
||||
} else {
|
||||
super.handleFailureViewState(failure);
|
||||
}
|
||||
@@ -119,6 +120,12 @@ class ForwardController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
void updateTMailForward(TMailForward forward) {
|
||||
currentForward.value = forward;
|
||||
listRecipientForward.value = forward.listRecipientForward;
|
||||
_updateForwardWarningBannerState();
|
||||
}
|
||||
|
||||
void deleteRecipients(BuildContext context, String emailAddress) {
|
||||
clearInputFocus();
|
||||
|
||||
@@ -154,11 +161,8 @@ class ForwardController extends BaseController {
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).toastMessageDeleteRecipientSuccessfully);
|
||||
}
|
||||
|
||||
currentForward.value = success.forward;
|
||||
listRecipientForward.value = currentForward.value!.listRecipientForward;
|
||||
selectionMode.value = SelectMode.INACTIVE;
|
||||
_updateForwardWarningBannerState();
|
||||
updateTMailForward(success.forward);
|
||||
}
|
||||
|
||||
List<RecipientForward> get listRecipientForwardSelected =>
|
||||
@@ -260,13 +264,8 @@ class ForwardController extends BaseController {
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).toastMessageAddRecipientsSuccessfully);
|
||||
}
|
||||
|
||||
currentForward.value = success.forward;
|
||||
listRecipientForward.value = currentForward.value!.listRecipientForward;
|
||||
|
||||
recipientController.clearAll();
|
||||
|
||||
_updateForwardWarningBannerState();
|
||||
updateTMailForward(success.forward);
|
||||
}
|
||||
|
||||
void handleEditLocalCopy() {
|
||||
@@ -292,11 +291,7 @@ class ForwardController extends BaseController {
|
||||
? AppLocalizations.of(currentContext!).toastMessageLocalCopyEnable
|
||||
: AppLocalizations.of(currentContext!).toastMessageLocalCopyDisable);
|
||||
}
|
||||
|
||||
currentForward.value = success.forward;
|
||||
listRecipientForward.value = currentForward.value!.listRecipientForward;
|
||||
|
||||
_updateForwardWarningBannerState();
|
||||
updateTMailForward(success.forward);
|
||||
}
|
||||
|
||||
void registerListenerWorker() {
|
||||
|
||||
Reference in New Issue
Block a user