Files
workavia-mail-front/model/lib/extensions/mailbox_extension.dart
T
dab246 c279730309 TF-1705 Auto create default folder if missing on server CYRUS
Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit 1a5bad168cddf07662f4c682189840bc8c4bdcef)
2023-11-21 16:54:33 +07:00

59 lines
2.4 KiB
Dart

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() {
return PresentationMailbox(
id!,
name: name,
parentId: parentId,
role: role,
sortOrder: sortOrder,
totalEmails: totalEmails,
unreadEmails: unreadEmails,
totalThreads: totalThreads,
unreadThreads: unreadThreads,
myRights: myRights,
isSubscribed: isSubscribed,
namespace: namespace,
);
}
Mailbox combineMailbox(Mailbox newMailbox, Properties updatedProperties) {
return Mailbox(
id: newMailbox.id,
name: updatedProperties.contain(MailboxProperty.name) ? newMailbox.name : name,
parentId: updatedProperties.contain(MailboxProperty.parentId) ? newMailbox.parentId : parentId,
role: updatedProperties.contain(MailboxProperty.role) ? newMailbox.role : role,
sortOrder: updatedProperties.contain(MailboxProperty.sortOrder) ? newMailbox.sortOrder : sortOrder,
totalEmails: updatedProperties.contain(MailboxProperty.totalEmails) ? newMailbox.totalEmails : totalEmails,
unreadEmails: updatedProperties.contain(MailboxProperty.unreadEmails) ? newMailbox.unreadEmails : unreadEmails,
totalThreads: updatedProperties.contain(MailboxProperty.totalThreads) ? newMailbox.totalThreads : totalThreads,
unreadThreads: updatedProperties.contain(MailboxProperty.unreadThreads) ? newMailbox.unreadThreads : unreadThreads,
myRights: updatedProperties.contain(MailboxProperty.myRights) ? newMailbox.myRights : myRights,
isSubscribed: updatedProperties.contain(MailboxProperty.isSubscribed) ? newMailbox.isSubscribed : isSubscribed,
namespace: updatedProperties.contain(MailboxProperty.namespace) ? newMailbox.namespace : namespace,
);
}
Mailbox toMailbox(MailboxName mailboxName, {MailboxId? parentId, Role? mailboxRole}) {
return Mailbox(
id: id,
name: mailboxName,
parentId: parentId,
role: mailboxRole ?? role,
sortOrder: sortOrder,
totalEmails: totalEmails,
unreadEmails: unreadEmails,
totalThreads: totalThreads,
unreadThreads: unreadThreads,
myRights: myRights,
isSubscribed: isSubscribed,
namespace: namespace,
);
}
}