Skip to content

Commit

Permalink
fix: Remove attachments and calendar events from notification preview (
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon authored May 30, 2024
2 parents 445445b + 9767f88 commit 23b9f8c
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 24 deletions.
3 changes: 1 addition & 2 deletions Mail/StandardWindowViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ struct StandardWindowViewModifier: ViewModifier {
func updateUI(accent: AccentColor, theme: Theme) {
let allWindows = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.flatMap(\.windows)
for window in allWindows {
window.overrideUserInterfaceStyle = theme.interfaceStyle
window.tintColor = accent.primary.color
window.updateUI(accent: accent, theme: theme)
}
}
}
66 changes: 66 additions & 0 deletions Mail/Views/Thread/Message/MessageSubHeaderView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
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 MailCoreUI
import MailResources
import RealmSwift
import SwiftUI

struct MessageSubHeaderView: View {
@ObservedRealmObject var message: Message

@Binding var displayContentBlockedActionView: Bool

private var isRemoteContentBlocked: Bool {
return (UserDefaults.shared.displayExternalContent == .askMe || message.folder?.role == .spam)
&& !message.localSafeDisplay
}

var body: some View {
if isRemoteContentBlocked && displayContentBlockedActionView {
MessageHeaderActionView(
icon: MailResourcesAsset.emailActionWarning.swiftUIImage,
message: MailResourcesStrings.Localizable.alertBlockedImagesDescription
) {
Button(MailResourcesStrings.Localizable.alertBlockedImagesDisplayContent) {
withAnimation {
$message.localSafeDisplay.wrappedValue = true
}
}
.buttonStyle(.ikLink(isInlined: true))
.controlSize(.small)
}
}

if let event = message.calendarEventResponse?.frozenEvent, event.type == .event {
CalendarView(event: event)
.padding(.horizontal, value: .regular)
}

if !message.attachments.filter({ $0.disposition == .attachment || $0.contentId == nil }).isEmpty {
AttachmentsView(message: message)
}
}
}

#Preview {
MessageSubHeaderView(message: PreviewHelper.sampleMessage, displayContentBlockedActionView: .constant(false))
}
29 changes: 7 additions & 22 deletions Mail/Views/Thread/Message/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extension EnvironmentValues {
struct MessageView: View {
@LazyInjectService private var snackbarPresenter: SnackBarPresentable

@Environment(\.isMessageInteractive) private var isMessageInteractive

@EnvironmentObject var mailboxManager: MailboxManager

@State var presentableBody: PresentableBody
Expand Down Expand Up @@ -73,28 +75,11 @@ struct MessageView: View {

if isMessageExpanded {
VStack(spacing: UIPadding.regular) {
if isRemoteContentBlocked && displayContentBlockedActionView {
MessageHeaderActionView(
icon: MailResourcesAsset.emailActionWarning.swiftUIImage,
message: MailResourcesStrings.Localizable.alertBlockedImagesDescription
) {
Button(MailResourcesStrings.Localizable.alertBlockedImagesDisplayContent) {
withAnimation {
$message.localSafeDisplay.wrappedValue = true
}
}
.buttonStyle(.ikLink(isInlined: true))
.controlSize(.small)
}
}

if let event = message.calendarEventResponse?.frozenEvent, event.type == .event {
CalendarView(event: event)
.padding(.horizontal, value: .regular)
}

if !message.attachments.filter({ $0.disposition == .attachment || $0.contentId == nil }).isEmpty {
AttachmentsView(message: message)
if isMessageInteractive {
MessageSubHeaderView(
message: message,
displayContentBlockedActionView: $displayContentBlockedActionView
)
}

if isShowingErrorLoading {
Expand Down
28 changes: 28 additions & 0 deletions MailCoreUI/Extensions/UIWindow+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
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 Foundation
import MailCore
import UIKit

public extension UIWindow {
func updateUI(accent: AccentColor, theme: Theme) {
overrideUserInterfaceStyle = theme.interfaceStyle
tintColor = accent.primary.color
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
])
}

override func viewIsAppearing(_ animated: Bool) {
super.viewIsAppearing(animated)
view.window?.updateUI(accent: UserDefaults.shared.accentColor, theme: UserDefaults.shared.theme)
}

func stopAnimating(displayError: Bool) {
activityIndicator.stopAnimating()
errorLabel.isHidden = displayError
Expand Down

0 comments on commit 23b9f8c

Please sign in to comment.