mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Remote Push Notifications can now be decrypted (#854)
* refactored the NSE to use the client function * removed unused imports in the target.yml * some code improvements * changelog * code improvement * code improvement * more code improvements * separated the client and the media provider in a dedicated NSEUserSession * Update ElementX/Sources/Services/Client/ClientProxy.swift Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com> * pr suggestions * logging the error --------- Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
@@ -1,23 +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 MockNotificationServiceProxy: NotificationServiceProxyProtocol {
|
||||
func notificationItem(roomId: String, eventId: String) async throws -> NotificationItemProxyProtocol? {
|
||||
nil
|
||||
}
|
||||
}
|
||||
@@ -102,10 +102,7 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
// The mock and the protocol are just temporary until we can handle
|
||||
// and decrypt notifications both in background and in foreground
|
||||
// but they should not be necessary in the future
|
||||
struct MockNotificationItemProxy: NotificationItemProxyProtocol {
|
||||
struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
|
||||
let eventID: String
|
||||
|
||||
var event: TimelineEventProxyProtocol {
|
||||
@@ -167,13 +164,13 @@ extension NotificationItemProxyProtocol {
|
||||
/// - roomId: Room identifier
|
||||
/// - mediaProvider: Media provider to process also media. May be passed nil to ignore media operations.
|
||||
/// - Returns: A notification content object if the notification should be displayed. Otherwise nil.
|
||||
func process(mediaProvider: MediaProviderProtocol?) async throws -> UNMutableNotificationContent? {
|
||||
if self is MockNotificationItemProxy {
|
||||
return processMock()
|
||||
func process(mediaProvider: MediaProviderProtocol?) async throws -> UNMutableNotificationContent {
|
||||
if self is EmptyNotificationItemProxy {
|
||||
return processEmpty()
|
||||
} else {
|
||||
switch event.type {
|
||||
case .none, .state:
|
||||
return nil
|
||||
return processEmpty()
|
||||
case let .messageLike(content):
|
||||
switch content {
|
||||
case .roomMessage(messageType: let messageType):
|
||||
@@ -194,7 +191,7 @@ extension NotificationItemProxyProtocol {
|
||||
return try await processText(content: content, mediaProvider: mediaProvider)
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
return processEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,8 +201,7 @@ extension NotificationItemProxyProtocol {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
// To be removed once we don't need the mock anymore
|
||||
private func processMock() -> UNMutableNotificationContent {
|
||||
private func processEmpty() -> UNMutableNotificationContent {
|
||||
let notification = UNMutableNotificationContent()
|
||||
notification.receiverID = receiverID
|
||||
notification.roomID = roomID
|
||||
|
||||
@@ -1,33 +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
|
||||
import MatrixRustSDK
|
||||
|
||||
class NotificationServiceProxy: NotificationServiceProxyProtocol {
|
||||
private let userID: String
|
||||
// private let service: NotificationServiceProtocol
|
||||
|
||||
init(basePath: String,
|
||||
userID: String) {
|
||||
self.userID = userID
|
||||
// service = NotificationService(basePath: basePath, userId: userId)
|
||||
}
|
||||
|
||||
func notificationItem(roomId: String, eventId: String) async throws -> NotificationItemProxyProtocol? {
|
||||
MockNotificationItemProxy(eventID: eventId, roomID: roomId, receiverID: userID)
|
||||
}
|
||||
}
|
||||
@@ -1,21 +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
|
||||
|
||||
protocol NotificationServiceProxyProtocol {
|
||||
func notificationItem(roomId: String, eventId: String) async throws -> NotificationItemProxyProtocol?
|
||||
}
|
||||
Reference in New Issue
Block a user