Add model PresentationEmail
This commit is contained in:
@@ -1,17 +1,86 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
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/core/utc_date.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:model/mailbox/select_mode.dart';
|
||||
import 'package:model/extensions/email_address_extension.dart';
|
||||
|
||||
class PresentationThread with EquatableMixin {
|
||||
class PresentationEmail with EquatableMixin {
|
||||
|
||||
final String id;
|
||||
final String? message;
|
||||
static PresentationEmail presentationEmailEmpty = PresentationEmail(EmailId(Id('empty')));
|
||||
|
||||
PresentationThread(this.id, {this.message});
|
||||
final EmailId id;
|
||||
final Map<KeyWordIdentifier, bool>? keywords;
|
||||
final UnsignedInt? size;
|
||||
final UTCDate? receivedAt;
|
||||
final bool? hasAttachment;
|
||||
final String? preview;
|
||||
final String? subject;
|
||||
final UTCDate? sentAt;
|
||||
final Set<EmailAddress>? from;
|
||||
final Set<EmailAddress>? to;
|
||||
final Set<EmailAddress>? cc;
|
||||
final Set<EmailAddress>? bcc;
|
||||
final Set<EmailAddress>? replyTo;
|
||||
final SelectMode selectMode;
|
||||
|
||||
factory PresentationThread.createThreadEmpty() {
|
||||
return PresentationThread('empty');
|
||||
PresentationEmail(
|
||||
this.id,
|
||||
{
|
||||
this.keywords,
|
||||
this.size,
|
||||
this.receivedAt,
|
||||
this.hasAttachment,
|
||||
this.preview,
|
||||
this.subject,
|
||||
this.sentAt,
|
||||
this.from,
|
||||
this.to,
|
||||
this.cc,
|
||||
this.bcc,
|
||||
this.replyTo,
|
||||
this.selectMode = SelectMode.INACTIVE
|
||||
}
|
||||
);
|
||||
|
||||
String getSenderName() {
|
||||
if (from != null && from!.isNotEmpty) {
|
||||
return from!.first.asString();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
String getEmailTitle() => subject != null ? subject! : '';
|
||||
|
||||
String getPartialContent() => preview != null ? preview! : '';
|
||||
|
||||
String getTimeForToday() => receivedAt != null ? DateFormat('h:mm a').format(receivedAt!.value) : '';
|
||||
|
||||
String getTimeForYesterday() => receivedAt != null ? DateFormat('EEE').format(receivedAt!.value) : '';
|
||||
|
||||
String getTimeThisYear() => receivedAt != null ? DateFormat('MMMd').format(receivedAt!.value) : '';
|
||||
|
||||
String getTimeOtherYear() => receivedAt != null ? DateFormat('yMMMd').format(receivedAt!.value) : '';
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, message];
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
subject,
|
||||
from,
|
||||
to,
|
||||
cc,
|
||||
bcc,
|
||||
keywords,
|
||||
size,
|
||||
receivedAt,
|
||||
sentAt,
|
||||
replyTo,
|
||||
preview,
|
||||
hasAttachment
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
|
||||
extension EmailAddressExtension on EmailAddress {
|
||||
|
||||
String asString() {
|
||||
if (name != null && name!.isNotEmpty) {
|
||||
return name!;
|
||||
} else if (email != null && email!.isNotEmpty) {
|
||||
return email!;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import 'package:model/mailbox/select_mode.dart';
|
||||
|
||||
class PresentationMailbox with EquatableMixin {
|
||||
|
||||
static PresentationMailbox presentationMailboxEmpty = PresentationMailbox(MailboxId(Id('empty')));
|
||||
|
||||
final MailboxId id;
|
||||
final MailboxName? name;
|
||||
final MailboxId? parentId;
|
||||
@@ -36,10 +38,6 @@ class PresentationMailbox with EquatableMixin {
|
||||
}
|
||||
);
|
||||
|
||||
factory PresentationMailbox.createMailboxEmpty() {
|
||||
return PresentationMailbox(MailboxId(Id("empty")));
|
||||
}
|
||||
|
||||
bool hasParentId() => parentId != null && parentId!.id.value.isNotEmpty;
|
||||
|
||||
bool hasRole() => role != null && role!.value.isNotEmpty;
|
||||
|
||||
@@ -15,3 +15,6 @@ export 'mailbox/expand_mode.dart';
|
||||
|
||||
// Email
|
||||
export 'email/presentation_email.dart';
|
||||
|
||||
// Extensions
|
||||
export 'extensions/email_address_extension.dart';
|
||||
+5
-6
@@ -34,11 +34,14 @@ dependencies:
|
||||
# quiver
|
||||
quiver: 3.0.1
|
||||
|
||||
# intl
|
||||
intl: 0.17.0
|
||||
|
||||
# jmap_dart_client
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: git://github.com/dab246/jmap-dart-client.git
|
||||
ref: fixbug_get_session
|
||||
url: git://github.com/linagora/jmap-dart-client.git
|
||||
ref: master
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
@@ -93,7 +96,3 @@ flutter:
|
||||
# maintain consistency when adding or modifying assets and plugins.
|
||||
# They also do not have any bearing on your native host application's
|
||||
# identifiers, which may be completely independent or the same as these.
|
||||
module:
|
||||
androidX: true
|
||||
androidPackage: com.linagora.android.tmail.model
|
||||
iosBundleIdentifier: com.linagora.android.tmail.model
|
||||
|
||||
+2
-2
@@ -77,8 +77,8 @@ dependencies:
|
||||
# jmap_dart_client
|
||||
jmap_dart_client:
|
||||
git:
|
||||
url: git://github.com/dab246/jmap-dart-client.git
|
||||
ref: fixbug_get_session
|
||||
url: git://github.com/linagora/jmap-dart-client.git
|
||||
ref: master
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user