diff --git a/Mail/Views/New Message/ComposeMessageIntentView.swift b/Mail/Views/New Message/ComposeMessageIntentView.swift index c1a2e111df..da14b680eb 100644 --- a/Mail/Views/New Message/ComposeMessageIntentView.swift +++ b/Mail/Views/New Message/ComposeMessageIntentView.swift @@ -25,30 +25,30 @@ import SwiftUI struct ComposeMessageIntentView: View, IntentViewable { typealias Intent = ResolvedIntent + struct ResolvedIntent { + let mailboxManager: MailboxManager + let draft: Draft + let messageReply: MessageReply? + } + @LazyInjectService private var accountManager: AccountManager @LazyInjectService private var snackbarPresenter: SnackBarPresentable @Environment(\.dismiss) private var dismiss - @State var mailboxManager: MailboxManager? - private var shouldPresentMailToView: Bool { - composeMessageIntent.mailboxId == nil && composeMessageIntent.userId == nil - } - + @State private var composeMessageIntent: ComposeMessageIntent let resolvedIntent = State() - struct ResolvedIntent { - let mailboxManager: MailboxManager - let draft: Draft - let messageReply: MessageReply? - } + private var attachments: [Attachable] - @State var composeMessageIntent: ComposeMessageIntent - var attachments: [Attachable] = [] + init(composeMessageIntent: ComposeMessageIntent, attachments: [Attachable] = []) { + _composeMessageIntent = State(wrappedValue: composeMessageIntent) + self.attachments = attachments + } var body: some View { NBNavigationStack { - if shouldPresentMailToView { + if composeMessageIntent.shouldSelectMailbox { SelectComposeMailboxView(composeMessageIntent: $composeMessageIntent) } else { if let resolvedIntent = resolvedIntent.wrappedValue { @@ -106,15 +106,8 @@ struct ComposeMessageIntentView: View, IntentViewable { } } - switch composeMessageIntent.type { - case .mailTo: + if composeMessageIntent.isFromOutsideOfApp { try? await mailboxManager.refreshAllSignatures() - case .new(let fromExtension): - if fromExtension { - try? await mailboxManager.refreshAllSignatures() - } - default: - break } if let draftToWrite { diff --git a/MailCore/Models/ComposeMessageIntent.swift b/MailCore/Models/ComposeMessageIntent.swift index 693ea8b54b..cf738693d2 100644 --- a/MailCore/Models/ComposeMessageIntent.swift +++ b/MailCore/Models/ComposeMessageIntent.swift @@ -33,6 +33,21 @@ public struct ComposeMessageIntent: Codable, Identifiable, Hashable { public let mailboxId: Int? public let type: IntentType + public var shouldSelectMailbox: Bool { + userId == nil || mailboxId == nil + } + + public var isFromOutsideOfApp: Bool { + switch type { + case .new(let fromExtension) where fromExtension: + return true + case .mailTo(let mailToURLComponents): + return true + default: + return false + } + } + init(userId: Int?, mailboxId: Int?, type: IntentType) { id = UUID() self.userId = userId