Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(local-notifications): extra not being returned on notification events #340

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions local-notifications/ios/Plugin/LocalNotificationsHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,46 @@ public class LocalNotificationsHandler: NSObject, NotificationHandlerProtocol {
*/
func makeNotificationRequestJSObject(_ request: UNNotificationRequest) -> JSObject {
let notificationRequest = notificationRequestLookup[request.identifier] ?? [:]
return [
var notification = makePendingNotificationRequestJSObject(request)
notification["sound"] = notificationRequest["sound"] ?? ""
notification["actionTypeId"] = request.content.categoryIdentifier
notification["attachments"] = notificationRequest["attachments"] ?? []
return notification

}

func makePendingNotificationRequestJSObject(_ request: UNNotificationRequest) -> JSObject {
var notification: JSObject = [
"id": Int(request.identifier) ?? -1,
"title": request.content.title,
"sound": notificationRequest["sound"] ?? "",
"body": request.content.body,
"extra": request.content.userInfo as? JSObject ?? [:],
"actionTypeId": request.content.categoryIdentifier,
"attachments": notificationRequest["attachments"] ?? []
"body": request.content.body
]

if let userInfo = JSTypes.coerceDictionaryToJSObject(request.content.userInfo) {
var extra = userInfo["cap_extra"] as? JSObject ?? userInfo

// check for any dates and convert them to strings
for(key, value) in extra {
if let date = value as? Date {
let dateString = ISO8601DateFormatter().string(from: date)
extra[key] = dateString
}
}

notification["extra"] = extra

if var schedule = userInfo["cap_schedule"] as? JSObject {
// convert schedule at date to string
if let date = schedule["at"] as? Date {
let dateString = ISO8601DateFormatter().string(from: date)
schedule["at"] = dateString
}

notification["schedule"] = schedule
}
}

return notification

}
}
37 changes: 1 addition & 36 deletions local-notifications/ios/Plugin/LocalNotificationsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public class LocalNotificationsPlugin: CAPPlugin {
CAPLog.print(notifications)

let ret = notifications.compactMap({ [weak self] (notification) -> JSObject? in
return self?.makePendingNotificationRequestJSObject(notification)
return self?.notificationDelegationHandler.makePendingNotificationRequestJSObject(notification)
})

call.resolve([
Expand Down Expand Up @@ -546,41 +546,6 @@ public class LocalNotificationsPlugin: CAPPlugin {
return opts
}

func makePendingNotificationRequestJSObject(_ request: UNNotificationRequest) -> JSObject {
var notification: JSObject = [
"id": Int(request.identifier) ?? -1,
"title": request.content.title,
"body": request.content.body
]

if let userInfo = JSTypes.coerceDictionaryToJSObject(request.content.userInfo) {
var extra = userInfo["cap_extra"] as? JSObject ?? userInfo

// check for any dates and convert them to strings
for(key, value) in extra {
if let date = value as? Date {
let dateString = ISO8601DateFormatter().string(from: date)
extra[key] = dateString
}
}

notification["extra"] = extra

if var schedule = userInfo["cap_schedule"] as? JSObject {
// convert schedule at date to string
if let date = schedule["at"] as? Date {
let dateString = ISO8601DateFormatter().string(from: date)
schedule["at"] = dateString
}

notification["schedule"] = schedule
}
}

return notification

}

@objc func createChannel(_ call: CAPPluginCall) {
call.unimplemented()
}
Expand Down