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
@@ -1,37 +0,0 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
class MockNotificationManager: NotificationManagerProtocol {
// MARK: NotificationManagerProtocol
var isAvailable: Bool {
false
}
weak var delegate: NotificationManagerDelegate?
func start() {
delegate?.authorizationStatusUpdated(self, granted: false)
}
func register(with deviceToken: Data) async -> Bool { false }
func registrationFailed(with error: Error) { }
func showLocalNotification(with title: String, subtitle: String?) { }
}
@@ -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) { }
@@ -31,12 +31,14 @@ protocol NotificationManagerDelegate: AnyObject {
// MARK: - NotificationManagerProtocol
protocol NotificationManagerProtocol {
var isAvailable: Bool { get }
// sourcery: AutoMockable
protocol NotificationManagerProtocol: AnyObject {
var delegate: NotificationManagerDelegate? { get set }
func start()
func register(with deviceToken: Data) async -> Bool
func registrationFailed(with error: Error)
func showLocalNotification(with title: String, subtitle: String?) async
func setClientProxy(_ clientProxy: ClientProxyProtocol?)
func requestAuthorization()
}