TF-1710 Move all method of PresentationMailbox object to extension to sync
(cherry picked from commit 408fb1840df1f04d51c018992e13ad1011649cbd)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/extensions/presentation_mailbox_extension.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
|
||||
extension ListPresentationMailboxExtension on List<PresentationMailbox> {
|
||||
@@ -14,7 +15,7 @@ extension ListPresentationMailboxExtension on List<PresentationMailbox> {
|
||||
|
||||
bool get isAllDefaultMailboxes => every((mailbox) => mailbox.isDefault);
|
||||
|
||||
bool get isAllUnreadMailboxes => every((mailbox) => mailbox.getCountUnReadEmails().isNotEmpty);
|
||||
bool get isAllUnreadMailboxes => every((mailbox) => mailbox.countUnReadEmailsAsString.isNotEmpty);
|
||||
|
||||
List<MailboxId> get mailboxIds => map((mailbox) => mailbox.id).toList();
|
||||
}
|
||||
@@ -1,8 +1,73 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/namespace.dart';
|
||||
import 'package:model/mailbox/mailbox_state.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:model/mailbox/select_mode.dart';
|
||||
|
||||
extension PresentationMailboxExtension on PresentationMailbox {
|
||||
|
||||
bool get isActivated => state == MailboxState.activated;
|
||||
|
||||
bool hasParentId() => parentId != null && parentId!.id.value.isNotEmpty;
|
||||
|
||||
bool hasRole() => role != null && role!.value.isNotEmpty;
|
||||
|
||||
bool get isDefault => hasRole();
|
||||
|
||||
bool get isPersonal => namespace == null || namespace == Namespace('Personal');
|
||||
|
||||
bool get isTeamMailboxes => !isPersonal && !hasParentId();
|
||||
|
||||
bool get isChildOfTeamMailboxes => !isPersonal && hasParentId();
|
||||
|
||||
String get countUnReadEmailsAsString {
|
||||
if (countUnreadEmails <= 0) return '';
|
||||
return countUnreadEmails <= 999 ? '$countUnreadEmails' : '999+';
|
||||
}
|
||||
|
||||
int get countUnreadEmails => unreadEmails?.value.value.toInt() ?? 0;
|
||||
|
||||
int get countTotalEmails => totalEmails?.value.value.toInt() ?? 0;
|
||||
|
||||
bool get isSpam => role == PresentationMailbox.roleSpam;
|
||||
|
||||
bool get isTrash => role == PresentationMailbox.roleTrash;
|
||||
|
||||
bool get isDrafts => role == PresentationMailbox.roleDrafts;
|
||||
|
||||
bool get isTemplates => role == PresentationMailbox.roleTemplates;
|
||||
|
||||
bool get isSent => role == PresentationMailbox.roleSent;
|
||||
|
||||
bool get isOutbox => name == PresentationMailbox.lowerCaseOutboxMailboxName || role == PresentationMailbox.roleOutbox;
|
||||
|
||||
bool get isSubscribedMailbox => isSubscribed != null && isSubscribed?.value == true;
|
||||
|
||||
bool get allowedToDisplayCountOfUnreadEmails => !(isTrash || isSpam || isDrafts || isTemplates || isSent);
|
||||
|
||||
bool get allowedToDisplayCountOfTotalEmails => isTrash || isSpam;
|
||||
|
||||
String get countTotalEmailsAsString {
|
||||
if (countTotalEmails <= 0) return '';
|
||||
return countTotalEmails <= 999 ? '$countTotalEmails' : '999+';
|
||||
}
|
||||
|
||||
String? get emailTeamMailBoxes => namespace?.value.substring(
|
||||
(namespace?.value.indexOf('[') ?? 0) + 1,
|
||||
namespace?.value.indexOf(']'));
|
||||
|
||||
bool get allowedToDisplay => isSubscribedMailbox || isDefault;
|
||||
|
||||
MailboxId? get mailboxId {
|
||||
if (id == PresentationMailbox.unifiedMailbox.id) {
|
||||
return null;
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
bool get pushNotificationDeactivated => isOutbox || isSent || isDrafts || isTrash || isSpam;
|
||||
|
||||
PresentationMailbox toPresentationMailboxWithMailboxPath(String mailboxPath) {
|
||||
return PresentationMailbox(
|
||||
id,
|
||||
|
||||
@@ -68,68 +68,6 @@ class PresentationMailbox with EquatableMixin {
|
||||
}
|
||||
);
|
||||
|
||||
bool get isActivated => state == MailboxState.activated;
|
||||
|
||||
bool hasParentId() => parentId != null && parentId!.id.value.isNotEmpty;
|
||||
|
||||
bool hasRole() => role != null && role!.value.isNotEmpty;
|
||||
|
||||
bool get isDefault => hasRole();
|
||||
|
||||
bool get isPersonal => namespace == null || namespace == Namespace('Personal');
|
||||
|
||||
bool get isTeamMailboxes => !isPersonal && !hasParentId();
|
||||
|
||||
bool get isChildOfTeamMailboxes => !isPersonal && hasParentId();
|
||||
|
||||
String getCountUnReadEmails() {
|
||||
if (unreadEmails == null || unreadEmails!.value.value <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return unreadEmails!.value.value <= 999 ? '${unreadEmails!.value.value}' : '999+';
|
||||
}
|
||||
|
||||
int get countEmails => totalEmails?.value.value.toInt() ?? 0;
|
||||
|
||||
bool get isSpam => role == roleSpam;
|
||||
|
||||
bool get isTrash => role == roleTrash;
|
||||
|
||||
bool get isDrafts => role == roleDrafts;
|
||||
|
||||
bool get isTemplates => role == roleTemplates;
|
||||
|
||||
bool get isSent => role == roleSent;
|
||||
|
||||
bool get isOutbox => name == lowerCaseOutboxMailboxName || role == roleOutbox;
|
||||
|
||||
bool get isSubscribedMailbox => isSubscribed != null && isSubscribed?.value == true;
|
||||
|
||||
bool matchCountingRules() {
|
||||
if (isTrash || isDrafts || isTemplates || isSent) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
String? get emailTeamMailBoxes => namespace?.value.substring(
|
||||
(namespace?.value.indexOf('[') ?? 0) + 1,
|
||||
namespace?.value.indexOf(']'));
|
||||
|
||||
bool get allowedToDisplay => isSubscribedMailbox || isDefault;
|
||||
|
||||
MailboxId? get mailboxId {
|
||||
if (id == unifiedMailbox.id) {
|
||||
return null;
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
bool get pushNotificationDeactivated => isOutbox || isSent || isDrafts || isTrash || isSpam;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
@@ -147,5 +85,6 @@ class PresentationMailbox with EquatableMixin {
|
||||
mailboxPath,
|
||||
state,
|
||||
namespace,
|
||||
displayName,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user