Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add presentation layer for get EmailContent
- Loading branch information
Showing
36 changed files
with
849 additions
and
120 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
lib/features/email/presentation/constants/email_contants.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
class EmailConstants { | ||
static const HTML_TEXT = 'text/html'; | ||
static const PLAIN_TEXT = 'text/plain'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import 'package:core/presentation/utils/responsive_utils.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:tmail_ui_user/features/email/data/datasource/email_datasource.dart'; | ||
import 'package:tmail_ui_user/features/email/data/datasource_impl/email_datasource_impl.dart'; | ||
import 'package:tmail_ui_user/features/email/data/network/email_api.dart'; | ||
import 'package:tmail_ui_user/features/email/data/repository/email_repository_impl.dart'; | ||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart'; | ||
import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart'; | ||
import 'package:tmail_ui_user/features/email/presentation/email_controller.dart'; | ||
|
||
class EmailBindings extends Bindings { | ||
@override | ||
void dependencies() { | ||
Get.lazyPut(() => EmailController(Get.find<ResponsiveUtils>())); | ||
Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>())); | ||
Get.lazyPut<EmailDataSource>(() => Get.find<EmailDataSourceImpl>()); | ||
Get.lazyPut(() => EmailRepositoryImpl(Get.find<EmailDataSource>())); | ||
Get.lazyPut<EmailRepository>(() => Get.find<EmailRepositoryImpl>()); | ||
Get.lazyPut(() => GetEmailContentInteractor(Get.find<EmailRepository>())); | ||
Get.lazyPut(() => EmailController( | ||
Get.find<ResponsiveUtils>(), | ||
Get.find<GetEmailContentInteractor>())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
lib/features/email/presentation/extensions/email_body_part_extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart'; | ||
import 'package:tmail_ui_user/features/email/presentation/model/attachment_file.dart'; | ||
|
||
extension EmailBodyPartExtension on EmailBodyPart { | ||
AttachmentFile toAttachmentFile() => AttachmentFile(partId, blobId, size, name, type); | ||
} |
39 changes: 39 additions & 0 deletions
39
lib/features/email/presentation/extensions/email_content_extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart'; | ||
import 'package:model/email/email_content.dart'; | ||
import 'package:tmail_ui_user/features/email/presentation/constants/email_contants.dart'; | ||
import 'package:tmail_ui_user/features/email/presentation/model/attachment_file.dart'; | ||
import 'package:tmail_ui_user/features/email/presentation/model/message_content.dart'; | ||
import 'package:tmail_ui_user/features/email/presentation/model/text_format.dart'; | ||
import 'package:tmail_ui_user/features/email/presentation/extensions/email_body_part_extension.dart'; | ||
|
||
extension EmailContentExtension on EmailContent { | ||
|
||
List<MessageContent> getListMessageContent() { | ||
Map<PartId, TextFormat> mapHtmlBody = Map(); | ||
List<MessageContent> listMessageContent = []; | ||
|
||
htmlBody?.forEach((element) { | ||
if (element.partId != null && element.type != null) { | ||
mapHtmlBody[element.partId!] = element.type!.mimeType == EmailConstants.HTML_TEXT | ||
? TextFormat.HTML | ||
: TextFormat.PLAIN; | ||
} | ||
}); | ||
|
||
bodyValues?.forEach((key, value) { | ||
listMessageContent.add(MessageContent(mapHtmlBody[key] ?? TextFormat.PLAIN, value.value)); | ||
}); | ||
|
||
return listMessageContent; | ||
} | ||
|
||
List<AttachmentFile> getListAttachment() { | ||
if (attachments != null) { | ||
return attachments! | ||
.where((element) => element.disposition != 'inline') | ||
.map((item) => item.toAttachmentFile()) | ||
.toList(); | ||
} | ||
return []; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
lib/features/email/presentation/extensions/presentation_email_extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:intl/intl.dart'; | ||
import 'package:model/model.dart'; | ||
|
||
extension PresentationEmailExtension on PresentationEmail { | ||
|
||
String getNameReceiver() { | ||
if (to != null) { | ||
final listNameEmail = to!.map((emailAddress) => emailAddress.getNameEmail()).toList(); | ||
return listNameEmail.join(', '); | ||
} | ||
return ''; | ||
} | ||
|
||
String getNameReceiverCc() { | ||
if (cc != null) { | ||
final listNameEmail = cc!.map((emailAddress) => emailAddress.getNameEmail()).toList(); | ||
return listNameEmail.join(', '); | ||
} | ||
return ''; | ||
} | ||
|
||
String getNameReceiverBcc() { | ||
if (bcc != null) { | ||
final listNameEmail = bcc!.map((emailAddress) => emailAddress.getNameEmail()).toList(); | ||
return listNameEmail.join(', '); | ||
} | ||
return ''; | ||
} | ||
|
||
String getTimeSent() => sentAt != null ? DateFormat('dd/MM/yyyy h:mm a').format(sentAt!.value) : ''; | ||
} |
Oops, something went wrong.