Skip to content

Commit

Permalink
Revert "handle notifications from a cold start"
Browse files Browse the repository at this point in the history
This reverts commit d3e4916.
  • Loading branch information
MaximBelov committed Apr 19, 2024
1 parent 5446425 commit 93ebe85
Showing 1 changed file with 0 additions and 75 deletions.
75 changes: 0 additions & 75 deletions cordova-airship/src/android/AirshipCordova.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@

package com.urbanairship.cordova

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Build
import com.urbanairship.Autopilot
import com.urbanairship.PendingResult
import com.urbanairship.UALog
import com.urbanairship.actions.ActionResult
import com.urbanairship.android.framework.proxy.EventType
import com.urbanairship.android.framework.proxy.Utils
import com.urbanairship.android.framework.proxy.events.EventEmitter
import com.urbanairship.android.framework.proxy.proxies.AirshipProxy
import com.urbanairship.android.framework.proxy.proxies.FeatureFlagProxy
import com.urbanairship.json.JsonList
import com.urbanairship.json.JsonMap
import com.urbanairship.json.JsonSerializable
import com.urbanairship.json.JsonValue
import com.urbanairship.json.jsonMapOf
import com.urbanairship.push.NotificationInfo
import com.urbanairship.push.PushManager
import com.urbanairship.push.PushMessage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
Expand All @@ -44,7 +37,6 @@ class AirshipCordova : CordovaPlugin() {
)

private var listeners: MutableMap<EventType, MutableList<Listener>> = mutableMapOf()
private val notificationStack: MutableMap<EventType, MutableList<NotificationInfo>> = mutableMapOf()

companion object {
private val EVENT_NAME_MAP = mapOf(
Expand Down Expand Up @@ -95,33 +87,6 @@ class AirshipCordova : CordovaPlugin() {
notifyPendingEvents()
}
}

cordova.getThreadPool().execute {
try {
notifyListeners(
EventType.BACKGROUND_NOTIFICATION_RESPONSE_RECEIVED,
cordova.getActivity().intent
)
} catch (e: java.lang.Exception) {
val msg = e.toString()
UALog.e { msg }
}
}

}

override fun onNewIntent(intent: Intent?) {
try {
super.onNewIntent(intent)
notifyListeners(
EventType.BACKGROUND_NOTIFICATION_RESPONSE_RECEIVED,
intent!!
)
} catch (e: java.lang.Exception) {
val msg = e.toString()
UALog.e { msg }

}
}

override fun onReset() {
Expand All @@ -132,34 +97,6 @@ class AirshipCordova : CordovaPlugin() {
override fun onDestroy() {
super.onDestroy()
this.listeners.clear()
this.notificationStack.clear()
}

@SuppressLint("RestrictedApi")
private fun notifyListeners(eventType: EventType, intent: Intent) {
val data = intent.extras
if (data != null && data.containsKey(PushManager.EXTRA_PUSH_MESSAGE_BUNDLE)) {
val dataString = data.toString();
UALog.i { "Notification message on new intent: $dataString" }
val message = PushMessage.fromIntent(intent) ?: return
val id: Int = intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, -1)
val tag: String? = intent.getStringExtra(PushManager.EXTRA_NOTIFICATION_TAG)
val notificationInfo = NotificationInfo(message, id, tag)
val listeners = this.listeners[eventType];
val pluginResult = jsonMapOf(
"pushPayload" to Utils.notificationMap(
notificationInfo.message,
),
).pluginResult()
if (listeners?.isNotEmpty() == true) {
listeners.forEach { listener ->
pluginResult.keepCallback = true
listener.callbackContext.sendPluginResult(pluginResult)
}
} else {
this.notificationStack.getOrPut(eventType) { mutableListOf() }.add(notificationInfo)
}
}
}

private fun addListener(args: JSONArray, callbackContext: CallbackContext) {
Expand All @@ -180,18 +117,6 @@ class AirshipCordova : CordovaPlugin() {
)

this.listeners.getOrPut(event) { mutableListOf() }.add(listener)

this.notificationStack[event]?.forEach { notificationInfo ->
val pluginResult = jsonMapOf(
"pushPayload" to Utils.notificationMap(
notificationInfo.message,
),
).pluginResult()
pluginResult.keepCallback = true
listener.callbackContext.sendPluginResult(pluginResult)
this.notificationStack[event]?.remove(notificationInfo)
}

notifyPendingEvents()
}

Expand Down

0 comments on commit 93ebe85

Please sign in to comment.