TF-123 Create objects for caching mailbox
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
extension ListMailboxCacheExtension on List<MailboxCache> {
|
||||
Map<String, MailboxCache> toMap() {
|
||||
return Map<String, MailboxCache>.fromIterable(
|
||||
this,
|
||||
key: (mailboxCache) => mailboxCache.id,
|
||||
value: (mailboxCache) => mailboxCache);
|
||||
}
|
||||
|
||||
List<Mailbox> toMailboxList() {
|
||||
return map((mailboxCache) => mailboxCache.toMailbox()).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
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:model/model.dart';
|
||||
|
||||
extension MailboxCacheExtension on MailboxCache {
|
||||
Mailbox toMailbox() {
|
||||
return Mailbox(
|
||||
MailboxId(Id(id)),
|
||||
name != null ? MailboxName(name!) : null,
|
||||
parentId != null ? MailboxId(Id(parentId!)) : null,
|
||||
role != null ? Role(role!) : null,
|
||||
sortOrder != null ? SortOrder(sortValue: sortOrder!) : null,
|
||||
totalEmails != null ? TotalEmails(UnsignedInt(totalEmails!)) : null,
|
||||
unreadEmails != null ? UnreadEmails(UnsignedInt(unreadEmails!)) : null,
|
||||
totalThreads != null ? TotalThreads(UnsignedInt(totalThreads!)) : null,
|
||||
unreadThreads != null ? UnreadThreads(UnsignedInt(unreadThreads!)) : null,
|
||||
myRights != null ? myRights!.toMailboxRights() : null,
|
||||
isSubscribed != null ? IsSubscribed(isSubscribed!) : null
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
extension MailboxExtension on Mailbox {
|
||||
|
||||
bool hasRole() => role != null && role!.value.isNotEmpty;
|
||||
|
||||
PresentationMailbox toPresentationMailbox({SelectMode selectMode = SelectMode.INACTIVE}) {
|
||||
return PresentationMailbox(
|
||||
id,
|
||||
name: name,
|
||||
parentId: parentId,
|
||||
role: role,
|
||||
sortOrder: sortOrder,
|
||||
totalEmails: totalEmails,
|
||||
unreadEmails: unreadEmails,
|
||||
totalThreads: totalThreads,
|
||||
unreadThreads: unreadThreads,
|
||||
myRights: myRights,
|
||||
isSubscribed: isSubscribed,
|
||||
selectMode: selectMode
|
||||
);
|
||||
}
|
||||
|
||||
MailboxCache toMailboxCache() {
|
||||
return MailboxCache(
|
||||
id.id.value,
|
||||
name: name?.name,
|
||||
parentId: parentId?.id.value,
|
||||
role: role?.value,
|
||||
sortOrder: sortOrder?.value.value.round(),
|
||||
totalEmails: totalEmails?.value.value.round(),
|
||||
unreadEmails: unreadEmails?.value.value.round(),
|
||||
totalThreads: totalThreads?.value.value.round(),
|
||||
unreadThreads: unreadThreads?.value.value.round(),
|
||||
myRights: myRights != null ? myRights!.toMailboxRightsCache() : null,
|
||||
isSubscribed: isSubscribed?.value
|
||||
);
|
||||
}
|
||||
|
||||
Mailbox combineMailbox(Mailbox newMailbox, Properties updatedProperties) {
|
||||
return Mailbox(
|
||||
newMailbox.id,
|
||||
updatedProperties.contain(MailboxProperty.name) ? newMailbox.name : name,
|
||||
updatedProperties.contain(MailboxProperty.parentId) ? newMailbox.parentId : parentId,
|
||||
updatedProperties.contain(MailboxProperty.role) ? newMailbox.role : role,
|
||||
updatedProperties.contain(MailboxProperty.sortOrder) ? newMailbox.sortOrder : sortOrder,
|
||||
updatedProperties.contain(MailboxProperty.totalEmails) ? newMailbox.totalEmails : totalEmails,
|
||||
updatedProperties.contain(MailboxProperty.unreadEmails) ? newMailbox.unreadEmails : unreadEmails,
|
||||
updatedProperties.contain(MailboxProperty.totalThreads) ? newMailbox.totalThreads : totalThreads,
|
||||
updatedProperties.contain(MailboxProperty.unreadThreads) ? newMailbox.unreadThreads : unreadThreads,
|
||||
updatedProperties.contain(MailboxProperty.myRights) ? newMailbox.myRights : myRights,
|
||||
updatedProperties.contain(MailboxProperty.isSubscribed) ? newMailbox.isSubscribed : isSubscribed,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
|
||||
extension MailboxNameExtension on MailboxName {
|
||||
int compareAlphabetically(MailboxName? other) {
|
||||
if (other == null) {
|
||||
return 1;
|
||||
}
|
||||
return name.toLowerCase().compareTo(other.name.toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_rights.dart';
|
||||
import 'package:model/caching/mailbox/mailbox_rights_cache.dart';
|
||||
|
||||
extension MailboxRightsCacheExtension on MailboxRightsCache {
|
||||
MailboxRights toMailboxRights() {
|
||||
return MailboxRights(
|
||||
mayReadItems,
|
||||
mayAddItems,
|
||||
mayRemoveItems,
|
||||
maySetSeen,
|
||||
maySetKeywords,
|
||||
mayCreateChild,
|
||||
mayRename,
|
||||
mayDelete,
|
||||
maySubmit
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_rights.dart';
|
||||
import 'package:model/caching/mailbox/mailbox_rights_cache.dart';
|
||||
|
||||
extension MailboxRightsExtension on MailboxRights {
|
||||
MailboxRightsCache toMailboxRightsCache() {
|
||||
return MailboxRightsCache(
|
||||
mayReadItems,
|
||||
mayAddItems,
|
||||
mayRemoveItems,
|
||||
maySetSeen,
|
||||
maySetKeywords,
|
||||
mayCreateChild,
|
||||
mayRename,
|
||||
mayDelete,
|
||||
maySubmit
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
|
||||
extension PropertiesExtension on Properties {
|
||||
|
||||
bool contain(String key) => value.contains(key);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
extension StateExtension on State {
|
||||
StateDao toStateDao(StateType stateType) {
|
||||
return StateDao(stateType, value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user