-
Notifications
You must be signed in to change notification settings - Fork 149
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
Release 15.2.0 #428
Merged
Merged
Release 15.2.0 #428
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce7353e
Map foreground/background events to same listener
rlepinski 09665e9
Fix null values
rlepinski 6c88d04
Update type
rlepinski f745738
Update version to 15.2.0
rlepinski fabfacb
Proxy 6.1.0
rlepinski 53f44d4
Changelog
rlepinski d647199
Update to 6.1.1
rlepinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ class AirshipCordova : CordovaPlugin() { | |
val callbackContext: CallbackContext | ||
) | ||
|
||
private var listeners: MutableMap<EventType, MutableList<Listener>> = mutableMapOf() | ||
private var listeners: MutableMap<String, MutableList<Listener>> = mutableMapOf() | ||
|
||
companion object { | ||
private val EVENT_NAME_MAP = mapOf( | ||
|
@@ -49,7 +49,7 @@ class AirshipCordova : CordovaPlugin() { | |
EventType.MESSAGE_CENTER_UPDATED to "airship.event.message_center_updated", | ||
EventType.PUSH_TOKEN_RECEIVED to "airship.event.push_token_received", | ||
EventType.FOREGROUND_PUSH_RECEIVED to "airship.event.push_received", | ||
EventType.BACKGROUND_PUSH_RECEIVED to "airship.event.background_push_received", | ||
EventType.BACKGROUND_PUSH_RECEIVED to "airship.event.push_received", | ||
EventType.NOTIFICATION_STATUS_CHANGED to "airship.event.notification_status_changed" | ||
) | ||
} | ||
|
@@ -103,44 +103,30 @@ class AirshipCordova : CordovaPlugin() { | |
val jsonArgs = JsonValue.wrap(args).requireList() | ||
|
||
val eventName = jsonArgs.get(0).requireString() | ||
val event: EventType = EVENT_NAME_MAP.firstNotNullOf { | ||
if (it.value == eventName) { | ||
it.key | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
val listener = Listener( | ||
listenerId = jsonArgs.get(1).requireInt(), | ||
callbackContext = callbackContext | ||
) | ||
|
||
this.listeners.getOrPut(event) { mutableListOf() }.add(listener) | ||
this.listeners.getOrPut(eventName) { mutableListOf() }.add(listener) | ||
notifyPendingEvents() | ||
} | ||
|
||
private fun removeListener(args: JSONArray) { | ||
val jsonArgs = JsonValue.wrap(args).requireList() | ||
|
||
val eventName = jsonArgs.get(0).requireString() | ||
val event: EventType = EVENT_NAME_MAP.firstNotNullOf { | ||
if (it.value == eventName) { | ||
it.key | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
val listenerId = jsonArgs.get(1).requireInt() | ||
this.listeners[event]?.removeAll { | ||
this.listeners[eventName]?.removeAll { | ||
it.listenerId == listenerId | ||
} | ||
} | ||
|
||
private fun notifyPendingEvents() { | ||
EventType.values().forEach { eventType -> | ||
val listeners = this.listeners[eventType] | ||
val listeners = this.listeners[EVENT_NAME_MAP[eventType]] | ||
if (listeners?.isNotEmpty() == true) { | ||
EventEmitter.shared().processPending(listOf(eventType)) { event -> | ||
listeners.forEach { listeners -> | ||
|
@@ -396,7 +382,7 @@ internal fun JsonSerializable.pluginResult(): PluginResult { | |
val json = this.toJsonValue() | ||
|
||
return when { | ||
json.isNull -> PluginResult(PluginResult.Status.OK) | ||
json.isNull -> PluginResult(PluginResult.Status.OK, null as String?) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do not set a value on Android cordova it will set the value based on the status message. |
||
json.isString -> PluginResult(PluginResult.Status.OK, json.requireString()) | ||
json.isBoolean -> PluginResult(PluginResult.Status.OK, json.requireBoolean()) | ||
json.isInteger -> PluginResult(PluginResult.Status.OK, json.getInt(0)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to map to types, instead only use the map when finding the listener. This fixes background response and makes it so we can combine foreground/background push received