TF-145 Implement refresh changes emails in mailbox
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/filter/filter.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/model/email_response.dart';
|
||||
@@ -19,4 +20,15 @@ abstract class ThreadRepository {
|
||||
MailboxId? inMailboxId
|
||||
}
|
||||
);
|
||||
|
||||
Stream<EmailResponse> refreshChanges(
|
||||
AccountId accountId,
|
||||
jmap.State currentState,
|
||||
{
|
||||
Set<Comparator>? sort,
|
||||
Properties? propertiesCreated,
|
||||
Properties? propertiesUpdated,
|
||||
MailboxId? inMailboxId
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -17,8 +17,6 @@ class MarkAsMultipleEmailReadInteractor {
|
||||
ReadActions readAction
|
||||
) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingState());
|
||||
|
||||
final listEmailNeedMarkAsRead = emails
|
||||
.where((email) => readAction == ReadActions.markAsUnread ? email.isReadEmail() : email.isUnReadEmail())
|
||||
.toList();
|
||||
|
||||
@@ -17,8 +17,6 @@ class MarkAsStarMultipleEmailInteractor {
|
||||
MarkStarAction markStarAction
|
||||
) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingState());
|
||||
|
||||
final listEmailNeedMarkStar = emails
|
||||
.where((email) => markStarAction == MarkStarAction.unMarkStar ? email.isFlaggedEmail() : !email.isFlaggedEmail())
|
||||
.toList();
|
||||
|
||||
@@ -14,8 +14,6 @@ class MoveMultipleEmailToMailboxInteractor {
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, MoveRequest moveRequest) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingState());
|
||||
|
||||
final result = await _emailRepository.moveToMailbox(accountId, moveRequest);
|
||||
|
||||
if (moveRequest.emailIds.length == result.length) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/model/email_response.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/repository/thread_repository.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/state/get_all_email_state.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
|
||||
class RefreshChangesEmailsInMailboxInteractor {
|
||||
final ThreadRepository threadRepository;
|
||||
|
||||
RefreshChangesEmailsInMailboxInteractor(this.threadRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
AccountId accountId,
|
||||
jmap.State currentState,
|
||||
{
|
||||
Set<Comparator>? sort,
|
||||
Properties? propertiesCreated,
|
||||
Properties? propertiesUpdated,
|
||||
MailboxId? inMailboxId
|
||||
}
|
||||
) async* {
|
||||
try {
|
||||
yield* threadRepository
|
||||
.refreshChanges(
|
||||
accountId,
|
||||
currentState,
|
||||
sort: sort,
|
||||
propertiesCreated: propertiesCreated,
|
||||
propertiesUpdated: propertiesUpdated,
|
||||
inMailboxId: inMailboxId)
|
||||
.map(_toGetEmailState);
|
||||
} catch (e) {
|
||||
yield Left(GetAllEmailFailure(e));
|
||||
}
|
||||
}
|
||||
|
||||
Either<Failure, Success> _toGetEmailState(EmailResponse emailResponse) {
|
||||
final presentationEmailList = emailResponse.emailList
|
||||
?.map((email) => email.toPresentationEmail()).toList() ?? List.empty();
|
||||
|
||||
return Right<Failure, Success>(GetAllEmailSuccess(
|
||||
emailList: presentationEmailList,
|
||||
currentEmailState: emailResponse.state));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user