@trycourier/courier-react-native 2.0.0-beta4 → 2.0.0-beta6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/courierreactnative/CourierEvents.kt +28 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +17 -19
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +229 -158
- package/android/src/main/java/com/courierreactnative/Extensions.kt +95 -0
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcuserdata/mike.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/CourierReactNativeModule.m +5 -8
- package/ios/CourierReactNativeModule.swift +16 -31
- package/lib/commonjs/hooks/CourierProvider.js +15 -15
- package/lib/commonjs/hooks/CourierProvider.js.map +1 -1
- package/lib/commonjs/index.js +2 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/hooks/CourierProvider.js +14 -14
- package/lib/module/hooks/CourierProvider.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/hooks/CourierProvider.d.ts +7 -7
- package/lib/typescript/hooks/CourierProvider.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +5 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/hooks/CourierProvider.tsx +17 -16
- package/src/index.tsx +14 -6
package/android/build.gradle
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
internal class CourierEvents {
|
|
4
|
+
|
|
5
|
+
companion object {
|
|
6
|
+
const val COURIER_ERROR_TAG = "Courier Android SDK Error"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
object Log {
|
|
10
|
+
const val DEBUG_LOG = "courierDebugEvent"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
object Auth {
|
|
14
|
+
const val USER_CHANGED = "courierAuthUserChanged"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
object Push {
|
|
18
|
+
const val CLICKED_EVENT = "pushNotificationClicked"
|
|
19
|
+
const val DELIVERED_EVENT = "pushNotificationDelivered"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
object Inbox {
|
|
23
|
+
const val INITIAL_LOADING = "inboxInitialLoad"
|
|
24
|
+
const val ERROR = "inboxError"
|
|
25
|
+
const val MESSAGES_CHANGED = "inboxMessagesChanged"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
}
|
|
@@ -3,6 +3,9 @@ package com.courierreactnative
|
|
|
3
3
|
import android.content.Intent
|
|
4
4
|
import android.os.Bundle
|
|
5
5
|
import com.courier.android.Courier
|
|
6
|
+
import com.courier.android.utils.getLastDeliveredMessage
|
|
7
|
+
import com.courier.android.utils.pushNotification
|
|
8
|
+
import com.courier.android.utils.trackPushNotificationClick
|
|
6
9
|
//import com.courier.android.pushNotification
|
|
7
10
|
//import com.courier.android.trackPushNotificationClick
|
|
8
11
|
import com.facebook.react.ReactActivity
|
|
@@ -12,11 +15,6 @@ import org.json.JSONObject
|
|
|
12
15
|
|
|
13
16
|
open class CourierReactNativeActivity : ReactActivity() {
|
|
14
17
|
|
|
15
|
-
companion object {
|
|
16
|
-
private const val PUSH_CLICKED_EVENT = "pushNotificationClicked"
|
|
17
|
-
private const val PUSH_DELIVERED_EVENT = "pushNotificationDelivered"
|
|
18
|
-
}
|
|
19
|
-
|
|
20
18
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
21
19
|
super.onCreate(savedInstanceState)
|
|
22
20
|
|
|
@@ -28,16 +26,10 @@ open class CourierReactNativeActivity : ReactActivity() {
|
|
|
28
26
|
checkIntentForPushNotificationClick(intent)
|
|
29
27
|
|
|
30
28
|
// Handle delivered messages on the main thread
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private fun sendEvent(eventName: String, params: String) {
|
|
38
|
-
reactInstanceManager.currentReactContext?.let { reactContext ->
|
|
39
|
-
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit(eventName, params)
|
|
29
|
+
Courier.shared.getLastDeliveredMessage { message ->
|
|
30
|
+
postPushNotificationDelivered(message)
|
|
40
31
|
}
|
|
32
|
+
|
|
41
33
|
}
|
|
42
34
|
|
|
43
35
|
override fun onNewIntent(intent: Intent?) {
|
|
@@ -46,17 +38,23 @@ open class CourierReactNativeActivity : ReactActivity() {
|
|
|
46
38
|
}
|
|
47
39
|
|
|
48
40
|
private fun checkIntentForPushNotificationClick(intent: Intent?) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
intent?.trackPushNotificationClick { message ->
|
|
42
|
+
postPushNotificationClicked(message)
|
|
43
|
+
}
|
|
52
44
|
}
|
|
53
45
|
|
|
54
46
|
private fun postPushNotificationDelivered(message: RemoteMessage) {
|
|
55
|
-
|
|
47
|
+
reactInstanceManager.currentReactContext?.sendEvent(
|
|
48
|
+
eventName = CourierEvents.Push.DELIVERED_EVENT,
|
|
49
|
+
value = JSONObject(message.pushNotification).toString()
|
|
50
|
+
)
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
private fun postPushNotificationClicked(message: RemoteMessage) {
|
|
59
|
-
|
|
54
|
+
reactInstanceManager.currentReactContext?.sendEvent(
|
|
55
|
+
eventName = CourierEvents.Push.CLICKED_EVENT,
|
|
56
|
+
value = JSONObject(message.pushNotification).toString()
|
|
57
|
+
)
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
}
|
|
@@ -1,52 +1,99 @@
|
|
|
1
1
|
package com.courierreactnative
|
|
2
2
|
|
|
3
3
|
import android.content.Intent
|
|
4
|
-
import com.courier.android
|
|
5
|
-
import com.courier.android.models
|
|
6
|
-
import com.courier.android.models.CourierProvider
|
|
4
|
+
import com.courier.android.Courier
|
|
5
|
+
import com.courier.android.models.*
|
|
7
6
|
import com.courier.android.modules.*
|
|
8
7
|
import com.courier.android.utils.pushNotification
|
|
9
8
|
import com.courier.android.utils.trackPushNotificationClick
|
|
10
9
|
import com.facebook.react.ReactActivity
|
|
11
10
|
import com.facebook.react.bridge.*
|
|
12
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
13
11
|
import com.google.firebase.messaging.RemoteMessage
|
|
14
12
|
import org.json.JSONObject
|
|
13
|
+
import java.util.*
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
18
17
|
|
|
19
18
|
override fun getName() = "CourierReactNativeModule"
|
|
19
|
+
private val reactActivity: ReactActivity? get() = currentActivity as? ReactActivity
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
private const val COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT = "courierDebugEvent"
|
|
24
|
-
private const val COURIER_PUSH_NOTIFICATION_CLICKED_EVENT = "pushNotificationClicked"
|
|
25
|
-
}
|
|
21
|
+
private val authListeners = mutableMapOf<String, CourierAuthenticationListener>()
|
|
22
|
+
private val inboxListeners = mutableMapOf<String, CourierInboxListener>()
|
|
26
23
|
|
|
27
24
|
init {
|
|
25
|
+
|
|
28
26
|
// User Agent is used to ensure we know the SDK
|
|
29
27
|
// the requests come from
|
|
30
28
|
Courier.USER_AGENT = CourierAgent.REACT_NATIVE_ANDROID
|
|
31
29
|
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// Attach the log listener
|
|
31
|
+
Courier.shared.logListener = { data ->
|
|
32
|
+
reactContext.sendEvent(CourierEvents.Log.DEBUG_LOG, data)
|
|
33
|
+
}
|
|
35
34
|
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
@ReactMethod
|
|
38
|
+
fun addListener(type: String?) {
|
|
39
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
40
|
+
}
|
|
39
41
|
|
|
40
42
|
@ReactMethod
|
|
41
|
-
fun
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
fun removeListeners(type: Int?) {
|
|
44
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
48
|
+
fun setDebugMode(isDebugging: Boolean): Boolean {
|
|
49
|
+
Courier.shared.isDebugging = isDebugging
|
|
50
|
+
return Courier.shared.isDebugging
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@ReactMethod
|
|
54
|
+
fun registerPushNotificationClickedOnKilledState() {
|
|
55
|
+
reactActivity?.let { activity ->
|
|
56
|
+
checkIntentForPushNotificationClick(activity.intent)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private fun checkIntentForPushNotificationClick(intent: Intent?) {
|
|
61
|
+
intent?.trackPushNotificationClick { message ->
|
|
62
|
+
postPushNotificationClicked(message)
|
|
47
63
|
}
|
|
48
64
|
}
|
|
49
65
|
|
|
66
|
+
private fun postPushNotificationClicked(message: RemoteMessage) {
|
|
67
|
+
reactApplicationContext.sendEvent(
|
|
68
|
+
eventName = CourierEvents.Push.CLICKED_EVENT,
|
|
69
|
+
value = JSONObject(message.pushNotification).toString()
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@ReactMethod
|
|
74
|
+
fun requestNotificationPermission(promise: Promise) {
|
|
75
|
+
// try {
|
|
76
|
+
// reactActivity?.requestNotificationPermission { isGranted ->
|
|
77
|
+
//// val status = if (isGranted) NotificationPermissionStatus.AUTHORIZED else NotificationPermissionStatus.DENIED
|
|
78
|
+
//// promise.resolve(status.value)
|
|
79
|
+
// }
|
|
80
|
+
// } catch (e: Exception) {
|
|
81
|
+
// promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
82
|
+
// }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@ReactMethod
|
|
86
|
+
fun getNotificationPermissionStatus(promise: Promise) {
|
|
87
|
+
// try {
|
|
88
|
+
// reactActivity?.getNotificationPermissionStatus { isGranted ->
|
|
89
|
+
// val status = if (isGranted) NotificationPermissionStatus.AUTHORIZED else NotificationPermissionStatus.DENIED
|
|
90
|
+
// promise.resolve(status.value)
|
|
91
|
+
// }
|
|
92
|
+
// } catch (e: Exception) {
|
|
93
|
+
// promise.reject(COURIER_ERROR_TAG, e)
|
|
94
|
+
// }
|
|
95
|
+
}
|
|
96
|
+
|
|
50
97
|
@ReactMethod
|
|
51
98
|
fun signIn(accessToken: String, clientKey: String?, userId: String, promise: Promise) {
|
|
52
99
|
Courier.shared.signIn(
|
|
@@ -57,160 +104,184 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
57
104
|
promise.resolve(null)
|
|
58
105
|
},
|
|
59
106
|
onFailure = { e ->
|
|
60
|
-
promise.reject(COURIER_ERROR_TAG, e)
|
|
107
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
61
108
|
}
|
|
62
109
|
)
|
|
63
110
|
}
|
|
64
111
|
|
|
65
|
-
// @ReactMethod
|
|
66
|
-
// fun getFcmToken(promise: Promise) {
|
|
67
|
-
// Courier.shared.getFCMToken(
|
|
68
|
-
// onSuccess = { token ->
|
|
69
|
-
// promise.resolve(token)
|
|
70
|
-
// },
|
|
71
|
-
// onFailure = { e ->
|
|
72
|
-
// promise.reject(COURIER_ERROR_TAG, e)
|
|
73
|
-
// }
|
|
74
|
-
// )
|
|
75
|
-
// }
|
|
76
|
-
//
|
|
77
|
-
// @ReactMethod
|
|
78
|
-
// fun setFcmToken(token: String, promise: Promise) {
|
|
79
|
-
//
|
|
80
|
-
// token.let { fcmToken ->
|
|
81
|
-
//
|
|
82
|
-
// Courier.shared.setFCMToken(
|
|
83
|
-
// fcmToken,
|
|
84
|
-
// onSuccess = {
|
|
85
|
-
// promise.resolve(null)
|
|
86
|
-
// },
|
|
87
|
-
// onFailure = { e ->
|
|
88
|
-
// promise.reject(COURIER_ERROR_TAG, e)
|
|
89
|
-
// }
|
|
90
|
-
// )
|
|
91
|
-
//
|
|
92
|
-
// }
|
|
93
|
-
//
|
|
94
|
-
// }
|
|
95
|
-
//
|
|
96
112
|
@ReactMethod
|
|
97
|
-
fun
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
fun signOut(promise: Promise) {
|
|
114
|
+
Courier.shared.signOut(
|
|
115
|
+
onSuccess = {
|
|
116
|
+
promise.resolve(null)
|
|
117
|
+
},
|
|
118
|
+
onFailure = { e ->
|
|
119
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
125
|
+
fun getUserId(): String? {
|
|
126
|
+
return Courier.shared.userId
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
130
|
+
fun addAuthenticationListener(): String {
|
|
131
|
+
|
|
132
|
+
val listener = Courier.shared.addAuthenticationListener { userId ->
|
|
133
|
+
reactApplicationContext.sendEvent(
|
|
134
|
+
eventName = CourierEvents.Auth.USER_CHANGED,
|
|
135
|
+
value = userId
|
|
136
|
+
)
|
|
103
137
|
}
|
|
138
|
+
|
|
139
|
+
val id = UUID.randomUUID().toString()
|
|
140
|
+
authListeners[id] = listener
|
|
141
|
+
|
|
142
|
+
return id
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
147
|
+
fun removeAuthenticationListener(listenerId: String): String {
|
|
148
|
+
|
|
149
|
+
// Remove the listener
|
|
150
|
+
val listener = authListeners[listenerId]
|
|
151
|
+
listener?.remove()
|
|
152
|
+
|
|
153
|
+
// Remove from map
|
|
154
|
+
authListeners.remove(listenerId)
|
|
155
|
+
|
|
156
|
+
return listenerId
|
|
157
|
+
|
|
104
158
|
}
|
|
105
159
|
|
|
106
160
|
@ReactMethod
|
|
107
|
-
fun
|
|
108
|
-
Courier.shared.
|
|
161
|
+
fun setFcmToken(token: String, promise: Promise) {
|
|
162
|
+
Courier.shared.setFCMToken(
|
|
163
|
+
token = token,
|
|
109
164
|
onSuccess = {
|
|
110
165
|
promise.resolve(null)
|
|
111
166
|
},
|
|
112
167
|
onFailure = { e ->
|
|
113
|
-
promise.reject(COURIER_ERROR_TAG, e)
|
|
168
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
114
169
|
}
|
|
115
170
|
)
|
|
116
171
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
172
|
+
|
|
173
|
+
@ReactMethod
|
|
174
|
+
fun getFcmToken(promise: Promise) {
|
|
175
|
+
Courier.shared.getFCMToken(
|
|
176
|
+
onSuccess = { token ->
|
|
177
|
+
promise.resolve(token)
|
|
178
|
+
},
|
|
179
|
+
onFailure = { e ->
|
|
180
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
181
|
+
}
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
186
|
+
fun readMessage(messageId: String): String {
|
|
187
|
+
Courier.shared.readMessage(messageId)
|
|
188
|
+
return messageId
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
192
|
+
fun unreadMessage(messageId: String): String {
|
|
193
|
+
Courier.shared.unreadMessage(messageId)
|
|
194
|
+
return messageId
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@ReactMethod
|
|
198
|
+
fun readAllInboxMessages(promise: Promise) {
|
|
199
|
+
Courier.shared.readAllInboxMessages(
|
|
200
|
+
onSuccess = {
|
|
201
|
+
promise.resolve(null)
|
|
202
|
+
},
|
|
203
|
+
onFailure = { e ->
|
|
204
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
210
|
+
fun addInboxListener(): String {
|
|
211
|
+
|
|
212
|
+
val listener = Courier.shared.addInboxListener(
|
|
213
|
+
onInitialLoad = {
|
|
214
|
+
reactApplicationContext.sendEvent(
|
|
215
|
+
eventName = CourierEvents.Inbox.INITIAL_LOADING,
|
|
216
|
+
value = null
|
|
217
|
+
)
|
|
218
|
+
},
|
|
219
|
+
onError = { e ->
|
|
220
|
+
reactApplicationContext.sendEvent(
|
|
221
|
+
eventName = CourierEvents.Inbox.ERROR,
|
|
222
|
+
value = e.message ?: "Courier Inbox Error"
|
|
223
|
+
)
|
|
224
|
+
},
|
|
225
|
+
onMessagesChanged = { messages: List<InboxMessage>, unreadMessageCount: Int, totalMessageCount: Int, canPaginate: Boolean ->
|
|
226
|
+
|
|
227
|
+
val json = Arguments.createMap()
|
|
228
|
+
json.putArray("messages", messages.toWritableArray())
|
|
229
|
+
json.putInt("unreadMessageCount", unreadMessageCount)
|
|
230
|
+
json.putInt("totalMessageCount", totalMessageCount)
|
|
231
|
+
json.putBoolean("canPaginate", canPaginate)
|
|
232
|
+
|
|
233
|
+
reactApplicationContext.sendEvent(
|
|
234
|
+
eventName = CourierEvents.Inbox.MESSAGES_CHANGED,
|
|
235
|
+
value = json
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
val id = UUID.randomUUID().toString()
|
|
242
|
+
inboxListeners[id] = listener
|
|
243
|
+
|
|
244
|
+
return id
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
249
|
+
fun removeInboxListener(listenerId: String): String {
|
|
250
|
+
|
|
251
|
+
// Remove the listener
|
|
252
|
+
val listener = inboxListeners[listenerId]
|
|
253
|
+
listener?.remove()
|
|
254
|
+
|
|
255
|
+
// Remove from map
|
|
256
|
+
inboxListeners.remove(listenerId)
|
|
257
|
+
|
|
258
|
+
return listenerId
|
|
259
|
+
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
@ReactMethod
|
|
263
|
+
fun refreshInbox(promise: Promise) {
|
|
264
|
+
Courier.shared.refreshInbox {
|
|
265
|
+
promise.resolve(null)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
@ReactMethod
|
|
270
|
+
fun fetchNextPageOfMessages(promise: Promise) {
|
|
271
|
+
Courier.shared.fetchNextPageOfMessages(
|
|
272
|
+
onSuccess = { messages ->
|
|
273
|
+
promise.resolve(messages.toWritableArray())
|
|
274
|
+
},
|
|
275
|
+
onFailure = { e ->
|
|
276
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
277
|
+
}
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
282
|
+
fun setInboxPaginationLimit(limit: Double): String {
|
|
283
|
+
Courier.shared.inboxPaginationLimit = limit.toInt()
|
|
284
|
+
return Courier.shared.inboxPaginationLimit.toString()
|
|
285
|
+
}
|
|
215
286
|
|
|
216
287
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import com.courier.android.models.InboxAction
|
|
4
|
+
import com.courier.android.models.InboxMessage
|
|
5
|
+
import com.facebook.react.bridge.Arguments
|
|
6
|
+
import com.facebook.react.bridge.ReactContext
|
|
7
|
+
import com.facebook.react.bridge.WritableArray
|
|
8
|
+
import com.facebook.react.bridge.WritableMap
|
|
9
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
+
|
|
11
|
+
internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
|
|
12
|
+
getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, value)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@JvmName("toWritableArrayInboxMessage")
|
|
16
|
+
internal fun List<InboxMessage>.toWritableArray(): WritableArray {
|
|
17
|
+
|
|
18
|
+
val messagesArray = Arguments.createArray()
|
|
19
|
+
|
|
20
|
+
forEach { message ->
|
|
21
|
+
messagesArray.pushMap(message.toWritableMap())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return messagesArray
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
internal fun InboxMessage.toWritableMap(): WritableMap {
|
|
29
|
+
|
|
30
|
+
val map = Arguments.createMap()
|
|
31
|
+
map.putString("messageId", messageId)
|
|
32
|
+
map.putString("title", title)
|
|
33
|
+
map.putString("body", body)
|
|
34
|
+
map.putString("preview", preview)
|
|
35
|
+
map.putString("created", created)
|
|
36
|
+
|
|
37
|
+
actions?.let { actionList ->
|
|
38
|
+
val actionsArray = Arguments.createArray()
|
|
39
|
+
actionList.forEach { action ->
|
|
40
|
+
actionsArray.pushMap(action.toWritableMap())
|
|
41
|
+
}
|
|
42
|
+
map.putArray("actions", actionsArray)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
map.putMap("data", data.toWritableMap())
|
|
46
|
+
map.putBoolean("read", isRead)
|
|
47
|
+
map.putBoolean("opened", isOpened)
|
|
48
|
+
map.putBoolean("archived", isArchived)
|
|
49
|
+
|
|
50
|
+
return map
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
internal fun InboxAction.toWritableMap(): WritableMap {
|
|
55
|
+
|
|
56
|
+
val map = Arguments.createMap()
|
|
57
|
+
map.putString("content", content)
|
|
58
|
+
map.putString("href", href)
|
|
59
|
+
map.putMap("data", data.toWritableMap())
|
|
60
|
+
|
|
61
|
+
return map
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
internal fun Map<String, Any>?.toWritableMap(): WritableMap {
|
|
66
|
+
val map = Arguments.createMap()
|
|
67
|
+
this?.forEach { (key, value) ->
|
|
68
|
+
when (value) {
|
|
69
|
+
is String -> map.putString(key, value)
|
|
70
|
+
is Int -> map.putInt(key, value)
|
|
71
|
+
is Double -> map.putDouble(key, value)
|
|
72
|
+
is Boolean -> map.putBoolean(key, value)
|
|
73
|
+
is Map<*, *> -> map.putMap(key, (value as? Map<String, Any>).toWritableMap())
|
|
74
|
+
is List<*> -> map.putArray(key, (value as? List<Any>).toWritableArray())
|
|
75
|
+
else -> map.putNull(key)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return map
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
internal fun List<Any>?.toWritableArray(): WritableArray {
|
|
82
|
+
val array = Arguments.createArray()
|
|
83
|
+
this?.forEach { item ->
|
|
84
|
+
when (item) {
|
|
85
|
+
is String -> array.pushString(item)
|
|
86
|
+
is Int -> array.pushInt(item)
|
|
87
|
+
is Double -> array.pushDouble(item)
|
|
88
|
+
is Boolean -> array.pushBoolean(item)
|
|
89
|
+
is Map<*, *> -> array.pushMap((item as? Map<String, Any>).toWritableMap())
|
|
90
|
+
is List<*> -> array.pushArray((item as? List<Any>).toWritableArray())
|
|
91
|
+
else -> array.pushNull()
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return array
|
|
95
|
+
}
|
|
Binary file
|
|
@@ -49,8 +49,9 @@ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
|
49
49
|
getApnsToken
|
|
50
50
|
)
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
getFcmToken
|
|
52
|
+
RCT_EXTERN_METHOD(
|
|
53
|
+
getFcmToken: (RCTPromiseResolveBlock)resolve
|
|
54
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
54
55
|
)
|
|
55
56
|
|
|
56
57
|
RCT_EXTERN_METHOD(
|
|
@@ -59,16 +60,12 @@ RCT_EXTERN_METHOD(
|
|
|
59
60
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
60
61
|
)
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
63
64
|
readMessage: (NSString*)messageId
|
|
64
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
65
|
-
withRejecter: (RCTPromiseRejectBlock)reject
|
|
66
65
|
)
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
69
68
|
unreadMessage: (NSString*)messageId
|
|
70
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
71
|
-
withRejecter: (RCTPromiseRejectBlock)reject
|
|
72
69
|
)
|
|
73
70
|
|
|
74
71
|
RCT_EXTERN_METHOD(
|