TF-2628 [Part-2] Add attachmentsViewState to track attachments' action
This commit is contained in:
@@ -122,6 +122,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
final eventActions = <EventAction>[].obs;
|
final eventActions = <EventAction>[].obs;
|
||||||
final emailLoadedViewState = Rx<Either<Failure, Success>>(Right(UIState.idle));
|
final emailLoadedViewState = Rx<Either<Failure, Success>>(Right(UIState.idle));
|
||||||
final emailUnsubscribe = Rxn<EmailUnsubscribe>();
|
final emailUnsubscribe = Rxn<EmailUnsubscribe>();
|
||||||
|
final attachmentsViewState = RxMap<Id, Either<Failure, Success>>();
|
||||||
|
|
||||||
EmailId? _currentEmailId;
|
EmailId? _currentEmailId;
|
||||||
Identity? _identitySelected;
|
Identity? _identitySelected;
|
||||||
@@ -181,8 +182,16 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
_markAsEmailStarSuccess(success);
|
_markAsEmailStarSuccess(success);
|
||||||
} else if (success is ViewAttachmentForWebSuccess) {
|
} else if (success is ViewAttachmentForWebSuccess) {
|
||||||
_viewAttachmentForWebSuccessAction(success);
|
_viewAttachmentForWebSuccessAction(success);
|
||||||
|
} else if (success is StartViewAttachmentForWeb) {
|
||||||
|
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||||
|
} else if (success is ViewingAttachmentForWeb) {
|
||||||
|
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||||
} else if (success is DownloadAttachmentForWebSuccess) {
|
} else if (success is DownloadAttachmentForWebSuccess) {
|
||||||
_downloadAttachmentForWebSuccessAction(success);
|
_downloadAttachmentForWebSuccessAction(success);
|
||||||
|
} else if (success is StartDownloadAttachmentForWeb) {
|
||||||
|
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||||
|
} else if (success is DownloadingAttachmentForWeb) {
|
||||||
|
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||||
} else if (success is GetAllIdentitiesSuccess) {
|
} else if (success is GetAllIdentitiesSuccess) {
|
||||||
_getAllIdentitiesSuccess(success);
|
_getAllIdentitiesSuccess(success);
|
||||||
} else if (success is SendReceiptToSenderSuccess) {
|
} else if (success is SendReceiptToSenderSuccess) {
|
||||||
@@ -450,6 +459,10 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
|
|
||||||
if (success.emailCurrent?.id == currentEmail?.id) {
|
if (success.emailCurrent?.id == currentEmail?.id) {
|
||||||
attachments.value = success.attachments;
|
attachments.value = success.attachments;
|
||||||
|
attachmentsViewState.value = {
|
||||||
|
for (var attachment in attachments.where((item) => item.blobId != null))
|
||||||
|
attachment.blobId!: Right(IdleDownloadAttachmentForWeb())
|
||||||
|
};
|
||||||
|
|
||||||
if (_canParseCalendarEvent(blobIds: success.attachments.calendarEventBlobIds)) {
|
if (_canParseCalendarEvent(blobIds: success.attachments.calendarEventBlobIds)) {
|
||||||
_parseCalendarEventAction(
|
_parseCalendarEventAction(
|
||||||
@@ -490,6 +503,10 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
|
|
||||||
if (success.emailCurrent?.id == currentEmail?.id) {
|
if (success.emailCurrent?.id == currentEmail?.id) {
|
||||||
attachments.value = success.attachments;
|
attachments.value = success.attachments;
|
||||||
|
attachmentsViewState.value = {
|
||||||
|
for (var attachment in attachments.where((item) => item.blobId != null))
|
||||||
|
attachment.blobId!: Right(IdleDownloadAttachmentForWeb())
|
||||||
|
};
|
||||||
|
|
||||||
if (_canParseCalendarEvent(blobIds: success.attachments.calendarEventBlobIds)) {
|
if (_canParseCalendarEvent(blobIds: success.attachments.calendarEventBlobIds)) {
|
||||||
_parseCalendarEventAction(
|
_parseCalendarEventAction(
|
||||||
@@ -556,6 +573,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
emailContents.value = null;
|
emailContents.value = null;
|
||||||
_currentEmailLoaded = null;
|
_currentEmailLoaded = null;
|
||||||
attachments.clear();
|
attachments.clear();
|
||||||
|
attachmentsViewState.value = {};
|
||||||
calendarEvent.value = null;
|
calendarEvent.value = null;
|
||||||
eventActions.clear();
|
eventActions.clear();
|
||||||
emailUnsubscribe.value = null;
|
emailUnsubscribe.value = null;
|
||||||
@@ -745,7 +763,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
} else {
|
} else {
|
||||||
consumeState(Stream.value(
|
consumeState(Stream.value(
|
||||||
Left(DownloadAttachmentForWebFailure(
|
Left(DownloadAttachmentForWebFailure(
|
||||||
attachment: attachment,
|
attachmentBlobId: attachment.blobId,
|
||||||
exception: NotFoundSessionException()))
|
exception: NotFoundSessionException()))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -766,7 +784,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
} else {
|
} else {
|
||||||
consumeState(Stream.value(
|
consumeState(Stream.value(
|
||||||
Left(ViewAttachmentForWebFailure(
|
Left(ViewAttachmentForWebFailure(
|
||||||
attachment: attachment,
|
attachmentBlobId: attachment.blobId,
|
||||||
exception: NotFoundSessionException()))
|
exception: NotFoundSessionException()))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -774,6 +792,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
|
|
||||||
void _downloadAttachmentForWebSuccessAction(DownloadAttachmentForWebSuccess success) {
|
void _downloadAttachmentForWebSuccessAction(DownloadAttachmentForWebSuccess success) {
|
||||||
log('SingleEmailController::_downloadAttachmentForWebSuccessAction():');
|
log('SingleEmailController::_downloadAttachmentForWebSuccessAction():');
|
||||||
|
|
||||||
|
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||||
|
|
||||||
mailboxDashBoardController.deleteDownloadTask(success.taskId);
|
mailboxDashBoardController.deleteDownloadTask(success.taskId);
|
||||||
|
|
||||||
_downloadManager.createAnchorElementDownloadFileWeb(
|
_downloadManager.createAnchorElementDownloadFileWeb(
|
||||||
@@ -792,6 +813,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||||
|
|
||||||
mailboxDashBoardController.deleteDownloadTask(success.taskId);
|
mailboxDashBoardController.deleteDownloadTask(success.taskId);
|
||||||
|
|
||||||
_downloadManager.openDownloadedFileWeb(
|
_downloadManager.openDownloadedFileWeb(
|
||||||
@@ -805,6 +828,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
mailboxDashBoardController.deleteDownloadTask(failure.taskId!);
|
mailboxDashBoardController.deleteDownloadTask(failure.taskId!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updateAttachmentsViewState(failure.attachmentBlobId, Left(failure));
|
||||||
|
|
||||||
if (currentOverlayContext != null && currentContext != null) {
|
if (currentOverlayContext != null && currentContext != null) {
|
||||||
appToast.showToastErrorMessage(
|
appToast.showToastErrorMessage(
|
||||||
currentOverlayContext!,
|
currentOverlayContext!,
|
||||||
@@ -817,6 +842,14 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
_downloadAttachmentForWebFailureAction(failure);
|
_downloadAttachmentForWebFailureAction(failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _updateAttachmentsViewState(
|
||||||
|
Id? attachmentBlobId,
|
||||||
|
Either<Failure, Success> viewState) {
|
||||||
|
if (attachmentBlobId != null) {
|
||||||
|
attachmentsViewState[attachmentBlobId] = viewState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void moveToMailbox(BuildContext context, PresentationEmail email) async {
|
void moveToMailbox(BuildContext context, PresentationEmail email) async {
|
||||||
final currentMailbox = getMailboxContain(email);
|
final currentMailbox = getMailboxContain(email);
|
||||||
final accountId = mailboxDashBoardController.accountId.value;
|
final accountId = mailboxDashBoardController.accountId.value;
|
||||||
|
|||||||
Reference in New Issue
Block a user