@trycourier/courier-react-native 2.0.3 → 2.2.0
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/README.md +13 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +0 -3
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +101 -22
- package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +84 -18
- package/android/src/main/java/com/courierreactnative/Extensions.kt +51 -3
- package/courier-react-native.podspec +1 -1
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcuserdata/mike.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/CourierReactNative.xcodeproj/xcuserdata/mike.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/CourierReactNativeModule.m +32 -9
- package/ios/CourierReactNativeModule.swift +59 -26
- package/ios/CourierReactNativeViewManager.swift +117 -159
- package/ios/Utils.swift +199 -0
- package/lib/commonjs/index.js +83 -28
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierPaging.js +2 -0
- package/lib/commonjs/models/CourierPaging.js.map +1 -0
- package/lib/commonjs/models/CourierPushProvider.js +16 -0
- package/lib/commonjs/models/CourierPushProvider.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferences.js +6 -0
- package/lib/commonjs/models/CourierUserPreferences.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferencesChannel.js +17 -0
- package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferencesStatus.js +15 -0
- package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferencesTopic.js +6 -0
- package/lib/commonjs/models/CourierUserPreferencesTopic.js.map +1 -0
- package/lib/module/index.js +36 -17
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierPaging.js +2 -0
- package/lib/module/models/CourierPaging.js.map +1 -0
- package/lib/module/models/CourierPushProvider.js +9 -0
- package/lib/module/models/CourierPushProvider.js.map +1 -0
- package/lib/module/models/CourierUserPreferences.js +2 -0
- package/lib/module/models/CourierUserPreferences.js.map +1 -0
- package/lib/module/models/CourierUserPreferencesChannel.js +10 -0
- package/lib/module/models/CourierUserPreferencesChannel.js.map +1 -0
- package/lib/module/models/CourierUserPreferencesStatus.js +8 -0
- package/lib/module/models/CourierUserPreferencesStatus.js.map +1 -0
- package/lib/module/models/CourierUserPreferencesTopic.js +2 -0
- package/lib/module/models/CourierUserPreferencesTopic.js.map +1 -0
- package/lib/typescript/index.d.ts +43 -8
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/CourierInboxTheme.d.ts +24 -8
- package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -1
- package/lib/typescript/models/CourierPaging.d.ts +5 -0
- package/lib/typescript/models/CourierPaging.d.ts.map +1 -0
- package/lib/typescript/models/CourierPushProvider.d.ts +8 -0
- package/lib/typescript/models/CourierPushProvider.d.ts.map +1 -0
- package/lib/typescript/models/CourierUserPreferences.d.ts +7 -0
- package/lib/typescript/models/CourierUserPreferences.d.ts.map +1 -0
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +9 -0
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +1 -0
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +7 -0
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +1 -0
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +11 -0
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +1 -0
- package/lib/typescript/views/CourierInboxView.d.ts +3 -3
- package/lib/typescript/views/CourierInboxView.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/index.tsx +43 -20
- package/src/models/CourierInboxTheme.tsx +28 -8
- package/src/models/CourierPaging.tsx +4 -0
- package/src/models/CourierPushProvider.tsx +7 -0
- package/src/models/CourierUserPreferences.tsx +7 -0
- package/src/models/CourierUserPreferencesChannel.tsx +8 -0
- package/src/models/CourierUserPreferencesStatus.tsx +6 -0
- package/src/models/CourierUserPreferencesTopic.tsx +11 -0
- package/src/views/CourierInboxView.tsx +3 -3
- package/lib/commonjs/hooks/CourierProvider.js +0 -254
- package/lib/commonjs/hooks/CourierProvider.js.map +0 -1
- package/lib/module/hooks/CourierProvider.js +0 -241
- package/lib/module/hooks/CourierProvider.js.map +0 -1
- package/lib/typescript/hooks/CourierProvider.d.ts +0 -57
- package/lib/typescript/hooks/CourierProvider.d.ts.map +0 -1
- package/src/hooks/CourierProvider.tsx +0 -356
package/README.md
CHANGED
|
@@ -186,6 +186,19 @@ These are all the available features of the SDK.
|
|
|
186
186
|
Automatically manages push notification device tokens and gives convenient functions for handling push notification receiving and clicking.
|
|
187
187
|
</td>
|
|
188
188
|
</tr>
|
|
189
|
+
<tr width="600px">
|
|
190
|
+
<td align="center">
|
|
191
|
+
4
|
|
192
|
+
</td>
|
|
193
|
+
<td align="left">
|
|
194
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/Preferences.md">
|
|
195
|
+
<code>Preferences</code>
|
|
196
|
+
</a>
|
|
197
|
+
</td>
|
|
198
|
+
<td align="left">
|
|
199
|
+
Allow users to update which types of notifications they would like to receive.
|
|
200
|
+
</td>
|
|
201
|
+
</tr>
|
|
189
202
|
</tbody>
|
|
190
203
|
</table>
|
|
191
204
|
|
package/android/build.gradle
CHANGED
|
@@ -101,8 +101,8 @@ dependencies {
|
|
|
101
101
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
102
102
|
|
|
103
103
|
// Courier Core SDK
|
|
104
|
-
api 'com.github.trycourier:courier-android:2.0
|
|
105
|
-
api 'androidx.recyclerview:recyclerview:1.3.
|
|
104
|
+
api 'com.github.trycourier:courier-android:2.3.0'
|
|
105
|
+
api 'androidx.recyclerview:recyclerview:1.3.2'
|
|
106
106
|
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -6,10 +6,7 @@ import com.courier.android.Courier
|
|
|
6
6
|
import com.courier.android.utils.getLastDeliveredMessage
|
|
7
7
|
import com.courier.android.utils.pushNotification
|
|
8
8
|
import com.courier.android.utils.trackPushNotificationClick
|
|
9
|
-
//import com.courier.android.pushNotification
|
|
10
|
-
//import com.courier.android.trackPushNotificationClick
|
|
11
9
|
import com.facebook.react.ReactActivity
|
|
12
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
13
10
|
import com.google.firebase.messaging.RemoteMessage
|
|
14
11
|
import org.json.JSONObject
|
|
15
12
|
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
package com.courierreactnative
|
|
2
2
|
|
|
3
|
+
import android.Manifest
|
|
3
4
|
import android.content.Intent
|
|
5
|
+
import android.content.pm.PackageManager
|
|
6
|
+
import android.os.Build
|
|
7
|
+
import androidx.core.app.ActivityCompat
|
|
8
|
+
import androidx.core.content.ContextCompat
|
|
4
9
|
import com.courier.android.Courier
|
|
5
10
|
import com.courier.android.models.*
|
|
6
11
|
import com.courier.android.modules.*
|
|
7
|
-
import com.courier.android.utils.isPushPermissionGranted
|
|
8
12
|
import com.courier.android.utils.pushNotification
|
|
9
|
-
import com.courier.android.utils.requestNotificationPermission
|
|
10
13
|
import com.courier.android.utils.trackPushNotificationClick
|
|
11
14
|
import com.facebook.react.ReactActivity
|
|
12
15
|
import com.facebook.react.bridge.*
|
|
@@ -72,16 +75,48 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
72
75
|
)
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
@ReactMethod
|
|
78
|
+
@ReactMethod
|
|
76
79
|
fun requestNotificationPermission(promise: Promise) {
|
|
77
|
-
|
|
80
|
+
|
|
81
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
|
82
|
+
promise.resolve("unknown")
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Request the push permission
|
|
87
|
+
reactActivity?.let { context ->
|
|
88
|
+
|
|
89
|
+
val permissionState: Int = ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS)
|
|
90
|
+
|
|
91
|
+
if (permissionState == PackageManager.PERMISSION_DENIED) {
|
|
92
|
+
ActivityCompat.requestPermissions(context, arrayOf(Manifest.permission.POST_NOTIFICATIONS), 1)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
promise.resolve("unknown")
|
|
98
|
+
|
|
78
99
|
}
|
|
79
100
|
|
|
80
|
-
@ReactMethod
|
|
101
|
+
@ReactMethod
|
|
81
102
|
fun getNotificationPermissionStatus(promise: Promise) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
|
|
104
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
|
105
|
+
promise.resolve("unknown")
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
reactActivity?.let { context ->
|
|
110
|
+
|
|
111
|
+
val permissionState: Int = ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS)
|
|
112
|
+
val status = if (permissionState == PackageManager.PERMISSION_GRANTED) "authorized" else "denied"
|
|
113
|
+
promise.resolve(status)
|
|
114
|
+
return
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
promise.resolve("unknown")
|
|
119
|
+
|
|
85
120
|
}
|
|
86
121
|
|
|
87
122
|
@ReactMethod
|
|
@@ -147,9 +182,15 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
147
182
|
|
|
148
183
|
}
|
|
149
184
|
|
|
185
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
186
|
+
fun getToken(key: String): String? {
|
|
187
|
+
return Courier.shared.getToken(key)
|
|
188
|
+
}
|
|
189
|
+
|
|
150
190
|
@ReactMethod
|
|
151
|
-
fun
|
|
152
|
-
Courier.shared.
|
|
191
|
+
fun setToken(key: String, token: String, promise: Promise) {
|
|
192
|
+
Courier.shared.setToken(
|
|
193
|
+
provider = key,
|
|
153
194
|
token = token,
|
|
154
195
|
onSuccess = {
|
|
155
196
|
promise.resolve(null)
|
|
@@ -160,18 +201,6 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
160
201
|
)
|
|
161
202
|
}
|
|
162
203
|
|
|
163
|
-
@ReactMethod
|
|
164
|
-
fun getFcmToken(promise: Promise) {
|
|
165
|
-
Courier.shared.getFCMToken(
|
|
166
|
-
onSuccess = { token ->
|
|
167
|
-
promise.resolve(token)
|
|
168
|
-
},
|
|
169
|
-
onFailure = { e ->
|
|
170
|
-
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
171
|
-
}
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
204
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
176
205
|
fun readMessage(messageId: String): String {
|
|
177
206
|
Courier.shared.readMessage(messageId)
|
|
@@ -274,4 +303,54 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
274
303
|
return Courier.shared.inboxPaginationLimit.toString()
|
|
275
304
|
}
|
|
276
305
|
|
|
306
|
+
@ReactMethod
|
|
307
|
+
fun getUserPreferences(paginationCursor: String, promise: Promise) {
|
|
308
|
+
|
|
309
|
+
val cursor = if (paginationCursor != "") paginationCursor else null
|
|
310
|
+
|
|
311
|
+
Courier.shared.getUserPreferences(
|
|
312
|
+
paginationCursor = cursor,
|
|
313
|
+
onSuccess = { preferences ->
|
|
314
|
+
promise.resolve(preferences.toWritableMap())
|
|
315
|
+
},
|
|
316
|
+
onFailure = { e ->
|
|
317
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
318
|
+
}
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
@ReactMethod
|
|
324
|
+
fun getUserPreferencesTopic(topicId: String, promise: Promise) {
|
|
325
|
+
Courier.shared.getUserPreferenceTopic(
|
|
326
|
+
topicId = topicId,
|
|
327
|
+
onSuccess = { topic ->
|
|
328
|
+
promise.resolve(topic.toWritableMap())
|
|
329
|
+
},
|
|
330
|
+
onFailure = { e ->
|
|
331
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
@ReactMethod
|
|
337
|
+
fun putUserPreferencesTopic(topicId: String, status: String, hasCustomRouting: Boolean, customRouting: ReadableArray, promise: Promise) {
|
|
338
|
+
|
|
339
|
+
val routing = customRouting.toArrayList().map { CourierPreferenceChannel.fromString(it as String) }
|
|
340
|
+
|
|
341
|
+
Courier.shared.putUserPreferenceTopic(
|
|
342
|
+
topicId = topicId,
|
|
343
|
+
status = CourierPreferenceStatus.fromString(status),
|
|
344
|
+
hasCustomRouting = hasCustomRouting,
|
|
345
|
+
customRouting = routing,
|
|
346
|
+
onSuccess = {
|
|
347
|
+
promise.resolve(null)
|
|
348
|
+
},
|
|
349
|
+
onFailure = { e ->
|
|
350
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
351
|
+
}
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
}
|
|
355
|
+
|
|
277
356
|
}
|
|
@@ -5,10 +5,7 @@ import android.graphics.Color
|
|
|
5
5
|
import android.graphics.Typeface
|
|
6
6
|
import android.view.View
|
|
7
7
|
import androidx.recyclerview.widget.DividerItemDecoration
|
|
8
|
-
import com.courier.android.inbox
|
|
9
|
-
import com.courier.android.inbox.CourierInboxButtonStyles
|
|
10
|
-
import com.courier.android.inbox.CourierInboxFont
|
|
11
|
-
import com.courier.android.inbox.CourierInboxTheme
|
|
8
|
+
import com.courier.android.inbox.*
|
|
12
9
|
import com.facebook.react.bridge.Arguments
|
|
13
10
|
import com.facebook.react.bridge.ReadableMap
|
|
14
11
|
import com.facebook.react.uimanager.SimpleViewManager
|
|
@@ -90,26 +87,41 @@ class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
90
87
|
val android = getMap("android")
|
|
91
88
|
val dividerItemDecoration = android?.getString("dividerItemDecoration")
|
|
92
89
|
|
|
93
|
-
val
|
|
90
|
+
val unreadIndicatorStyle = getMap("unreadIndicatorStyle")
|
|
94
91
|
val loadingIndicatorColor = getString("loadingIndicatorColor")
|
|
95
92
|
|
|
96
|
-
val
|
|
97
|
-
val
|
|
98
|
-
val
|
|
99
|
-
val
|
|
93
|
+
val titleStyle = getMap("titleStyle")
|
|
94
|
+
val timeStyle = getMap("timeStyle")
|
|
95
|
+
val bodyStyle = getMap("bodyStyle")
|
|
96
|
+
val infoViewStyle = getMap("infoViewStyle")
|
|
100
97
|
val buttonStyles = getMap("buttonStyles")
|
|
101
98
|
|
|
102
99
|
val context = view.context
|
|
103
100
|
|
|
104
101
|
return CourierInboxTheme(
|
|
105
|
-
|
|
106
|
-
unreadIndicatorBarColor = unreadIndicatorBarColor?.toColor(),
|
|
102
|
+
unreadIndicatorStyle = unreadIndicatorStyle?.toUnreadIndicatorStyle() ?: CourierInboxUnreadIndicatorStyle(),
|
|
107
103
|
loadingIndicatorColor = loadingIndicatorColor?.toColor(),
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
titleStyle = titleStyle?.toTextStyle(context) ?: CourierInboxTextStyle(
|
|
105
|
+
unread = CourierInboxFont(),
|
|
106
|
+
read = CourierInboxFont(),
|
|
107
|
+
),
|
|
108
|
+
timeStyle = timeStyle?.toTextStyle(context) ?: CourierInboxTextStyle(
|
|
109
|
+
unread = CourierInboxFont(),
|
|
110
|
+
read = CourierInboxFont(),
|
|
111
|
+
),
|
|
112
|
+
bodyStyle = bodyStyle?.toTextStyle(context) ?: CourierInboxTextStyle(
|
|
113
|
+
unread = CourierInboxFont(),
|
|
114
|
+
read = CourierInboxFont(),
|
|
115
|
+
),
|
|
116
|
+
buttonStyle = buttonStyles?.toButtonStyle(context) ?: CourierInboxButtonStyle(
|
|
117
|
+
unread = CourierInboxButton(),
|
|
118
|
+
read = CourierInboxButton(),
|
|
119
|
+
),
|
|
120
|
+
infoViewStyle = infoViewStyle?.toInfoStyle(context) ?: CourierInboxInfoViewStyle(
|
|
121
|
+
font = CourierInboxFont(),
|
|
122
|
+
button = CourierInboxButton(),
|
|
123
|
+
),
|
|
124
|
+
dividerItemDecoration = dividerItemDecoration?.toDivider(context),
|
|
113
125
|
)
|
|
114
126
|
|
|
115
127
|
}
|
|
@@ -142,13 +154,43 @@ class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
142
154
|
|
|
143
155
|
}
|
|
144
156
|
|
|
145
|
-
private fun ReadableMap.
|
|
157
|
+
private fun ReadableMap.toTextStyle(context: Context): CourierInboxTextStyle {
|
|
158
|
+
|
|
159
|
+
val unread = getMap("unread")
|
|
160
|
+
val read = getMap("read")
|
|
161
|
+
|
|
162
|
+
return CourierInboxTextStyle(
|
|
163
|
+
unread = unread?.toFont(context) ?: CourierInboxFont(),
|
|
164
|
+
read = read?.toFont(context) ?: CourierInboxFont(),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private fun ReadableMap.toUnreadIndicatorStyle(): CourierInboxUnreadIndicatorStyle {
|
|
170
|
+
|
|
171
|
+
val indicator = getString("indicator")
|
|
172
|
+
val color = getString("color")
|
|
173
|
+
|
|
174
|
+
var style = CourierInboxUnreadIndicator.LINE
|
|
175
|
+
|
|
176
|
+
if (indicator == "dot") {
|
|
177
|
+
style = CourierInboxUnreadIndicator.DOT
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return CourierInboxUnreadIndicatorStyle(
|
|
181
|
+
indicator = style,
|
|
182
|
+
color = color?.toColor(),
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private fun ReadableMap.toButton(context: Context): CourierInboxButton {
|
|
146
188
|
|
|
147
189
|
val font = getMap("font")
|
|
148
190
|
val backgroundColor = getString("backgroundColor")
|
|
149
191
|
val cornerRadius = if (isNull("cornerRadius")) null else getDouble("cornerRadius")
|
|
150
192
|
|
|
151
|
-
return
|
|
193
|
+
return CourierInboxButton(
|
|
152
194
|
font = font?.toFont(context),
|
|
153
195
|
backgroundColor = backgroundColor?.toColor(),
|
|
154
196
|
cornerRadiusInDp = cornerRadius?.toInt()
|
|
@@ -156,4 +198,28 @@ class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
156
198
|
|
|
157
199
|
}
|
|
158
200
|
|
|
201
|
+
private fun ReadableMap.toButtonStyle(context: Context): CourierInboxButtonStyle {
|
|
202
|
+
|
|
203
|
+
val unread = getMap("unread")
|
|
204
|
+
val read = getMap("read")
|
|
205
|
+
|
|
206
|
+
return CourierInboxButtonStyle(
|
|
207
|
+
unread = unread?.toButton(context) ?: CourierInboxButton(),
|
|
208
|
+
read = read?.toButton(context) ?: CourierInboxButton()
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private fun ReadableMap.toInfoStyle(context: Context): CourierInboxInfoViewStyle {
|
|
214
|
+
|
|
215
|
+
val font = getMap("font")
|
|
216
|
+
val button = getMap("button")
|
|
217
|
+
|
|
218
|
+
return CourierInboxInfoViewStyle(
|
|
219
|
+
font = font?.toFont(context) ?: CourierInboxFont(),
|
|
220
|
+
button = button?.toButton(context) ?: CourierInboxButton()
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
159
225
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.courierreactnative
|
|
2
2
|
|
|
3
|
-
import com.courier.android.models
|
|
4
|
-
import com.courier.android.models.InboxMessage
|
|
3
|
+
import com.courier.android.models.*
|
|
5
4
|
import com.facebook.react.bridge.Arguments
|
|
6
5
|
import com.facebook.react.bridge.ReactContext
|
|
7
6
|
import com.facebook.react.bridge.WritableArray
|
|
@@ -12,9 +11,58 @@ internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
|
|
|
12
11
|
getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, value)
|
|
13
12
|
}
|
|
14
13
|
|
|
14
|
+
internal fun CourierUserPreferences.toWritableMap(): WritableMap {
|
|
15
|
+
|
|
16
|
+
val map = Arguments.createMap()
|
|
17
|
+
|
|
18
|
+
val itemsArray = Arguments.createArray()
|
|
19
|
+
items.forEach { topic ->
|
|
20
|
+
itemsArray.pushMap(topic.toWritableMap())
|
|
21
|
+
}
|
|
22
|
+
map.putArray("items", itemsArray)
|
|
23
|
+
|
|
24
|
+
map.putMap("paging", paging.toWritableMap())
|
|
25
|
+
|
|
26
|
+
return map
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
internal fun CourierPreferenceTopic.toWritableMap(): WritableMap {
|
|
31
|
+
|
|
32
|
+
val map = Arguments.createMap()
|
|
33
|
+
map.putString("defaultStatus", defaultStatus.value)
|
|
34
|
+
map.putBoolean("hasCustomRouting", hasCustomRouting)
|
|
35
|
+
map.putString("status", status.value)
|
|
36
|
+
map.putString("topicId", topicId)
|
|
37
|
+
map.putString("topicName", topicName)
|
|
38
|
+
|
|
39
|
+
val actionsArray = Arguments.createArray()
|
|
40
|
+
customRouting.forEach { routing ->
|
|
41
|
+
actionsArray.pushString(routing.value)
|
|
42
|
+
}
|
|
43
|
+
map.putArray("customRouting", actionsArray)
|
|
44
|
+
|
|
45
|
+
return map
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
internal fun Paging.toWritableMap(): WritableMap {
|
|
50
|
+
|
|
51
|
+
val map = Arguments.createMap()
|
|
52
|
+
|
|
53
|
+
cursor?.let {
|
|
54
|
+
map.putString("cursor", it)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
map.putBoolean("more", more)
|
|
58
|
+
|
|
59
|
+
return map
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
15
63
|
@JvmName("toWritableArrayInboxMessage")
|
|
16
64
|
internal fun List<InboxMessage>.toWritableArray(): WritableArray {
|
|
17
|
-
|
|
65
|
+
|
|
18
66
|
val messagesArray = Arguments.createArray()
|
|
19
67
|
|
|
20
68
|
forEach { message ->
|
|
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
|
|
|
17
17
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
18
|
|
|
19
19
|
# Courier Core Dependency
|
|
20
|
-
s.dependency "Courier_iOS", "2.
|
|
20
|
+
s.dependency "Courier_iOS", "2.7.2"
|
|
21
21
|
|
|
22
22
|
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
23
23
|
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>SchemeUserState</key>
|
|
6
|
+
<dict>
|
|
7
|
+
<key>CourierReactNative.xcscheme_^#shared#^_</key>
|
|
8
|
+
<dict>
|
|
9
|
+
<key>orderHint</key>
|
|
10
|
+
<integer>0</integer>
|
|
11
|
+
</dict>
|
|
12
|
+
</dict>
|
|
13
|
+
</dict>
|
|
14
|
+
</plist>
|
|
@@ -45,19 +45,15 @@ RCT_EXTERN_METHOD(
|
|
|
45
45
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
46
46
|
)
|
|
47
47
|
|
|
48
|
-
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
49
|
-
getApnsToken
|
|
50
|
-
)
|
|
51
|
-
|
|
52
48
|
RCT_EXTERN_METHOD(
|
|
53
|
-
|
|
49
|
+
setToken: (NSString*)key
|
|
50
|
+
withToken: (NSString*)token
|
|
51
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
54
52
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
55
53
|
)
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
60
|
-
withRejecter: (RCTPromiseRejectBlock)reject
|
|
55
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
56
|
+
getToken: (NSString*)key
|
|
61
57
|
)
|
|
62
58
|
|
|
63
59
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
@@ -95,6 +91,33 @@ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
|
95
91
|
setInboxPaginationLimit: (double)limit
|
|
96
92
|
)
|
|
97
93
|
|
|
94
|
+
RCT_EXTERN_METHOD(
|
|
95
|
+
getUserPreferences: (NSString*)paginationCursor
|
|
96
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
97
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
RCT_EXTERN_METHOD(
|
|
101
|
+
getUserPreferencesTopic: (NSString*)topicId
|
|
102
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
103
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
RCT_EXTERN_METHOD(
|
|
107
|
+
getUserPreferencesTopic: (NSString*)topicId
|
|
108
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
109
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
RCT_EXTERN_METHOD(
|
|
113
|
+
putUserPreferencesTopic: (NSString*)topicId
|
|
114
|
+
withStatus: (NSString*)status
|
|
115
|
+
withHasCustomRouting: (BOOL*)hasCustomRouting
|
|
116
|
+
withCustomRouting: (NSArray*)customRouting
|
|
117
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
118
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
119
|
+
)
|
|
120
|
+
|
|
98
121
|
RCT_EXTERN_METHOD(
|
|
99
122
|
registerPushNotificationClickedOnKilledState
|
|
100
123
|
)
|
|
@@ -226,11 +226,12 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
226
226
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
@objc(
|
|
230
|
-
func
|
|
229
|
+
@objc(setToken: withToken: withResolver: withRejecter:)
|
|
230
|
+
func setToken(key: NSString, token: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
231
231
|
|
|
232
|
-
Courier.shared.
|
|
233
|
-
|
|
232
|
+
Courier.shared.setToken(
|
|
233
|
+
providerKey: key as String,
|
|
234
|
+
token: token as String,
|
|
234
235
|
onSuccess: {
|
|
235
236
|
resolve(nil)
|
|
236
237
|
},
|
|
@@ -241,13 +242,9 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
241
242
|
|
|
242
243
|
}
|
|
243
244
|
|
|
244
|
-
@objc(
|
|
245
|
-
func
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
@objc func getApnsToken() -> String? {
|
|
250
|
-
return Courier.shared.apnsToken
|
|
245
|
+
@objc(getToken:)
|
|
246
|
+
func getToken(key: NSString) -> String? {
|
|
247
|
+
return Courier.shared.getToken(providerKey: key as String)
|
|
251
248
|
}
|
|
252
249
|
|
|
253
250
|
@objc(iOSForegroundPresentationOptions:)
|
|
@@ -380,6 +377,57 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
380
377
|
Courier.shared.inboxPaginationLimit = Int(limit)
|
|
381
378
|
return String(describing: Courier.shared.inboxPaginationLimit)
|
|
382
379
|
}
|
|
380
|
+
|
|
381
|
+
@objc(getUserPreferences: withResolver: withRejecter:)
|
|
382
|
+
func getUserPreferences(paginationCursor: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
383
|
+
|
|
384
|
+
let cursor = paginationCursor != "" ? paginationCursor as String : nil
|
|
385
|
+
|
|
386
|
+
Courier.shared.getUserPreferences(
|
|
387
|
+
paginationCursor: cursor,
|
|
388
|
+
onSuccess: { preferences in
|
|
389
|
+
resolve(preferences.toDictionary())
|
|
390
|
+
},
|
|
391
|
+
onFailure: { error in
|
|
392
|
+
reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
|
|
393
|
+
}
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
@objc(getUserPreferencesTopic: withResolver: withRejecter:)
|
|
399
|
+
func getUserPreferencesTopic(topicId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
400
|
+
|
|
401
|
+
Courier.shared.getUserPreferencesTopic(
|
|
402
|
+
topicId: topicId as String,
|
|
403
|
+
onSuccess: { topic in
|
|
404
|
+
resolve(topic.toDictionary())
|
|
405
|
+
},
|
|
406
|
+
onFailure: { error in
|
|
407
|
+
reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
|
|
408
|
+
}
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
@objc(putUserPreferencesTopic: withStatus: withHasCustomRouting: withCustomRouting: withResolver: withRejecter:)
|
|
414
|
+
func putUserPreferencesTopic(topicId: NSString, status: NSString, hasCustomRouting: Bool, customRouting: [NSString], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
Courier.shared.putUserPreferencesTopic(
|
|
418
|
+
topicId: topicId as String,
|
|
419
|
+
status: CourierUserPreferencesStatus(rawValue: status as String) ?? .unknown,
|
|
420
|
+
hasCustomRouting: hasCustomRouting,
|
|
421
|
+
customRouting: customRouting.map { CourierUserPreferencesChannel(rawValue: $0 as String) ?? .unknown },
|
|
422
|
+
onSuccess: {
|
|
423
|
+
resolve(nil)
|
|
424
|
+
},
|
|
425
|
+
onFailure: { error in
|
|
426
|
+
reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
|
|
427
|
+
}
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
}
|
|
383
431
|
|
|
384
432
|
override func supportedEvents() -> [String]! {
|
|
385
433
|
return [
|
|
@@ -432,18 +480,3 @@ extension NSDictionary {
|
|
|
432
480
|
}
|
|
433
481
|
|
|
434
482
|
}
|
|
435
|
-
|
|
436
|
-
extension UNAuthorizationStatus {
|
|
437
|
-
|
|
438
|
-
var name: String {
|
|
439
|
-
switch (self) {
|
|
440
|
-
case .notDetermined: return "notDetermined"
|
|
441
|
-
case .denied: return "denied"
|
|
442
|
-
case .authorized: return "authorized"
|
|
443
|
-
case .provisional: return "provisional"
|
|
444
|
-
case .ephemeral: return "ephemeral"
|
|
445
|
-
@unknown default: return "unknown"
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
}
|