diff --git a/core/lib/presentation/utils/app_toast.dart b/core/lib/presentation/utils/app_toast.dart index ce6bfa798..ba800c21d 100644 --- a/core/lib/presentation/utils/app_toast.dart +++ b/core/lib/presentation/utils/app_toast.dart @@ -123,7 +123,7 @@ class AppToast { fToast.showToast( child: toast, gravity: ToastGravity.BOTTOM, - toastDuration: toastLength ?? Duration(seconds: 2), + toastDuration: toastLength ?? Duration(seconds: 3), ); } } diff --git a/lib/features/mailbox/data/network/mailbox_api.dart b/lib/features/mailbox/data/network/mailbox_api.dart index 6866f4b72..dd252a900 100644 --- a/lib/features/mailbox/data/network/mailbox_api.dart +++ b/lib/features/mailbox/data/network/mailbox_api.dart @@ -5,6 +5,8 @@ import 'package:jmap_dart_client/http/http_client.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/capability/core_capability.dart'; +import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart'; +import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/patch_object.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/request/reference_path.dart'; @@ -125,16 +127,34 @@ class MailboxAPI { setMailboxInvocation.methodCallId, SetMailboxResponse.deserialize); - return Future.sync(() async { - final newMailbox = setMailboxResponse?.created?[request.creationId]; - if (newMailbox != null) { - return newMailbox.addMailboxName(newMailbox, request.newName, parentId: request.parentId); + final mapMailboxCreated = setMailboxResponse?.created; + if (mapMailboxCreated != null && + mapMailboxCreated.containsKey(request.creationId)) { + final mailboxCreated = mapMailboxCreated[request.creationId]!; + final newMailboxCreated = mailboxCreated.toMailbox( + request.newName, + parentId: request.parentId); + return newMailboxCreated; + } else { + throw _parseErrorForSetMailboxResponse(setMailboxResponse, request.creationId); + } + } + + _parseErrorForSetMailboxResponse(SetMailboxResponse? response, Id requestId) { + final mapError = response?.notCreated ?? response?.notUpdated ?? response?.notDestroyed; + if (mapError != null && mapError.containsKey(requestId)) { + final setError = mapError[requestId]; + log('MailboxAPI::_parseErrorForSetMailboxResponse():setError: $setError'); + if (setError?.type == ErrorMethodResponse.invalidArguments) { + throw InvalidArgumentsMethodResponse(description: setError?.description); + } else if (setError?.type == ErrorMethodResponse.invalidResultReference) { + throw InvalidResultReferenceMethodResponse(description: setError?.description); } else { - return null; + throw UnknownMethodResponse(description: setError?.description); } - }).catchError((error) { - throw error; - }); + } else { + throw UnknownMethodResponse(); + } } Future deleteMultipleMailbox(Session session, AccountId accountId, List mailboxIds) async { diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index e4c433121..892570d5f 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; +import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart'; import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; @@ -411,11 +412,17 @@ class MailboxController extends BaseMailboxController { void _createNewMailboxFailure(CreateNewMailboxFailure failure) { if (currentOverlayContext != null && currentContext != null) { + final exception = failure.exception; + var messageError = AppLocalizations.of(currentContext!).create_new_mailbox_failure; + if (exception is ErrorMethodResponse) { + messageError = exception.description ?? AppLocalizations.of(currentContext!).create_new_mailbox_failure; + } + _appToast.showToastWithIcon( currentOverlayContext!, - textColor: AppColor.toastErrorBackgroundColor, - message: AppLocalizations.of(currentContext!).create_new_mailbox_failure, - icon: _imagePaths.icFolderMailbox); + message: messageError, + iconColor: AppColor.toastErrorBackgroundColor, + icon: _imagePaths.icNotConnection); } } diff --git a/model/lib/extensions/mailbox_extension.dart b/model/lib/extensions/mailbox_extension.dart index 8b86a7078..1da03bf49 100644 --- a/model/lib/extensions/mailbox_extension.dart +++ b/model/lib/extensions/mailbox_extension.dart @@ -38,7 +38,7 @@ extension MailboxExtension on Mailbox { ); } - Mailbox addMailboxName(Mailbox newMailbox, MailboxName mailboxName, {MailboxId? parentId}) { + Mailbox toMailbox(MailboxName mailboxName, {MailboxId? parentId}) { return Mailbox( id: id, name: mailboxName,