-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: NotificationContentExtension (#1432)
- Loading branch information
Showing
16 changed files
with
429 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleVersion</key> | ||
<string>$(CURRENT_PROJECT_VERSION)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>$(MARKETING_VERSION)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>AppIdentifierPrefix</key> | ||
<string>$(AppIdentifierPrefix)</string> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionAttributes</key> | ||
<dict> | ||
<key>UNNotificationExtensionCategory</key> | ||
<string>com.infomaniak.mail.incoming</string> | ||
<key>UNNotificationExtensionUserInteractionEnabled</key> | ||
<true/> | ||
<key>UNNotificationExtensionDefaultContentHidden</key> | ||
<true/> | ||
<key>UNNotificationExtensionInitialContentSizeRatio</key> | ||
<real>1.5</real> | ||
</dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.usernotifications.content-extension</string> | ||
<key>NSExtensionPrincipalClass</key> | ||
<string>$(PRODUCT_MODULE_NAME).NotificationViewController</string> | ||
</dict> | ||
</dict> | ||
</plist> |
18 changes: 18 additions & 0 deletions
18
MailNotificationContentExtension/MailNotificationContentExtension.entitlements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.application-groups</key> | ||
<array> | ||
<string>group.com.infomaniak.mail</string> | ||
</array> | ||
<key>com.apple.security.network.client</key> | ||
<true/> | ||
<key>keychain-access-groups</key> | ||
<array> | ||
<string>$(AppIdentifierPrefix)com.infomaniak.mail</string> | ||
</array> | ||
</dict> | ||
</plist> |
22 changes: 22 additions & 0 deletions
22
MailNotificationContentExtension/NotificationContentExtensionTargetAssembly.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Infomaniak Mail - iOS App | ||
Copyright (C) 2022 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 InfomaniakDI | ||
|
||
class NotificationContentExtensionTargetAssembly: CommonAppAndShareTargetAssembly {} |
104 changes: 104 additions & 0 deletions
104
MailNotificationContentExtension/NotificationViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
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 InfomaniakDI | ||
import MailCore | ||
import MailResources | ||
import RealmSwift | ||
import SwiftUI | ||
import UIKit | ||
import UserNotifications | ||
import UserNotificationsUI | ||
|
||
class NotificationViewController: UIViewController, UNNotificationContentExtension { | ||
private let dependencyInjectionHook = NotificationContentExtensionTargetAssembly() | ||
|
||
@LazyInjectService private var accountManager: AccountManager | ||
@LazyInjectService private var mailboxInfosManager: MailboxInfosManager | ||
|
||
let activityIndicator = UIActivityIndicatorView(style: .medium) | ||
let errorLabel = UILabel() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
ModelMigrator().migrateRealmIfNeeded() | ||
SentryDebug.setUserId(accountManager.currentUserId) | ||
|
||
activityIndicator.translatesAutoresizingMaskIntoConstraints = false | ||
activityIndicator.hidesWhenStopped = true | ||
activityIndicator.startAnimating() | ||
view.addSubview(activityIndicator) | ||
|
||
errorLabel.isHidden = true | ||
errorLabel.font = UIFont.preferredFont(forTextStyle: .body) | ||
errorLabel.textAlignment = .center | ||
errorLabel.textColor = .secondaryLabel | ||
errorLabel.text = MailResourcesStrings.Localizable.errorMessageNotFound | ||
errorLabel.translatesAutoresizingMaskIntoConstraints = false | ||
view.addSubview(errorLabel) | ||
|
||
NSLayoutConstraint.activate([ | ||
activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
activityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor), | ||
errorLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
errorLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor) | ||
]) | ||
} | ||
|
||
func stopAnimating(displayError: Bool) { | ||
activityIndicator.stopAnimating() | ||
errorLabel.isHidden = displayError | ||
} | ||
|
||
func didReceive(_ notification: UNNotification) { | ||
Task { | ||
let userInfo = notification.request.content.userInfo | ||
guard let mailboxId = userInfo[NotificationsHelper.UserInfoKeys.mailboxId] as? Int, | ||
let userId = userInfo[NotificationsHelper.UserInfoKeys.userId] as? Int, | ||
let messageUid = userInfo[NotificationsHelper.UserInfoKeys.messageUid] as? String, | ||
let mailbox = mailboxInfosManager.getMailbox(id: mailboxId, userId: userId), | ||
let mailboxManager = accountManager.getMailboxManager(for: mailbox) else { | ||
stopAnimating(displayError: true) | ||
return | ||
} | ||
|
||
guard let message = try? await NotificationsHelper.fetchMessage(uid: messageUid, in: mailboxManager) else { | ||
stopAnimating(displayError: true) | ||
return | ||
} | ||
|
||
let messageView = ScrollView { | ||
MessageView( | ||
message: message, | ||
isMessageExpanded: true, | ||
threadForcedExpansion: .constant([:]) | ||
) | ||
.environment(\.isMessageInteractive, false) | ||
.environmentObject(mailboxManager) | ||
} | ||
|
||
let hostingViewController = UIHostingController(rootView: messageView) | ||
|
||
addChild(hostingViewController) | ||
view.addSubview(hostingViewController.view) | ||
hostingViewController.view.frame = view.bounds | ||
stopAnimating(displayError: false) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
MailNotificationContentExtension/Proxy/ApplicationState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Infomaniak Mail - iOS App | ||
Copyright (C) 2022 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 UIKit | ||
|
||
public struct ApplicationState: ApplicationStatable { | ||
public var applicationState: UIApplication.State? { | ||
nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Infomaniak Mail - iOS App | ||
Copyright (C) 2022 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 InfomaniakCore | ||
|
||
/// A cache manager that works in Extension mode | ||
public final class CacheManager: CacheManageable { | ||
public func refreshCacheData(account: Account?) { | ||
// NOOP in shareExtension | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
MailNotificationContentExtension/Proxy/MessageActionHandler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Infomaniak Mail - iOS App | ||
Copyright (C) 2023 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 | ||
|
||
// Stub for extension mode | ||
public struct MessageActionHandler: MessageActionHandlable { | ||
func handleTapOnNotification(messageUid: String, mailbox: Mailbox, mailboxManager: MailboxManager) async throws {} | ||
|
||
func handleArchiveOnNotification(messageUid: String, mailboxManager: MailboxManager) async throws {} | ||
|
||
func handleDeleteOnNotification(messageUid: String, mailboxManager: MailboxManager) async throws {} | ||
|
||
func handleReplyOnNotification(messageUid: String, mailbox: Mailbox, mailboxManager: MailboxManager) {} | ||
} |
Oops, something went wrong.