diff --git a/lib/features/quotas/presentation/quotas_controller.dart b/lib/features/quotas/presentation/quotas_controller.dart index 31a0ced82..c49849a5c 100644 --- a/lib/features/quotas/presentation/quotas_controller.dart +++ b/lib/features/quotas/presentation/quotas_controller.dart @@ -2,25 +2,28 @@ import 'package:core/core.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'; +import 'package:jmap_dart_client/jmap/core/session/session.dart'; import 'package:jmap_dart_client/jmap/quotas/data_types.dart'; import 'package:tmail_ui_user/features/base/base_controller.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart'; import 'package:tmail_ui_user/features/quotas/domain/state/get_quotas_state.dart'; import 'package:tmail_ui_user/features/quotas/domain/use_case/get_quotas_interactor.dart'; import 'package:tmail_ui_user/features/quotas/presentation/model/quotas_state.dart'; +import 'package:tmail_ui_user/main/error/capability_validator.dart'; class QuotasController extends BaseController { final MailboxDashBoardController mailboxDashBoardController = Get.find(); final GetQuotasInteractor _getQuotasInteractor; final usedCapacity = Rx(0); - final softLimitCapacity = Rx(0); + final limitCapacity = Rx(0); final warningLimitCapacity = Rx(0); final enableShowQuotas = false.obs; final quotasState = QuotasState.normal.obs; + final warningProgressConstant = 0.9; late Worker accountIdWorker; - double get progressUsedCapacity => softLimitCapacity.value != 0 - ? (usedCapacity.value / softLimitCapacity.value) + double get progressUsedCapacity => limitCapacity.value != 0 + ? (usedCapacity.value / limitCapacity.value) : 0; bool get enableShowWarningQuotas => @@ -35,18 +38,19 @@ class QuotasController extends BaseController { void _initWorker() { accountIdWorker = ever(mailboxDashBoardController.accountId, (accountId) { - if (accountId is AccountId) { - _getQuotasAction(accountId); + if (accountId is AccountId && mailboxDashBoardController.sessionCurrent!= null) { + _getQuotasAction(accountId, mailboxDashBoardController.sessionCurrent!); } }); } - void _getQuotasAction(AccountId accountId) { - enableShowQuotas.value = mailboxDashBoardController.sessionCurrent != null && - mailboxDashBoardController.sessionCurrent!.capabilities.containsValue(CapabilityIdentifier.jmapQuota); - - if(enableShowQuotas.isTrue) { + void _getQuotasAction(AccountId accountId, Session session) { + try { + requireCapability(session, accountId, [CapabilityIdentifier.jmapQuota]); + enableShowQuotas.value = true; consumeState(_getQuotasInteractor.execute(mailboxDashBoardController.accountId.value!)); + } catch (e) { + logError('QuotasController::_getQuotasAction():$e'); } } @@ -70,9 +74,9 @@ class QuotasController extends BaseController { try { final quotas = success.quotas.firstWhere((e) => e.resourceType == ResourceType.octets); usedCapacity.value = quotas.used.value; - warningLimitCapacity.value = quotas.warnLimit?.value ?? 0; - softLimitCapacity.value = quotas.softLimit?.value ?? 0; - if(usedCapacity.value >= softLimitCapacity.value) { + warningLimitCapacity.value = quotas.limit.value * warningProgressConstant; + limitCapacity.value = quotas.limit.value; + if(usedCapacity.value >= limitCapacity.value) { quotasState.value = QuotasState.runOutOfStorage; } else if (usedCapacity.value >= warningLimitCapacity.value) { quotasState.value = QuotasState.runningOutOfStorage; diff --git a/lib/features/quotas/presentation/widget/quotas_footer_widget.dart b/lib/features/quotas/presentation/widget/quotas_footer_widget.dart index 559212991..425db8c45 100644 --- a/lib/features/quotas/presentation/widget/quotas_footer_widget.dart +++ b/lib/features/quotas/presentation/widget/quotas_footer_widget.dart @@ -46,7 +46,7 @@ class QuotasFooterWidget extends GetWidget { controller.quotasState.value.getQuotasFooterText( context, controller.usedCapacity.value, - controller.softLimitCapacity.value, + controller.limitCapacity.value, ), style: TextStyle( fontSize: 13, diff --git a/lib/l10n/intl_messages.arb b/lib/l10n/intl_messages.arb index 6895ac159..c7f16973c 100644 --- a/lib/l10n/intl_messages.arb +++ b/lib/l10n/intl_messages.arb @@ -1,13 +1,5 @@ { -<<<<<<< HEAD -<<<<<<< HEAD - "@@last_modified": "2022-11-08T16:55:51.988372", -======= - "@@last_modified": "2022-11-09T17:10:23.172672", ->>>>>>> 24967b2c (TF-1014: [Dev] Show quota at the bottom of mailbox) -======= - "@@last_modified": "2022-11-10T10:33:41.637215", ->>>>>>> 1ad5dd5c (TF-1014: add quotas out of storage) + "@@last_modified": "2022-11-10T15:16:34.946211", "initializing_data": "Initializing data...", "@initializing_data": { "type": "text", @@ -2420,18 +2412,12 @@ "placeholders_order": [], "placeholders": {} }, -<<<<<<< HEAD "forwardingSettingExplanation": "Allows a new recipient to see the email sent if they were not originally included in the email chain.", "@forwardingSettingExplanation": { -======= - "storageQuotas": "Storage", - "@storageQuotas": { ->>>>>>> 24967b2c (TF-1014: [Dev] Show quota at the bottom of mailbox) "type": "text", "placeholders_order": [], "placeholders": {} }, -<<<<<<< HEAD "addRecipientButton": "Add recipient", "@addRecipientButton": { "type": "text", @@ -2458,7 +2444,14 @@ ], "placeholders": { "count": {} -======= + } + }, + "storageQuotas": "Storage", + "@storageQuotas": { + "type": "text", + "placeholders_order": [], + "placeholders": {} + }, "textQuotasUsed": "{used} GB of {softLimit} GB Used", "@textQuotasUsed": { "type": "text", @@ -2479,7 +2472,6 @@ ], "placeholders": { "progress": {} ->>>>>>> 24967b2c (TF-1014: [Dev] Show quota at the bottom of mailbox) } }, "textQuotasRunningOutOfStorageContent": "Soon you won't be able to email in Team Mail. Please clean your storage or upgrade your storage to get full features in Team Mail.",