diff --git a/MailCore/Cache/DraftManager.swift b/MailCore/Cache/DraftManager.swift index 58cb110a1c..b988609390 100644 --- a/MailCore/Cache/DraftManager.swift +++ b/MailCore/Cache/DraftManager.swift @@ -100,9 +100,7 @@ public final class DraftManager { // show error if needed else { guard error.shouldDisplay else { return } - if showSnackbar { - alertDisplayable.show(message: error.localizedDescription) - } + alertDisplayable.show(message: error.localizedDescription, shouldShow: showSnackbar) } } await draftQueue.endBackgroundTask(uuid: draft.localUUID) @@ -131,12 +129,10 @@ public final class DraftManager { public func sendOrSchedule(draft initialDraft: Draft, mailboxManager: MailboxManager, retry: Bool = true, showSnackbar: Bool, changeFolderAction: ((Folder) -> Void)?) async -> Date? { - if showSnackbar { - if initialDraft.action == .schedule { - alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarScheduling) - } else { - alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarEmailSending) - } + if initialDraft.action == .schedule { + alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarScheduling, shouldShow: showSnackbar) + } else { + alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarEmailSending, shouldShow: showSnackbar) } var sendDate: Date? @@ -149,9 +145,7 @@ public final class DraftManager { if draft.action == .send { let sendResponse = try await mailboxManager.send(draft: draft) sendDate = sendResponse.scheduledDate - if showSnackbar { - alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarEmailSent) - } + alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarEmailSent, shouldShow: showSnackbar) } else if draft.action == .schedule { let draft = removeDelay(draft: draft) let scheduleResponse = try await mailboxManager.schedule(draft: draft) @@ -182,9 +176,7 @@ public final class DraftManager { ) } - if showSnackbar { - alertDisplayable.show(message: error.localizedDescription) - } + alertDisplayable.show(message: error.localizedDescription, shouldShow: showSnackbar) } await draftQueue.endBackgroundTask(uuid: draft.localUUID) return sendDate diff --git a/MailCore/Utils/UserAlertDisplayable.swift b/MailCore/Utils/UserAlertDisplayable.swift index 0ac3b8f6fd..1ec8e0c1cc 100644 --- a/MailCore/Utils/UserAlertDisplayable.swift +++ b/MailCore/Utils/UserAlertDisplayable.swift @@ -38,6 +38,12 @@ public protocol UserAlertDisplayable { /// - message: The message to display /// - action: Title and closure associated with the action func show(message: String, action: UserAlertAction) + + /// Will present a snackbar while main app is opened, a local notification in Extension or Background. + /// - Parameters: + /// - message: The message to display + /// - shouldShow: The boolean to show or not the snackbar + func show(message: String, shouldShow: Bool) } public typealias UserAlertAction = (name: String, closure: () -> Void) @@ -59,6 +65,11 @@ public final class UserAlertDisplayer: UserAlertDisplayable { showInContext(message: message, action: action) } + public func show(message: String, shouldShow: Bool) { + guard shouldShow else { return } + show(message: message) + } + // MARK: - private private func showInContext(message: String, action: UserAlertAction?) {