Skip to content

Commit

Permalink
Merge branch 'master' into genericTextInMailBody
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Apr 3, 2024
2 parents 9d764c4 + 381e694 commit 81543c7
Show file tree
Hide file tree
Showing 28 changed files with 775 additions and 124 deletions.
1 change: 1 addition & 0 deletions Mail/Views/New Message/ComposeMessageHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct ComposeMessageHeaderView: View {
VStack(spacing: 0) {
ComposeMessageSenderMenu(
currentSignature: $currentSignature,
mailboxManager: mailboxManager,
autocompletionType: autocompletionType,
type: .from,
text: mailboxManager.mailbox.email
Expand Down
69 changes: 39 additions & 30 deletions Mail/Views/New Message/ComposeMessageIntentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,55 @@ import SwiftUI
struct ComposeMessageIntentView: View, IntentViewable {
typealias Intent = ResolvedIntent

@LazyInjectService private var accountManager: AccountManager
@LazyInjectService private var snackbarPresenter: SnackBarPresentable

@Environment(\.dismiss) private var dismiss

let resolvedIntent = State<ResolvedIntent?>()

struct ResolvedIntent {
let mailboxManager: MailboxManager
let draft: Draft
let messageReply: MessageReply?
}

let composeMessageIntent: ComposeMessageIntent
@LazyInjectService private var accountManager: AccountManager
@LazyInjectService private var snackbarPresenter: SnackBarPresentable

@Environment(\.dismiss) private var dismiss

@State private var composeMessageIntent: ComposeMessageIntent
let resolvedIntent = State<ResolvedIntent?>()
var htmlAttachments: [HTMLAttachable] = []
var attachments: [Attachable] = []

init(composeMessageIntent: ComposeMessageIntent, textAttachments: [TextAttachable] = [], attachments: [Attachable] = []) {
_composeMessageIntent = State(wrappedValue: composeMessageIntent)
self.textAttachments = textAttachments
self.attachments = attachments
}

var body: some View {
NBNavigationStack {
if let resolvedIntent = resolvedIntent.wrappedValue {
ComposeMessageView(
draft: resolvedIntent.draft,
mailboxManager: resolvedIntent.mailboxManager,
messageReply: resolvedIntent.messageReply,
attachments: attachments,
htmlAttachments: htmlAttachments
)
.environmentObject(resolvedIntent.mailboxManager)
} else {
ProgressView()
.progressViewStyle(.circular)
.task {
await initFromIntent()
}
if composeMessageIntent.shouldSelectMailbox {
CurrentComposeMailboxView(composeMessageIntent: $composeMessageIntent)
} else {
NavigationView {
if let resolvedIntent = resolvedIntent.wrappedValue {
ComposeMessageView(
draft: resolvedIntent.draft,
mailboxManager: resolvedIntent.mailboxManager,
messageReply: resolvedIntent.messageReply,
attachments: attachments
)
.environmentObject(resolvedIntent.mailboxManager)
} else {
ProgressView()
.progressViewStyle(.circular)
.task {
await initFromIntent()
}
}
}
}
.interactiveDismissDisabled()
}

func initFromIntent() async {
guard let mailboxManager = accountManager.getMailboxManager(
for: composeMessageIntent.mailboxId,
userId: composeMessageIntent.userId
) else {
guard let mailboxId = composeMessageIntent.mailboxId, let userId = composeMessageIntent.userId,
let mailboxManager = accountManager.getMailboxManager(for: mailboxId, userId: userId) else {
dismiss()
snackbarPresenter.show(message: MailError.unknownError.errorDescription ?? "")
return
Expand Down Expand Up @@ -98,6 +103,10 @@ struct ComposeMessageIntentView: View, IntentViewable {
}
}

if composeMessageIntent.isFromOutsideOfApp {
try? await mailboxManager.refreshAllSignatures()
}

if let draftToWrite {
let draftLocalUUID = draftToWrite.localUUID
writeDraftToRealm(mailboxManager.getRealm(), draft: draftToWrite)
Expand Down Expand Up @@ -133,6 +142,6 @@ struct ComposeMessageIntentView: View, IntentViewable {

#Preview {
ComposeMessageIntentView(
composeMessageIntent: .new(originMailboxManager: PreviewHelper.sampleMailboxManager)
composeMessageIntent: .new(originMailboxManager: PreviewHelper.sampleMailboxManager), textAttachments: [], attachments: []
)
}
34 changes: 18 additions & 16 deletions Mail/Views/New Message/ComposeMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ struct ComposeMessageView: View {
}
}
}
.navigationTitle(MailResourcesStrings.Localizable.buttonNewMessage)
.navigationBarTitleDisplayMode(.inline)
.interactiveDismissDisabled()
.navigationViewStyle(.stack)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
if !platformDetector.isMac {
CloseButton(dismissHandler: didTouchDismiss)
}
}

ToolbarItem(placement: .navigationBarTrailing) {
Button(action: didTouchSend) {
Label(MailResourcesStrings.Localizable.send, image: MailResourcesAsset.send.name)
}
.disabled(isSendButtonDisabled)
}
}
.background(MailResourcesAsset.backgroundColor.swiftUIColor)
.overlay {
if isLoadingContent {
Expand Down Expand Up @@ -198,22 +216,6 @@ struct ComposeMessageView: View {
let rectTop = CGRect(x: 0, y: 0, width: 1, height: 1)
scrollView?.scrollRectToVisible(rectTop, animated: true)
}
.navigationTitle(MailResourcesStrings.Localizable.buttonNewMessage)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
if !platformDetector.isMac {
CloseButton(dismissHandler: didTouchDismiss)
}
}

ToolbarItem(placement: .navigationBarTrailing) {
Button(action: didTouchSend) {
Label(MailResourcesStrings.Localizable.send, image: MailResourcesAsset.send.name)
}
.disabled(isSendButtonDisabled)
}
}
.safeAreaInset(edge: .bottom) {
ExternalTagBottomView(externalTag: draft.displayExternalTag(mailboxManager: mailboxManager))
}
Expand Down
36 changes: 22 additions & 14 deletions Mail/Views/New Message/Header Cells/ComposeMessageSenderMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,7 @@ import SwiftUI
struct ComposeMessageSenderMenu: View {
@EnvironmentObject private var draftContentManager: DraftContentManager

/// Note:
/// ObservedResults will invoke a `default.realm` store, and break (no migration block) while a migration is needed in share
/// extension.
///
/// Therefore, I have to pass the correct realm configuration for `Signature.self`, so it can function correctly.
@ObservedResults(Signature.self, configuration: {
@InjectService var accountManager: AccountManager
guard let currentMailboxManager = accountManager.currentMailboxManager else {
return nil
}
return currentMailboxManager.realmConfiguration
}()) private var signatures
@ObservedResults(Signature.self) private var signatures

@Binding var currentSignature: Signature?

Expand All @@ -48,6 +37,20 @@ struct ComposeMessageSenderMenu: View {
signatures.count > 1
}

init(
currentSignature: Binding<Signature?>,
mailboxManager: MailboxManager,
autocompletionType: ComposeViewFieldType?,
type: ComposeViewFieldType,
text: String
) {
_currentSignature = currentSignature
_signatures = ObservedResults(Signature.self, configuration: mailboxManager.realmConfiguration)
self.autocompletionType = autocompletionType
self.type = type
self.text = text
}

var body: some View {
if autocompletionType == nil {
VStack(spacing: 0) {
Expand Down Expand Up @@ -83,6 +86,11 @@ struct ComposeMessageSenderMenu: View {
}

#Preview {
ComposeMessageSenderMenu(currentSignature: .constant(nil), autocompletionType: nil, type: .from, text: "email@email.com")
.environmentObject(PreviewHelper.sampleMailboxManager)
ComposeMessageSenderMenu(
currentSignature: .constant(nil),
mailboxManager: PreviewHelper.sampleMailboxManager,
autocompletionType: nil,
type: .from,
text: "email@email.com"
)
}
48 changes: 48 additions & 0 deletions Mail/Views/New Message/Select Mailbox/AccountMailboxCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2024 Infomaniak Network SA
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import MailResources
import SwiftUI

struct AccountMailboxCell: View {
let mailbox: Mailbox
var selectedMailbox: Mailbox?
let selectMailbox: (Mailbox) -> Void

var body: some View {
Button {
withAnimation {
selectMailbox(mailbox)
}
} label: {
Label {
Text(mailbox.email)
} icon: {
if selectedMailbox?.mailboxId == mailbox.mailboxId {
MailResourcesAsset.check.swiftUIImage
}
}
.accessibilityHint(MailResourcesStrings.Localizable.composeMailboxSelectionTitle)
}
}
}

#Preview {
AccountMailboxCell(mailbox: PreviewHelper.sampleMailbox) { _ in }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2024 Infomaniak Network SA
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import InfomaniakCore
import InfomaniakDI
import MailCore
import MailResources
import SwiftUI

struct AccountMailboxesListView: View {
@LazyInjectService private var accountManager: AccountManager

@EnvironmentObject private var mailboxManager: MailboxManager

let account: Account
var selectedMailbox: Mailbox?

let selectMailbox: (Mailbox) -> Void

private var currentMailbox: Mailbox? {
return accountManager.currentMailboxManager?.mailbox
}

var body: some View {
Menu {
ForEachMailboxView(userId: account.userId) { mailbox in
AccountMailboxCell(mailbox: mailbox, selectedMailbox: selectedMailbox, selectMailbox: selectMailbox)
}
} label: {
AccountHeaderCell(
account: account,
mailboxManager: mailboxManager,
isSelected: .constant(false),
type: .selectComposeMailbox
)
}
}
}

#Preview {
AccountMailboxesListView(
account: PreviewHelper.sampleAccount,
selectedMailbox: PreviewHelper.sampleMailbox
) { _ in }
}
Loading

0 comments on commit 81543c7

Please sign in to comment.