Notifications are now handled when the app is in a killed state (#801)

* WIP, added support for receiver id and managed a way to store the app router state

* WIP, added support for receiver id and managed a way to store the app router state

* Notification Manager is now becoming the UNUserNotificationDelegate ASAP

* code improvements + changelog

* fixed Unit Tests

* pr suggestions
This commit is contained in:
Mauro
2023-04-14 14:24:48 +02:00
committed by GitHub
parent 41994baa4f
commit 3d0d883637
19 changed files with 338 additions and 89 deletions
@@ -20,10 +20,9 @@ import UserNotifications
class NotificationManager: NSObject, NotificationManagerProtocol {
private let notificationCenter: UserNotificationCenterProtocol
private let clientProxy: ClientProxyProtocol
private var clientProxy: ClientProxyProtocol?
init(clientProxy: ClientProxyProtocol, notificationCenter: UserNotificationCenterProtocol = UNUserNotificationCenter.current()) {
self.clientProxy = clientProxy
init(notificationCenter: UserNotificationCenterProtocol = UNUserNotificationCenter.current()) {
self.notificationCenter = notificationCenter
super.init()
}
@@ -32,10 +31,6 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
weak var delegate: NotificationManagerDelegate?
var isAvailable: Bool {
true
}
func start() {
let replyAction = UNTextInputNotificationAction(identifier: NotificationConstants.Action.inlineReply,
title: L10n.actionQuickReply,
@@ -46,6 +41,9 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
options: [])
notificationCenter.setNotificationCategories([replyCategory])
notificationCenter.delegate = self
}
func requestAuthorization() {
Task {
do {
let granted = try await notificationCenter.requestAuthorization(options: [.alert, .sound, .badge])
@@ -60,7 +58,14 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
}
func register(with deviceToken: Data) async -> Bool {
await setPusher(with: deviceToken, clientProxy: clientProxy)
guard let clientProxy else {
return false
}
return await setPusher(with: deviceToken, clientProxy: clientProxy)
}
func setClientProxy(_ clientProxy: ClientProxyProtocol?) {
self.clientProxy = clientProxy
}
func registrationFailed(with error: Error) { }