save notification

pull/340/head
Lucas Nogueira 2 years ago
parent c80c3182e5
commit 3c864a5e44
No known key found for this signature in database
GPG Key ID: 7C32FCA95C8C95D7

@ -5,7 +5,11 @@ public class NotificationHandler: NSObject, NotificationHandlerProtocol {
public weak var plugin: Plugin? public weak var plugin: Plugin?
var notificationsMap = [String: JSObject]() private var notificationsMap = [String: JSObject]()
public func saveNotification(_ key: String, _ notification: JSObject) {
notificationsMap.updateValue(notification, forKey: key)
}
public func requestPermissions(with completion: ((Bool, Error?) -> Void)? = nil) { public func requestPermissions(with completion: ((Bool, Error?) -> Void)? = nil) {
let center = UNUserNotificationCenter.current() let center = UNUserNotificationCenter.current()
@ -72,7 +76,7 @@ public class NotificationHandler: NSObject, NotificationHandlerProtocol {
var notification = makePendingNotificationRequestJSObject(request) var notification = makePendingNotificationRequestJSObject(request)
notification["sound"] = notificationRequest["sound"] ?? "" notification["sound"] = notificationRequest["sound"] ?? ""
notification["actionTypeId"] = request.content.categoryIdentifier notification["actionTypeId"] = request.content.categoryIdentifier
notification["attachments"] = notificationRequest["attachments"] ?? [] notification["attachments"] = notificationRequest["attachments"] ?? [JSObject]()
return notification return notification
} }

@ -61,18 +61,18 @@ func showNotification(invoke: Invoke, notification: JSObject)
} }
class NotificationPlugin: Plugin { class NotificationPlugin: Plugin {
let notificationHandler = NotificationHandler() var notificationHandler = NotificationHandler()
let notificationManager = NotificationManager() let notificationManager = NotificationManager()
override init() { override init() {
super.init() super.init()
notificationHandler.plugin = self
notificationManager.notificationHandler = notificationHandler notificationManager.notificationHandler = notificationHandler
notificationHandler.plugin = self
} }
@objc public func show(_ invoke: Invoke) throws { @objc public func show(_ invoke: Invoke) throws {
let request = try showNotification(invoke: invoke, notification: invoke.data) let request = try showNotification(invoke: invoke, notification: invoke.data)
// TODO self.notificationHandler.notificationsMap[request.identifier] = invoke.data notificationHandler.saveNotification(request.identifier, invoke.data)
invoke.resolve([ invoke.resolve([
"id": Int(request.identifier) ?? -1 "id": Int(request.identifier) ?? -1
]) ])
@ -87,7 +87,7 @@ class NotificationPlugin: Plugin {
for notification in notifications { for notification in notifications {
let request = try showNotification(invoke: invoke, notification: notification) let request = try showNotification(invoke: invoke, notification: notification)
// TODO self.notificationHandler.notificationsMap[request.identifier] = notification notificationHandler.saveNotification(request.identifier, notification)
ids.append(Int(request.identifier) ?? -1) ids.append(Int(request.identifier) ?? -1)
} }

Loading…
Cancel
Save