Skip to content

Commit

Permalink
TF-3334 Remove Email/get of unsubscribe email action
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Dec 18, 2024
1 parent 433c791 commit 9604036
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/features/email/data/datasource/email_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ abstract class EmailDataSource {

Future<SendingEmail> getStoredSendingEmail(AccountId accountId, UserName userName, String sendingId);

Future<Email> unsubscribeMail(Session session, AccountId accountId, EmailId emailId);
Future<void> unsubscribeMail(Session session, AccountId accountId, EmailId emailId);

Future<EmailRecoveryAction> restoreDeletedMessage(RestoredDeletedMessageRequest restoredDeletedMessageRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class EmailDataSourceImpl extends EmailDataSource {
}

@override
Future<Email> unsubscribeMail(Session session, AccountId accountId, EmailId emailId) {
Future<void> unsubscribeMail(Session session, AccountId accountId, EmailId emailId) {
return Future.sync(() async {
return await emailAPI.unsubscribeMail(session, accountId, emailId);
}).catchError(_exceptionThrower.throwException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
}

@override
Future<Email> unsubscribeMail(Session session, AccountId accountId, EmailId emailId) {
Future<void> unsubscribeMail(Session session, AccountId accountId, EmailId emailId) {
throw UnimplementedError();
}

Expand Down
27 changes: 14 additions & 13 deletions lib/features/email/data/network/email_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -678,17 +678,13 @@ class EmailAPI with HandleSetErrorMixin {
}
}

Future<Email> unsubscribeMail(Session session, AccountId accountId, EmailId emailId) async {
Future<void> unsubscribeMail(Session session, AccountId accountId, EmailId emailId) async {
final setEmailMethod = SetEmailMethod(accountId)
..addUpdates(emailId.generateMapUpdateObjectUnsubscribeMail());

final getEmailMethod = GetEmailMethod(accountId)
..addIds({emailId.id})
..addProperties(ThreadConstants.propertiesDefault);

final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
requestBuilder.invocation(setEmailMethod);
final getEmailInvocation = requestBuilder.invocation(getEmailMethod);
final setEmailInvocation = requestBuilder.invocation(setEmailMethod);

final capabilities = setEmailMethod.requiredCapabilities.toCapabilitiesSupportTeamMailboxes(session, accountId);

Expand All @@ -697,14 +693,19 @@ class EmailAPI with HandleSetErrorMixin {
.build()
.execute();

final getEmailResponse = response.parse<GetEmailResponse>(
getEmailInvocation.methodCallId,
GetEmailResponse.deserialize);
final setEmailResponse = response.parse<SetEmailResponse>(
setEmailInvocation.methodCallId,
SetEmailResponse.deserialize,
);

if (getEmailResponse?.list.isNotEmpty == true) {
return getEmailResponse!.list.first;
} else {
throw NotFoundEmailException();
final emailIdUpdated = setEmailResponse?.updated
?.keys
.map((id) => EmailId(id))
.toList() ?? [];
final mapErrors = handleSetResponse([setEmailResponse]);

if (emailIdUpdated.isEmpty) {
throw SetMethodException(mapErrors);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class EmailRepositoryImpl extends EmailRepository {
}

@override
Future<Email> unsubscribeMail(Session session, AccountId accountId, EmailId emailId) {
Future<void> unsubscribeMail(Session session, AccountId accountId, EmailId emailId) {
return emailDataSource[DataSourceType.network]!.unsubscribeMail(session, accountId, emailId);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/features/email/domain/repository/email_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ abstract class EmailRepository {
TransformConfiguration configuration
);

Future<Email> unsubscribeMail(Session session, AccountId accountId, EmailId emailId);
Future<void> unsubscribeMail(Session session, AccountId accountId, EmailId emailId);

Future<EmailRecoveryAction> restoreDeletedMessage(RestoredDeletedMessageRequest restoredDeletedMessageRequest);

Expand Down
7 changes: 0 additions & 7 deletions lib/features/email/domain/state/unsubscribe_email_state.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/base/state/ui_action_state.dart';

class UnsubscribeEmailLoading extends LoadingState {}

class UnsubscribeEmailSuccess extends UIActionState {
final Email newEmail;

UnsubscribeEmailSuccess(
this.newEmail,
{
jmap.State? currentEmailState,
jmap.State? currentMailboxState,
}
) : super(currentEmailState, currentMailboxState);

@override
List<Object?> get props => [newEmail, ...super.props];
}

class UnsubscribeEmailFailure extends FeatureFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class UnsubscribeEmailInteractor {
try {
yield Right(UnsubscribeEmailLoading());
final currentEmailState = await emailRepository.getEmailState(session, accountId);
final newEmail = await emailRepository.unsubscribeMail(session, accountId, emailId);
yield Right(UnsubscribeEmailSuccess(newEmail, currentEmailState: currentEmailState));
await emailRepository.unsubscribeMail(session, accountId, emailId);
yield Right(UnsubscribeEmailSuccess(currentEmailState: currentEmailState));
} catch (e) {
yield Left(UnsubscribeEmailFailure(exception: e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
} else if (success is DeleteSendingEmailSuccess) {
getAllSendingEmails();
} else if (success is UnsubscribeEmailSuccess) {
_handleUnsubscribeMailSuccess(success.newEmail);
_handleUnsubscribeMailSuccess();
} else if (success is RestoreDeletedMessageSuccess) {
dispatchMailboxUIAction(RefreshChangeMailboxAction(success.currentMailboxState));
_handleRestoreDeletedMessageSuccess(success.emailRecoveryAction.id!);
Expand Down Expand Up @@ -2599,13 +2599,16 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
}
}

void _handleUnsubscribeMailSuccess(Email email) {
void _handleUnsubscribeMailSuccess() {
if (currentContext != null && currentOverlayContext != null) {
appToast.showToastSuccessMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).unsubscribedFromThisMailingList);
}
setSelectedEmail(email.toPresentationEmail());
final newEmail = selectedEmail.value?.updateKeywords({
KeyWordIdentifierExtension.unsubscribeMail: true,
});
setSelectedEmail(newEmail);
}

void _replaceBrowserHistory({Uri? uri}) {
Expand Down

0 comments on commit 9604036

Please sign in to comment.