TF-48 Create and update object for compose email
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class AccountRequest with EquatableMixin {
|
||||
final UserName userName;
|
||||
final Password password;
|
||||
|
||||
AccountRequest(this.userName, this.password);
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'username': userName.userName,
|
||||
'password': password.value,
|
||||
};
|
||||
|
||||
@override
|
||||
List<Object> get props => [userName, password];
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class Attribute {
|
||||
static const id = '_id';
|
||||
static const firstname = 'firstname';
|
||||
static const lastname = 'lastname';
|
||||
static const job_title = 'job_title';
|
||||
static const building_location = 'building_location';
|
||||
static const office_location = 'office_location';
|
||||
static const main_phone = 'main_phone';
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
part 'presentation_account_response.g.dart';
|
||||
|
||||
@PresentationEmailAddressConverter()
|
||||
@JsonSerializable()
|
||||
class PresentationAccountResponse with EquatableMixin {
|
||||
final List<PresentationEmailAddress>? emails;
|
||||
final int preferredEmailIndex;
|
||||
final AccountType type;
|
||||
|
||||
PresentationAccountResponse(this.emails, this.preferredEmailIndex, this.type);
|
||||
|
||||
factory PresentationAccountResponse.fromJson(Map<String, dynamic> json) => _$PresentationAccountResponseFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$PresentationAccountResponseToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [emails, preferredEmailIndex, type];
|
||||
}
|
||||
|
||||
extension PresentationAccountResponseExtension on PresentationAccountResponse {
|
||||
PresentationAccount toPresentationAccount() {
|
||||
return PresentationAccount(emails ?? [], preferredEmailIndex, type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class AvatarIdConverter implements JsonConverter<AvatarId, String> {
|
||||
const AvatarIdConverter();
|
||||
|
||||
@override
|
||||
AvatarId fromJson(String json) => AvatarId(json);
|
||||
|
||||
@override
|
||||
String toJson(AvatarId object) => object.id;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class AvatarIdNullableConverter implements JsonConverter<AvatarId?, String?> {
|
||||
const AvatarIdNullableConverter();
|
||||
|
||||
@override
|
||||
AvatarId? fromJson(String? json) => json != null ? AvatarId(json) : AvatarId.initial();
|
||||
|
||||
@override
|
||||
String? toJson(AvatarId? object) => object?.id;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class PresentationEmailAddressConverter implements JsonConverter<PresentationEmailAddress, String> {
|
||||
const PresentationEmailAddressConverter();
|
||||
|
||||
@override
|
||||
PresentationEmailAddress fromJson(String json) => PresentationEmailAddress(json);
|
||||
|
||||
@override
|
||||
String toJson(PresentationEmailAddress object) => object.email;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class UserIdConverter implements JsonConverter<UserId, String> {
|
||||
const UserIdConverter();
|
||||
|
||||
@override
|
||||
UserId fromJson(String json) => UserId(json);
|
||||
|
||||
@override
|
||||
String toJson(UserId object) => object.id;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
import 'package:core/data/local/config/email_address_table.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'email_address_cache.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class EmailAddressCache with EquatableMixin {
|
||||
|
||||
@JsonKey(name: EmailAddressTable.NAME)
|
||||
final String name;
|
||||
@JsonKey(name: EmailAddressTable.EMAIL)
|
||||
final String email;
|
||||
|
||||
EmailAddressCache(this.name, this.email);
|
||||
|
||||
factory EmailAddressCache.fromJson(Map<String, dynamic> json) => _$EmailAddressCacheFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$EmailAddressCacheToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [name, email];
|
||||
}
|
||||
|
||||
extension EmailAddressCacheExtension on EmailAddressCache {
|
||||
EmailAddress toEmailAddress() => EmailAddress(name, email);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/email/email_address_cache.dart';
|
||||
|
||||
extension EmailAddressExtension on EmailAddress {
|
||||
|
||||
@@ -26,4 +27,6 @@ extension EmailAddressExtension on EmailAddress {
|
||||
String getEmail() => email != null ? email! : '';
|
||||
|
||||
String getName() => name != null ? name! : '';
|
||||
|
||||
EmailAddressCache toEmailAddressCache() => EmailAddressCache(name ?? '', email ?? '');
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
extension EmailExtension on Email {
|
||||
|
||||
Set<String> getRecipientEmailAddressList() {
|
||||
final listEmailAddress = Set<String>();
|
||||
final listToAddress = to.getListAddress() ?? [];
|
||||
final listCcAddress = cc.getListAddress() ?? [];
|
||||
final listBccAddress = bcc.getListAddress() ?? [];
|
||||
listEmailAddress.addAll(listToAddress + listCcAddress + listBccAddress);
|
||||
return listEmailAddress;
|
||||
}
|
||||
|
||||
EmailContent toEmailContent() {
|
||||
return EmailContent(
|
||||
id,
|
||||
htmlBody: htmlBody,
|
||||
attachments: attachments,
|
||||
bodyValues: bodyValues
|
||||
);
|
||||
}
|
||||
|
||||
PresentationEmail toPresentationEmail({SelectMode selectMode = SelectMode.INACTIVE}) {
|
||||
return PresentationEmail(
|
||||
id,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
hasAttachment: hasAttachment,
|
||||
preview: preview,
|
||||
subject: subject,
|
||||
sentAt: sentAt,
|
||||
from: from,
|
||||
to: to,
|
||||
cc: cc,
|
||||
bcc: bcc,
|
||||
replyTo: replyTo,
|
||||
selectMode: selectMode
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import 'package:model/extensions/email_address_extension.dart';
|
||||
|
||||
extension ListEmailAddressExtension on Set<EmailAddress>? {
|
||||
|
||||
List<String>? getListAddress() => this?.map((emailAddress) => emailAddress.getEmail()).toList();
|
||||
|
||||
List<String> getListEmailAddress({ExpandMode expandMode = ExpandMode.EXPAND, int limitAddress = 1, bool isFullEmailAddress = false}) {
|
||||
if (this != null) {
|
||||
if (expandMode == ExpandMode.EXPAND) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import 'package:model/model.dart';
|
||||
|
||||
extension PresentationAccountExtension on PresentationAccount {
|
||||
PresentationAccountResponse toPresentationAccountResponse() {
|
||||
return PresentationAccountResponse(emails, preferredEmailIndex, type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
extension PresentationEmailExtension on PresentationEmail {
|
||||
|
||||
int numberOfAllEmailAddress() => to.numberEmailAddress() + cc.numberEmailAddress() + bcc.numberEmailAddress();
|
||||
|
||||
String getEmailDateTime(String newLocale, {String? pattern}) {
|
||||
final emailTime = sentAt ?? receivedAt;
|
||||
if (emailTime != null) {
|
||||
return emailTime.formatDate(pattern: pattern ?? emailTime.value.toPattern(), locale: newLocale);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:model/model.dart';
|
||||
|
||||
extension UserProfileExtension on UserProfile {
|
||||
UserProfileResponse toUserProfileResponse() {
|
||||
return UserProfileResponse(
|
||||
id,
|
||||
firstName,
|
||||
lastName,
|
||||
jobTitle,
|
||||
service,
|
||||
buildingLocation,
|
||||
officeLocation,
|
||||
mainPhone,
|
||||
description,
|
||||
currentAvatar,
|
||||
avatars,
|
||||
accounts.map((account) => account.toPresentationAccountResponse()).toList()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,11 @@ import 'package:model/mailbox/select_mode.dart';
|
||||
|
||||
class PresentationMailbox with EquatableMixin {
|
||||
|
||||
static final roleInbox = Role('inbox');
|
||||
static final roleTrash = Role('trash');
|
||||
static final roleSent = Role('sent');
|
||||
static final roleTemplates = Role('templates');
|
||||
static final roleOutbox = Role('outbox');
|
||||
|
||||
final MailboxId id;
|
||||
final MailboxName? name;
|
||||
@@ -44,10 +46,6 @@ class PresentationMailbox with EquatableMixin {
|
||||
bool hasRole() => role != null && role!.value.isNotEmpty;
|
||||
|
||||
String getCountUnReadEmails() {
|
||||
if (role == roleTrash || role == roleSent || role == roleTemplates) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (unreadEmails == null || unreadEmails!.value.value <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
+16
-1
@@ -5,11 +5,15 @@ export 'account/user_name.dart';
|
||||
export 'account/password.dart';
|
||||
export 'account/account_type.dart';
|
||||
export 'account/presentation_account.dart';
|
||||
export 'account/presentation_account_response.dart';
|
||||
export 'account/attribute.dart';
|
||||
export 'account/account_request.dart';
|
||||
|
||||
// User
|
||||
export 'user/user_id.dart';
|
||||
export 'user/user_profile.dart';
|
||||
export 'user/avatar_id.dart';
|
||||
export 'user/user_profile_response.dart';
|
||||
|
||||
// Mailbox
|
||||
export 'mailbox/presentation_mailbox.dart';
|
||||
@@ -22,9 +26,20 @@ export 'email/email_content.dart';
|
||||
export 'email/prefix_email_address.dart';
|
||||
export 'email/email_action_type.dart';
|
||||
export 'email/presentation_email_address.dart';
|
||||
export 'email/email_address_cache.dart';
|
||||
|
||||
// Extensions
|
||||
export 'extensions/email_address_extension.dart';
|
||||
export 'extensions/list_email_address_extension.dart';
|
||||
export 'extensions/session_extension.dart';
|
||||
export 'extensions/utcdate_extension.dart';
|
||||
export 'extensions/utc_date_extension.dart';
|
||||
export 'extensions/email_extension.dart';
|
||||
export 'extensions/presentation_account_extension.dart';
|
||||
export 'extensions/user_profile_extension.dart';
|
||||
export 'extensions/presentation_email_extension.dart';
|
||||
|
||||
// Converter
|
||||
export 'converter/avatar_id_converter.dart';
|
||||
export 'converter/avatar_id_nullable_converter.dart';
|
||||
export 'converter/presentation_email_address_converter.dart';
|
||||
export 'converter/user_id_converter.dart';
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
part 'user_profile_response.g.dart';
|
||||
|
||||
@AvatarIdNullableConverter()
|
||||
@AvatarIdConverter()
|
||||
@UserIdConverter()
|
||||
@JsonSerializable()
|
||||
class UserProfileResponse with EquatableMixin {
|
||||
|
||||
@JsonKey(name: Attribute.id, includeIfNull: false)
|
||||
final UserId id;
|
||||
@JsonKey(name: Attribute.firstname, includeIfNull: false)
|
||||
final String? firstName;
|
||||
@JsonKey(name: Attribute.lastname, includeIfNull: false)
|
||||
final String? lastName;
|
||||
@JsonKey(name: Attribute.job_title, includeIfNull: false)
|
||||
final String? jobTitle;
|
||||
@JsonKey(includeIfNull: false)
|
||||
final String? service;
|
||||
@JsonKey(name: Attribute.building_location, includeIfNull: false)
|
||||
final String? buildingLocation;
|
||||
@JsonKey(name: Attribute.office_location, includeIfNull: false)
|
||||
final String? officeLocation;
|
||||
@JsonKey(name: Attribute.main_phone, includeIfNull: false)
|
||||
final String? mainPhone;
|
||||
@JsonKey(includeIfNull: false)
|
||||
final String? description;
|
||||
@JsonKey(includeIfNull: false)
|
||||
final AvatarId? currentAvatar;
|
||||
@JsonKey(includeIfNull: false)
|
||||
final List<AvatarId>? avatars;
|
||||
@JsonKey(includeIfNull: false)
|
||||
final List<PresentationAccountResponse>? accounts;
|
||||
|
||||
UserProfileResponse(
|
||||
this.id,
|
||||
this.firstName,
|
||||
this.lastName,
|
||||
this.jobTitle,
|
||||
this.service,
|
||||
this.buildingLocation,
|
||||
this.officeLocation,
|
||||
this.mainPhone,
|
||||
this.description,
|
||||
this.currentAvatar,
|
||||
this.avatars,
|
||||
this.accounts
|
||||
);
|
||||
|
||||
factory UserProfileResponse.fromJson(Map<String, dynamic> json) => _$UserProfileResponseFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$UserProfileResponseToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
firstName,
|
||||
lastName,
|
||||
accounts,
|
||||
];
|
||||
}
|
||||
|
||||
extension UserProfileResponseExtension on UserProfileResponse {
|
||||
UserProfile toUserProfile() {
|
||||
return UserProfile(
|
||||
id,
|
||||
firstName ?? '',
|
||||
lastName ?? '',
|
||||
jobTitle ?? '',
|
||||
service ?? '',
|
||||
buildingLocation ?? '',
|
||||
officeLocation ?? '',
|
||||
mainPhone ?? '',
|
||||
description ?? '',
|
||||
currentAvatar ?? AvatarId.initial(),
|
||||
avatars ?? [],
|
||||
accounts != null ? accounts!.map((account) => account.toPresentationAccount()).toList() : []
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,9 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
core:
|
||||
path: ../core
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.2
|
||||
@@ -46,11 +49,16 @@ dependencies:
|
||||
# uri
|
||||
uri: 1.0.0
|
||||
|
||||
# json_annotation
|
||||
json_annotation: 4.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
build_runner: 2.0.5
|
||||
|
||||
json_serializable: 4.1.3
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
|
||||
Reference in New Issue
Block a user