@trycourier/courier-react-native 3.2.2 → 4.1.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 +14 -3
- package/android/build.gradle +4 -1
- package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +441 -0
- package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -2
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +4 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +9 -3
- package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +312 -0
- package/android/src/main/java/com/courierreactnative/CourierSystemModule.kt +91 -0
- package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +36 -0
- package/android/src/main/java/com/courierreactnative/{Extensions.kt → Utils.kt} +5 -5
- package/courier-react-native.podspec +1 -1
- package/ios/CourierClientModule.swift +450 -0
- package/ios/CourierInboxReactNativeManager.swift +17 -9
- package/ios/CourierReactNativeDelegate.m +21 -35
- package/ios/CourierReactNativeEventEmitter.swift +25 -0
- package/ios/CourierReactNativeModule.m +192 -23
- package/ios/CourierSharedModule.swift +412 -0
- package/ios/CourierSystemModule.swift +136 -0
- package/ios/Utils.swift +103 -115
- package/lib/commonjs/Broadcaster.js +30 -0
- package/lib/commonjs/Broadcaster.js.map +1 -0
- package/lib/commonjs/Modules.js +25 -0
- package/lib/commonjs/Modules.js.map +1 -0
- package/lib/commonjs/client/BrandClient.js +25 -0
- package/lib/commonjs/client/BrandClient.js.map +1 -0
- package/lib/commonjs/client/ClientModule.js +21 -0
- package/lib/commonjs/client/ClientModule.js.map +1 -0
- package/lib/commonjs/client/CourierClient.js +33 -0
- package/lib/commonjs/client/CourierClient.js.map +1 -0
- package/lib/commonjs/client/InboxClient.js +116 -0
- package/lib/commonjs/client/InboxClient.js.map +1 -0
- package/lib/commonjs/client/PreferenceClient.js +73 -0
- package/lib/commonjs/client/PreferenceClient.js.map +1 -0
- package/lib/commonjs/client/TokenClient.js +36 -0
- package/lib/commonjs/client/TokenClient.js.map +1 -0
- package/lib/commonjs/client/TrackingClient.js +25 -0
- package/lib/commonjs/client/TrackingClient.js.map +1 -0
- package/lib/commonjs/index.js +418 -186
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/Android_CourierSheet.js.map +1 -1
- package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/commonjs/models/CourierBrand.js +2 -0
- package/lib/commonjs/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
- package/lib/commonjs/models/CourierButton.js.map +1 -1
- package/lib/commonjs/models/CourierDevice.js +2 -0
- package/lib/commonjs/models/CourierDevice.js.map +1 -0
- package/lib/commonjs/models/CourierFont.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js +2 -2
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
- package/lib/commonjs/models/{CourierUserPreferencesTopic.js → CourierInboxMessages.js} +1 -1
- package/lib/commonjs/models/CourierInboxMessages.js.map +1 -0
- package/lib/commonjs/models/CourierInboxTheme.js.map +1 -1
- package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -1
- package/lib/commonjs/models/CourierPaging.js.map +1 -1
- package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -1
- package/lib/commonjs/models/CourierPushListener.js +7 -3
- package/lib/commonjs/models/CourierPushListener.js.map +1 -1
- package/lib/commonjs/models/CourierPushProvider.js.map +1 -1
- package/lib/commonjs/models/CourierTrackingEvent.js +16 -0
- package/lib/commonjs/models/CourierTrackingEvent.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferences.js +54 -0
- package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
- package/lib/commonjs/models/InboxAction.js.map +1 -1
- package/lib/commonjs/models/InboxMessage.js.map +1 -1
- package/lib/commonjs/models/iOS_CourierCell.js.map +1 -1
- package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -1
- package/lib/commonjs/utils.js +9 -17
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/views/CourierInboxView.js +3 -3
- package/lib/commonjs/views/CourierInboxView.js.map +1 -1
- package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
- package/lib/module/Broadcaster.js +23 -0
- package/lib/module/Broadcaster.js.map +1 -0
- package/lib/module/Modules.js +18 -0
- package/lib/module/Modules.js.map +1 -0
- package/lib/module/client/BrandClient.js +18 -0
- package/lib/module/client/BrandClient.js.map +1 -0
- package/lib/module/client/ClientModule.js +14 -0
- package/lib/module/client/ClientModule.js.map +1 -0
- package/lib/module/client/CourierClient.js +26 -0
- package/lib/module/client/CourierClient.js.map +1 -0
- package/lib/module/client/InboxClient.js +109 -0
- package/lib/module/client/InboxClient.js.map +1 -0
- package/lib/module/client/PreferenceClient.js +66 -0
- package/lib/module/client/PreferenceClient.js.map +1 -0
- package/lib/module/client/TokenClient.js +29 -0
- package/lib/module/client/TokenClient.js.map +1 -0
- package/lib/module/client/TrackingClient.js +18 -0
- package/lib/module/client/TrackingClient.js.map +1 -0
- package/lib/module/index.js +383 -185
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/Android_CourierSheet.js.map +1 -1
- package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/module/models/CourierBrand.js +2 -0
- package/lib/module/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
- package/lib/module/models/CourierButton.js.map +1 -1
- package/lib/module/models/CourierDevice.js +2 -0
- package/lib/module/models/CourierDevice.js.map +1 -0
- package/lib/module/models/CourierFont.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js +1 -1
- package/lib/module/models/CourierInboxListener.js.map +1 -1
- package/lib/module/models/CourierInboxMessages.js +2 -0
- package/lib/module/models/CourierInboxMessages.js.map +1 -0
- package/lib/module/models/CourierInboxTheme.js.map +1 -1
- package/lib/module/models/CourierInfoViewStyle.js.map +1 -1
- package/lib/module/models/CourierPaging.js.map +1 -1
- package/lib/module/models/CourierPreferencesTheme.js.map +1 -1
- package/lib/module/models/CourierPushListener.js +7 -3
- package/lib/module/models/CourierPushListener.js.map +1 -1
- package/lib/module/models/CourierPushProvider.js.map +1 -1
- package/lib/module/models/CourierTrackingEvent.js +9 -0
- package/lib/module/models/CourierTrackingEvent.js.map +1 -0
- package/lib/module/models/CourierUserPreferences.js +53 -1
- package/lib/module/models/CourierUserPreferences.js.map +1 -1
- package/lib/module/models/InboxAction.js.map +1 -1
- package/lib/module/models/InboxMessage.js.map +1 -1
- package/lib/module/models/iOS_CourierCell.js.map +1 -1
- package/lib/module/models/iOS_CourierSheet.js.map +1 -1
- package/lib/module/utils.js +7 -16
- package/lib/module/utils.js.map +1 -1
- package/lib/module/views/CourierInboxView.js +3 -3
- package/lib/module/views/CourierInboxView.js.map +1 -1
- package/lib/module/views/CourierPreferencesView.js.map +1 -1
- package/lib/typescript/src/Broadcaster.d.ts +14 -0
- package/lib/typescript/src/Broadcaster.d.ts.map +1 -0
- package/lib/typescript/src/Modules.d.ts +8 -0
- package/lib/typescript/src/Modules.d.ts.map +1 -0
- package/lib/typescript/src/client/BrandClient.d.ts +15 -0
- package/lib/typescript/src/client/BrandClient.d.ts.map +1 -0
- package/lib/typescript/src/client/ClientModule.d.ts +8 -0
- package/lib/typescript/src/client/ClientModule.d.ts.map +1 -0
- package/lib/typescript/src/client/CourierClient.d.ts +31 -0
- package/lib/typescript/src/client/CourierClient.d.ts.map +1 -0
- package/lib/typescript/src/client/InboxClient.d.ts +94 -0
- package/lib/typescript/src/client/InboxClient.d.ts.map +1 -0
- package/lib/typescript/src/client/PreferenceClient.d.ts +39 -0
- package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -0
- package/lib/typescript/src/client/TokenClient.d.ts +28 -0
- package/lib/typescript/src/client/TokenClient.d.ts.map +1 -0
- package/lib/typescript/src/client/TrackingClient.d.ts +17 -0
- package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +300 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierBrand.d.ts +20 -0
- package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierButton.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierDevice.d.ts +9 -0
- package/lib/typescript/src/models/CourierDevice.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierFont.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInboxMessages.d.ts +23 -0
- package/lib/typescript/src/models/CourierInboxMessages.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPaging.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPushListener.d.ts +8 -0
- package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPushProvider.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierTrackingEvent.d.ts +8 -0
- package/lib/typescript/src/models/CourierTrackingEvent.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierUserPreferences.d.ts +35 -0
- package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -0
- package/lib/typescript/src/models/InboxAction.d.ts.map +1 -0
- package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -0
- package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -0
- package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +14 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -0
- package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/Broadcaster.tsx +32 -0
- package/src/Modules.tsx +28 -0
- package/src/client/BrandClient.tsx +23 -0
- package/src/client/ClientModule.tsx +21 -0
- package/src/client/CourierClient.tsx +49 -0
- package/src/client/InboxClient.tsx +114 -0
- package/src/client/PreferenceClient.tsx +77 -0
- package/src/client/TokenClient.tsx +34 -0
- package/src/client/TrackingClient.tsx +23 -0
- package/src/index.tsx +398 -205
- package/src/models/CourierBrand.tsx +24 -0
- package/src/models/CourierDevice.tsx +8 -0
- package/src/models/CourierInboxListener.tsx +1 -1
- package/src/models/CourierInboxMessages.tsx +28 -0
- package/src/models/CourierPushListener.tsx +11 -6
- package/src/models/CourierTrackingEvent.tsx +7 -0
- package/src/models/CourierUserPreferences.tsx +70 -3
- package/src/utils.tsx +7 -23
- package/src/views/CourierInboxView.tsx +3 -3
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +0 -393
- package/ios/CourierReactNativeModule.swift +0 -524
- package/lib/commonjs/models/CourierUserPreferencesChannel.js +0 -17
- package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +0 -1
- package/lib/commonjs/models/CourierUserPreferencesStatus.js +0 -15
- package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +0 -1
- package/lib/module/models/CourierUserPreferencesChannel.js +0 -10
- package/lib/module/models/CourierUserPreferencesChannel.js.map +0 -1
- package/lib/module/models/CourierUserPreferencesStatus.js +0 -8
- package/lib/module/models/CourierUserPreferencesStatus.js.map +0 -1
- package/lib/module/models/CourierUserPreferencesTopic.js +0 -2
- package/lib/typescript/index.d.ts +0 -199
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/models/Android_CourierSheet.d.ts.map +0 -1
- package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +0 -1
- package/lib/typescript/models/CourierButton.d.ts.map +0 -1
- package/lib/typescript/models/CourierFont.d.ts.map +0 -1
- package/lib/typescript/models/CourierInboxListener.d.ts.map +0 -1
- package/lib/typescript/models/CourierInboxTheme.d.ts.map +0 -1
- package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +0 -1
- package/lib/typescript/models/CourierPaging.d.ts.map +0 -1
- package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +0 -1
- package/lib/typescript/models/CourierPushListener.d.ts +0 -7
- package/lib/typescript/models/CourierPushListener.d.ts.map +0 -1
- package/lib/typescript/models/CourierPushProvider.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferences.d.ts +0 -7
- package/lib/typescript/models/CourierUserPreferences.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +0 -9
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +0 -7
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +0 -13
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +0 -1
- package/lib/typescript/models/InboxAction.d.ts.map +0 -1
- package/lib/typescript/models/InboxMessage.d.ts.map +0 -1
- package/lib/typescript/models/iOS_CourierCell.d.ts.map +0 -1
- package/lib/typescript/models/iOS_CourierSheet.d.ts.map +0 -1
- package/lib/typescript/utils.d.ts +0 -21
- package/lib/typescript/utils.d.ts.map +0 -1
- package/lib/typescript/views/CourierInboxView.d.ts.map +0 -1
- package/lib/typescript/views/CourierPreferencesView.d.ts.map +0 -1
- package/src/models/CourierUserPreferencesChannel.tsx +0 -8
- package/src/models/CourierUserPreferencesStatus.tsx +0 -6
- package/src/models/CourierUserPreferencesTopic.tsx +0 -13
- /package/lib/typescript/{models → src/models}/Android_CourierSheet.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierAuthenticationListener.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierButton.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierFont.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierInboxListener.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierInboxTheme.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierInfoViewStyle.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierPaging.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierPreferencesTheme.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierPushProvider.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/InboxAction.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/InboxMessage.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/iOS_CourierCell.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/iOS_CourierSheet.d.ts +0 -0
- /package/lib/typescript/{views → src/views}/CourierInboxView.d.ts +0 -0
- /package/lib/typescript/{views → src/views}/CourierPreferencesView.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
<img width="1040" alt="banner-react-native" src="https://github.com/
|
|
1
|
+
<img width="1040" alt="banner-react-native" src="https://github.com/user-attachments/assets/c38f52d8-792f-4b51-a423-f1c5dd9f996b">
|
|
2
2
|
|
|
3
3
|
 
|
|
4
4
|
|
|
5
5
|
# Requirements & Support
|
|
6
6
|
|
|
7
|
-
 
|
|
8
|
-
|
|
9
7
|
<table>
|
|
10
8
|
<thead>
|
|
11
9
|
<tr>
|
|
@@ -199,6 +197,19 @@ These are all the available features of the SDK.
|
|
|
199
197
|
Allow users to update which types of notifications they would like to receive.
|
|
200
198
|
</td>
|
|
201
199
|
</tr>
|
|
200
|
+
<tr width="600px">
|
|
201
|
+
<td align="center">
|
|
202
|
+
5
|
|
203
|
+
</td>
|
|
204
|
+
<td align="left">
|
|
205
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/Client.md">
|
|
206
|
+
<code>CourierClient</code>
|
|
207
|
+
</a>
|
|
208
|
+
</td>
|
|
209
|
+
<td align="left">
|
|
210
|
+
The base level API wrapper around the Courier endpoints. Useful if you have a highly customized user experience or codebase requirements.
|
|
211
|
+
</td>
|
|
212
|
+
</tr>
|
|
202
213
|
</tbody>
|
|
203
214
|
</table>
|
|
204
215
|
|
package/android/build.gradle
CHANGED
|
@@ -100,8 +100,11 @@ dependencies {
|
|
|
100
100
|
implementation "com.facebook.react:react-native:+"
|
|
101
101
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
102
102
|
|
|
103
|
+
// For converting to json
|
|
104
|
+
implementation 'com.google.code.gson:gson:2.11.0'
|
|
105
|
+
|
|
103
106
|
// Courier Core SDK
|
|
104
|
-
api 'com.github.trycourier:courier-android:
|
|
107
|
+
api 'com.github.trycourier:courier-android:4.4.1'
|
|
105
108
|
api 'androidx.recyclerview:recyclerview:1.3.2'
|
|
106
109
|
|
|
107
110
|
}
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import com.courier.android.client.CourierClient
|
|
4
|
+
import com.courier.android.models.CourierDevice
|
|
5
|
+
import com.courier.android.models.CourierPreferenceChannel
|
|
6
|
+
import com.courier.android.models.CourierPreferenceStatus
|
|
7
|
+
import com.courier.android.models.CourierTrackingEvent
|
|
8
|
+
import com.facebook.react.bridge.Promise
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
|
+
import com.facebook.react.bridge.ReactMethod
|
|
11
|
+
import com.facebook.react.bridge.ReadableArray
|
|
12
|
+
import com.facebook.react.bridge.ReadableMap
|
|
13
|
+
import kotlinx.coroutines.CoroutineScope
|
|
14
|
+
import kotlinx.coroutines.Dispatchers
|
|
15
|
+
import kotlinx.coroutines.launch
|
|
16
|
+
import java.util.UUID
|
|
17
|
+
|
|
18
|
+
class CourierClientModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "Client Error", name = "CourierClientModule", reactContext = reactContext) {
|
|
19
|
+
|
|
20
|
+
private var clients: MutableMap<String, CourierClient> = mutableMapOf()
|
|
21
|
+
|
|
22
|
+
@ReactMethod
|
|
23
|
+
fun addListener(type: String?) {
|
|
24
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@ReactMethod
|
|
28
|
+
fun removeListeners(type: Int?) {
|
|
29
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
33
|
+
fun addClient(options: ReadableMap): String {
|
|
34
|
+
|
|
35
|
+
val userId = options.getString("userId")
|
|
36
|
+
val showLogs = if (options.hasKey("showLogs")) options.getBoolean("showLogs") else null
|
|
37
|
+
|
|
38
|
+
if (userId == null || showLogs == null) {
|
|
39
|
+
return "invalid"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
val client = CourierClient(
|
|
43
|
+
jwt = options.getString("jwt"),
|
|
44
|
+
clientKey = options.getString("clientKey"),
|
|
45
|
+
userId = userId,
|
|
46
|
+
connectionId = options.getString("connectionId"),
|
|
47
|
+
tenantId = options.getString("tenantId"),
|
|
48
|
+
showLogs = showLogs
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
val uuid = UUID.randomUUID().toString()
|
|
52
|
+
clients[uuid] = client
|
|
53
|
+
|
|
54
|
+
return uuid
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
59
|
+
fun removeClient(clientId: String): String {
|
|
60
|
+
clients.remove(clientId)
|
|
61
|
+
return clientId
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Tokens
|
|
65
|
+
|
|
66
|
+
@ReactMethod
|
|
67
|
+
fun putUserToken(clientId: String, token: String, provider: String, device: ReadableMap?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
68
|
+
|
|
69
|
+
val client = clients[clientId]
|
|
70
|
+
if (client == null) {
|
|
71
|
+
promise.rejectMissingClient()
|
|
72
|
+
return@launch
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (reactActivity == null) {
|
|
76
|
+
promise.rejectMissingContext()
|
|
77
|
+
return@launch
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
val courierDevice = device?.let {
|
|
81
|
+
return@let CourierDevice(
|
|
82
|
+
appId = it.getString("appId"),
|
|
83
|
+
adId = it.getString("adId"),
|
|
84
|
+
deviceId = it.getString("deviceId"),
|
|
85
|
+
platform = it.getString("platform"),
|
|
86
|
+
manufacturer = it.getString("manufacturer"),
|
|
87
|
+
model = it.getString("model")
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
client.tokens.putUserToken(
|
|
93
|
+
token = token,
|
|
94
|
+
provider = provider,
|
|
95
|
+
device = courierDevice ?: CourierDevice.current(reactActivity!!)
|
|
96
|
+
)
|
|
97
|
+
promise.resolve(null)
|
|
98
|
+
} catch (e: Exception) {
|
|
99
|
+
promise.apiError(e)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@ReactMethod
|
|
105
|
+
fun deleteUserToken(clientId: String, token: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
106
|
+
|
|
107
|
+
val client = clients[clientId]
|
|
108
|
+
if (client == null) {
|
|
109
|
+
promise.rejectMissingClient()
|
|
110
|
+
return@launch
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
client.tokens.deleteUserToken(
|
|
115
|
+
token = token,
|
|
116
|
+
)
|
|
117
|
+
promise.resolve(null)
|
|
118
|
+
} catch (e: Exception) {
|
|
119
|
+
promise.apiError(e)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Brands
|
|
125
|
+
|
|
126
|
+
@ReactMethod
|
|
127
|
+
fun getBrand(clientId: String, brandId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
128
|
+
|
|
129
|
+
val client = clients[clientId]
|
|
130
|
+
if (client == null) {
|
|
131
|
+
promise.rejectMissingClient()
|
|
132
|
+
return@launch
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
val brand = client.brands.getBrand(
|
|
137
|
+
brandId = brandId
|
|
138
|
+
)
|
|
139
|
+
val json = brand.toJson()
|
|
140
|
+
promise.resolve(json)
|
|
141
|
+
} catch (e: Exception) {
|
|
142
|
+
promise.apiError(e)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Inbox
|
|
148
|
+
|
|
149
|
+
@ReactMethod
|
|
150
|
+
fun getMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
151
|
+
|
|
152
|
+
val client = clients[clientId]
|
|
153
|
+
if (client == null) {
|
|
154
|
+
promise.rejectMissingClient()
|
|
155
|
+
return@launch
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
val res = client.inbox.getMessages(
|
|
160
|
+
paginationLimit = paginationLimit,
|
|
161
|
+
startCursor = startCursor,
|
|
162
|
+
)
|
|
163
|
+
val json = res.toJson()
|
|
164
|
+
promise.resolve(json)
|
|
165
|
+
} catch (e: Exception) {
|
|
166
|
+
promise.apiError(e)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@ReactMethod
|
|
172
|
+
fun getArchivedMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
173
|
+
|
|
174
|
+
val client = clients[clientId]
|
|
175
|
+
if (client == null) {
|
|
176
|
+
promise.rejectMissingClient()
|
|
177
|
+
return@launch
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
val res = client.inbox.getArchivedMessages(
|
|
182
|
+
paginationLimit = paginationLimit,
|
|
183
|
+
startCursor = startCursor,
|
|
184
|
+
)
|
|
185
|
+
val json = res.toJson()
|
|
186
|
+
promise.resolve(json)
|
|
187
|
+
} catch (e: Exception) {
|
|
188
|
+
promise.apiError(e)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@ReactMethod
|
|
194
|
+
fun getMessageById(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
195
|
+
|
|
196
|
+
val client = clients[clientId]
|
|
197
|
+
if (client == null) {
|
|
198
|
+
promise.rejectMissingClient()
|
|
199
|
+
return@launch
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
val res = client.inbox.getMessage(
|
|
204
|
+
messageId = messageId,
|
|
205
|
+
)
|
|
206
|
+
val json = res.toJson()
|
|
207
|
+
promise.resolve(json)
|
|
208
|
+
} catch (e: Exception) {
|
|
209
|
+
promise.apiError(e)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@ReactMethod
|
|
215
|
+
fun getUnreadMessageCount(clientId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
216
|
+
|
|
217
|
+
val client = clients[clientId]
|
|
218
|
+
if (client == null) {
|
|
219
|
+
promise.rejectMissingClient()
|
|
220
|
+
return@launch
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
val count = client.inbox.getUnreadMessageCount()
|
|
225
|
+
promise.resolve(count)
|
|
226
|
+
} catch (e: Exception) {
|
|
227
|
+
promise.apiError(e)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
@ReactMethod
|
|
233
|
+
fun openMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
234
|
+
|
|
235
|
+
val client = clients[clientId]
|
|
236
|
+
if (client == null) {
|
|
237
|
+
promise.rejectMissingClient()
|
|
238
|
+
return@launch
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
client.inbox.open(
|
|
243
|
+
messageId = messageId,
|
|
244
|
+
)
|
|
245
|
+
promise.resolve(null)
|
|
246
|
+
} catch (e: Exception) {
|
|
247
|
+
promise.apiError(e)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
@ReactMethod
|
|
253
|
+
fun readMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
254
|
+
|
|
255
|
+
val client = clients[clientId]
|
|
256
|
+
if (client == null) {
|
|
257
|
+
promise.rejectMissingClient()
|
|
258
|
+
return@launch
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
client.inbox.read(
|
|
263
|
+
messageId = messageId,
|
|
264
|
+
)
|
|
265
|
+
promise.resolve(null)
|
|
266
|
+
} catch (e: Exception) {
|
|
267
|
+
promise.apiError(e)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
@ReactMethod
|
|
273
|
+
fun unreadMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
274
|
+
|
|
275
|
+
val client = clients[clientId]
|
|
276
|
+
if (client == null) {
|
|
277
|
+
promise.rejectMissingClient()
|
|
278
|
+
return@launch
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
try {
|
|
282
|
+
client.inbox.unread(
|
|
283
|
+
messageId = messageId,
|
|
284
|
+
)
|
|
285
|
+
promise.resolve(null)
|
|
286
|
+
} catch (e: Exception) {
|
|
287
|
+
promise.apiError(e)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
@ReactMethod
|
|
293
|
+
fun clickMessage(clientId: String, messageId: String, trackingId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
294
|
+
|
|
295
|
+
val client = clients[clientId]
|
|
296
|
+
if (client == null) {
|
|
297
|
+
promise.rejectMissingClient()
|
|
298
|
+
return@launch
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
client.inbox.click(
|
|
303
|
+
messageId = messageId,
|
|
304
|
+
trackingId = trackingId,
|
|
305
|
+
)
|
|
306
|
+
promise.resolve(null)
|
|
307
|
+
} catch (e: Exception) {
|
|
308
|
+
promise.apiError(e)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
@ReactMethod
|
|
314
|
+
fun archiveMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
315
|
+
|
|
316
|
+
val client = clients[clientId]
|
|
317
|
+
if (client == null) {
|
|
318
|
+
promise.rejectMissingClient()
|
|
319
|
+
return@launch
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
try {
|
|
323
|
+
client.inbox.archive(
|
|
324
|
+
messageId = messageId,
|
|
325
|
+
)
|
|
326
|
+
promise.resolve(null)
|
|
327
|
+
} catch (e: Exception) {
|
|
328
|
+
promise.apiError(e)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
@ReactMethod
|
|
334
|
+
fun readAllMessages(clientId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
335
|
+
|
|
336
|
+
val client = clients[clientId]
|
|
337
|
+
if (client == null) {
|
|
338
|
+
promise.rejectMissingClient()
|
|
339
|
+
return@launch
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
client.inbox.readAll()
|
|
344
|
+
promise.resolve(null)
|
|
345
|
+
} catch (e: Exception) {
|
|
346
|
+
promise.apiError(e)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Preferences
|
|
352
|
+
|
|
353
|
+
@ReactMethod
|
|
354
|
+
fun getUserPreferences(clientId: String, paginationCursor: String?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
355
|
+
|
|
356
|
+
val client = clients[clientId]
|
|
357
|
+
if (client == null) {
|
|
358
|
+
promise.rejectMissingClient()
|
|
359
|
+
return@launch
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
try {
|
|
363
|
+
val res = client.preferences.getUserPreferences(
|
|
364
|
+
paginationCursor = paginationCursor
|
|
365
|
+
)
|
|
366
|
+
val json = res.toJson()
|
|
367
|
+
promise.resolve(json)
|
|
368
|
+
} catch (e: Exception) {
|
|
369
|
+
promise.apiError(e)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
@ReactMethod
|
|
375
|
+
fun getUserPreferenceTopic(clientId: String, topicId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
376
|
+
|
|
377
|
+
val client = clients[clientId]
|
|
378
|
+
if (client == null) {
|
|
379
|
+
promise.rejectMissingClient()
|
|
380
|
+
return@launch
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
try {
|
|
384
|
+
val res = client.preferences.getUserPreferenceTopic(
|
|
385
|
+
topicId = topicId
|
|
386
|
+
)
|
|
387
|
+
val json = res.toJson()
|
|
388
|
+
promise.resolve(json)
|
|
389
|
+
} catch (e: Exception) {
|
|
390
|
+
promise.apiError(e)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
@ReactMethod
|
|
396
|
+
fun putUserPreferenceTopic(clientId: String, topicId: String, status: String, hasCustomRouting: Boolean, customRouting: ReadableArray, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
397
|
+
|
|
398
|
+
val client = clients[clientId]
|
|
399
|
+
if (client == null) {
|
|
400
|
+
promise.rejectMissingClient()
|
|
401
|
+
return@launch
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
try {
|
|
405
|
+
client.preferences.putUserPreferenceTopic(
|
|
406
|
+
topicId = topicId,
|
|
407
|
+
status = CourierPreferenceStatus.fromString(status),
|
|
408
|
+
hasCustomRouting = hasCustomRouting,
|
|
409
|
+
customRouting = customRouting.toArrayList().map { CourierPreferenceChannel.fromString(it as String) },
|
|
410
|
+
)
|
|
411
|
+
promise.resolve(null)
|
|
412
|
+
} catch (e: Exception) {
|
|
413
|
+
promise.apiError(e)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Tracking
|
|
419
|
+
|
|
420
|
+
@ReactMethod
|
|
421
|
+
fun postTrackingUrl(clientId: String, url: String, event: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
422
|
+
|
|
423
|
+
val client = clients[clientId]
|
|
424
|
+
if (client == null) {
|
|
425
|
+
promise.rejectMissingClient()
|
|
426
|
+
return@launch
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
try {
|
|
430
|
+
client.tracking.postTrackingUrl(
|
|
431
|
+
url = url,
|
|
432
|
+
event = CourierTrackingEvent.valueOf(event.uppercase()),
|
|
433
|
+
)
|
|
434
|
+
promise.resolve(null)
|
|
435
|
+
} catch (e: Exception) {
|
|
436
|
+
promise.apiError(e)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
}
|
|
@@ -51,7 +51,7 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
51
51
|
|
|
52
52
|
view.setOnClickMessageListener { message, index ->
|
|
53
53
|
val map = Arguments.createMap()
|
|
54
|
-
map.
|
|
54
|
+
map.putString("message", message.toJson())
|
|
55
55
|
map.putInt("index", index)
|
|
56
56
|
themedReactContext?.sendEvent(ON_CLICK_MESSAGE_AT_INDEX, map)
|
|
57
57
|
}
|
|
@@ -64,7 +64,7 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
64
64
|
view.setOnClickActionListener { action, message, index ->
|
|
65
65
|
val map = Arguments.createMap()
|
|
66
66
|
map.putMap("action", action.toWritableMap())
|
|
67
|
-
map.
|
|
67
|
+
map.putString("message", message.toJson())
|
|
68
68
|
map.putInt("index", index)
|
|
69
69
|
themedReactContext?.sendEvent(ON_CLICK_ACTION_AT_INDEX, map)
|
|
70
70
|
}
|
|
@@ -3,6 +3,7 @@ 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.models.CourierAgent
|
|
6
7
|
import com.courier.android.utils.getLastDeliveredMessage
|
|
7
8
|
import com.courier.android.utils.pushNotification
|
|
8
9
|
import com.courier.android.utils.trackPushNotificationClick
|
|
@@ -18,6 +19,9 @@ open class CourierReactNativeActivity : ReactActivity() {
|
|
|
18
19
|
// Used to ensure shared preferences works properly
|
|
19
20
|
Courier.initialize(this)
|
|
20
21
|
|
|
22
|
+
// Update the user agent
|
|
23
|
+
Courier.agent = CourierAgent.ReactNativeAndroid(version = "4.1.0")
|
|
24
|
+
|
|
21
25
|
super.onCreate(savedInstanceState)
|
|
22
26
|
|
|
23
27
|
// See if there is a pending click event
|
|
@@ -5,15 +5,21 @@ import com.facebook.react.bridge.NativeModule
|
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
6
|
import com.facebook.react.uimanager.ViewManager
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
class CourierReactNativePackage : ReactPackage {
|
|
10
9
|
|
|
11
10
|
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
12
|
-
return listOf(
|
|
11
|
+
return listOf(
|
|
12
|
+
CourierClientModule(reactContext),
|
|
13
|
+
CourierSharedModule(reactContext),
|
|
14
|
+
CourierSystemModule(reactContext),
|
|
15
|
+
)
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
16
|
-
return listOf(
|
|
19
|
+
return listOf(
|
|
20
|
+
CourierInboxViewManager(),
|
|
21
|
+
CourierPreferencesViewManager(),
|
|
22
|
+
)
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
}
|