Skip to content

Commit

Permalink
refactor: Clean ComposeMessageIntentView
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon committed Feb 20, 2024
1 parent 297a2c4 commit e53f273
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
35 changes: 14 additions & 21 deletions Mail/Views/New Message/ComposeMessageIntentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResolvedIntent?>()

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 {
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions MailCore/Models/ComposeMessageIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e53f273

Please sign in to comment.