TF-1923 Fix duplicated store new email from push notification
(cherry picked from commit 076bbe249cc870b944a2dc40bc31012e061e0897)
This commit is contained in:
@@ -5,4 +5,6 @@ class NotFoundStoredNewEmailException implements Exception {}
|
||||
|
||||
class NotFoundStoredEmailException implements Exception {}
|
||||
|
||||
class OpenedEmailAlreadyStoredException implements Exception {}
|
||||
class OpenedEmailAlreadyStoredException implements Exception {}
|
||||
|
||||
class NewEmailAlreadyStoredException implements Exception {}
|
||||
@@ -5,6 +5,7 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_cache_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/detailed_email.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/store_new_email_state.dart';
|
||||
@@ -22,14 +23,31 @@ class StoreNewEmailInteractor {
|
||||
) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StoreNewEmailLoading());
|
||||
await Future.wait([
|
||||
_emailRepository.storeEmail(session, accountId, email),
|
||||
_emailRepository.storeDetailedNewEmail(session, accountId, detailedEmail),
|
||||
]);
|
||||
log('StoreNewEmailInteractor::execute():Store Success | EMAIL: ${detailedEmail.htmlEmailContent} | TIME: ${detailedEmail.createdTime}');
|
||||
yield Right<Failure, Success>(StoreNewEmailSuccess());
|
||||
final isNewEmailExist = await _isNewEmailAlreadyStored(session, accountId, detailedEmail);
|
||||
log('StoreNewEmailInteractor::execute():isNewEmailExist: $isNewEmailExist');
|
||||
if (!isNewEmailExist) {
|
||||
await Future.wait([
|
||||
_emailRepository.storeEmail(session, accountId, email),
|
||||
_emailRepository.storeDetailedNewEmail(session, accountId, detailedEmail),
|
||||
], eagerError: true);
|
||||
log('StoreNewEmailInteractor::execute():Store Success | EMAIL: ${detailedEmail.emailId} | TIME: ${detailedEmail.createdTime}');
|
||||
yield Right<Failure, Success>(StoreNewEmailSuccess());
|
||||
} else {
|
||||
log('StoreNewEmailInteractor::execute():Store Failure | EMAIL: ${detailedEmail.emailId} | TIME: ${detailedEmail.createdTime}');
|
||||
yield Left<Failure, Success>(StoreNewEmailFailure(NewEmailAlreadyStoredException()));
|
||||
}
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(StoreNewEmailFailure(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _isNewEmailAlreadyStored(Session session, AccountId accountId, DetailedEmail detailedEmail) async {
|
||||
try {
|
||||
await _emailRepository.getStoredNewEmail(session, accountId, detailedEmail.emailId);
|
||||
return true;
|
||||
} catch (err) {
|
||||
logError('StoreNewEmailInteractor::_isNewEmailAlreadyStored():EXCEPTION: $err');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,7 @@ class StoreOpenedEmailInteractor {
|
||||
|
||||
Future<bool> _isOpenedEmailAlreadyStored(Session session, AccountId accountId, DetailedEmail detailedEmail) async {
|
||||
try {
|
||||
final storedOpenEmail = await _emailRepository.getStoredOpenedEmail(session, accountId, detailedEmail.emailId);
|
||||
log('StoreOpenedEmailInteractor::isOpenedEmailAlreadyStored():storedOpenEmail: $storedOpenEmail');
|
||||
await _emailRepository.getStoredOpenedEmail(session, accountId, detailedEmail.emailId);
|
||||
return true;
|
||||
} catch (err) {
|
||||
logError('StoreOpenedEmailInteractor::isOpenedEmailAlreadyStored():EXCEPTION: $err');
|
||||
|
||||
Reference in New Issue
Block a user