TF-1310: [Presentation] Refactor buildTree logic in TreeBuilder + BaseMailboxController

This commit is contained in:
HuyNguyen
2023-02-02 22:19:43 +07:00
committed by Dat Vu
parent d57bcd10dd
commit 10ba3867d8
30 changed files with 523 additions and 237 deletions
@@ -2,6 +2,7 @@
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/namespace.dart';
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart';
import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_rights_cache_extension.dart';
@@ -18,7 +19,8 @@ extension MailboxCacheExtension on MailboxCache {
totalThreads: totalThreads != null ? TotalThreads(UnsignedInt(totalThreads!)) : null,
unreadThreads: unreadThreads != null ? UnreadThreads(UnsignedInt(unreadThreads!)) : null,
myRights: myRights != null ? myRights!.toMailboxRights() : null,
isSubscribed: isSubscribed != null ? IsSubscribed(isSubscribed!) : null
isSubscribed: isSubscribed != null ? IsSubscribed(isSubscribed!) : null,
namespace: namespace != null ? Namespace(namespace!) : null
);
}
}
@@ -16,7 +16,8 @@ extension MailboxExtension on Mailbox {
totalThreads: totalThreads?.value.value.round(),
unreadThreads: unreadThreads?.value.value.round(),
myRights: myRights != null ? myRights!.toMailboxRightsCache() : null,
isSubscribed: isSubscribed?.value
isSubscribed: isSubscribed?.value,
namespace: namespace?.value
);
}
}
@@ -45,6 +45,9 @@ class MailboxCache extends HiveObject with EquatableMixin {
@HiveField(11)
final DateTime? lastOpened;
@HiveField(12)
final String? namespace;
MailboxCache(
this.id,
{
@@ -58,7 +61,8 @@ class MailboxCache extends HiveObject with EquatableMixin {
this.unreadThreads,
this.myRights,
this.isSubscribed,
this.lastOpened
this.lastOpened,
this.namespace,
}
);
@@ -68,7 +72,13 @@ class MailboxCache extends HiveObject with EquatableMixin {
name,
parentId,
role,
totalEmails,
unreadEmails,
totalThreads,
unreadThreads,
lastOpened,
myRights,
isSubscribed,
namespace,
];
}
@@ -47,7 +47,7 @@ class MailboxAPI with HandleSetErrorMixin {
final queryInvocation = jmapRequestBuilder.invocation(getMailboxCreated);
final capabilities = checkCapabilities(session, accountId);
final capabilities = capabilitiesSupportedMailboxes(session, accountId);
final result = await (jmapRequestBuilder
..usings(capabilities))
@@ -61,17 +61,13 @@ class MailboxAPI with HandleSetErrorMixin {
return MailboxResponse(mailboxes: resultCreated?.list, state: resultCreated?.state);
}
Set<CapabilityIdentifier> checkCapabilities(Session session, AccountId accountId) {
Set<CapabilityIdentifier> capabilitiesSupportedMailboxes(Session session, AccountId accountId) {
final getMailboxCreated = GetMailboxMethod(accountId);
try {
requireCapability(
session,
accountId,
[
CapabilityIdentifier.jmapCore,
CapabilityIdentifier.jmapMail,
CapabilityIdentifier.jmapTeamMailboxes
]);
[CapabilityIdentifier.jmapTeamMailboxes]);
return getMailboxCreated.requiredCapabilitiesSupportTeamMailboxes;
} catch (_) {
return getMailboxCreated.requiredCapabilities;
@@ -70,7 +70,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
]);
}
} else {
final mailboxResponse = await mapDataSource[DataSourceType.network]!.getAllMailbox(session, accountId,);
final mailboxResponse = await mapDataSource[DataSourceType.network]!.getAllMailbox(session, accountId);
await Future.wait([
mapDataSource[DataSourceType.local]!.update(created: mailboxResponse.mailboxes),