@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
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import com.courier.android.Courier
|
|
4
|
+
import com.courier.android.models.CourierAuthenticationListener
|
|
5
|
+
import com.courier.android.models.CourierInboxListener
|
|
6
|
+
import com.courier.android.models.InboxMessage
|
|
7
|
+
import com.courier.android.models.remove
|
|
8
|
+
import com.courier.android.modules.addAuthenticationListener
|
|
9
|
+
import com.courier.android.modules.addInboxListener
|
|
10
|
+
import com.courier.android.modules.archiveMessage
|
|
11
|
+
import com.courier.android.modules.clickMessage
|
|
12
|
+
import com.courier.android.modules.fetchNextInboxPage
|
|
13
|
+
import com.courier.android.modules.getToken
|
|
14
|
+
import com.courier.android.modules.inboxPaginationLimit
|
|
15
|
+
import com.courier.android.modules.isUserSignedIn
|
|
16
|
+
import com.courier.android.modules.openMessage
|
|
17
|
+
import com.courier.android.modules.readAllInboxMessages
|
|
18
|
+
import com.courier.android.modules.readMessage
|
|
19
|
+
import com.courier.android.modules.refreshInbox
|
|
20
|
+
import com.courier.android.modules.setToken
|
|
21
|
+
import com.courier.android.modules.signIn
|
|
22
|
+
import com.courier.android.modules.signOut
|
|
23
|
+
import com.courier.android.modules.tenantId
|
|
24
|
+
import com.courier.android.modules.tokens
|
|
25
|
+
import com.courier.android.modules.unreadMessage
|
|
26
|
+
import com.courier.android.modules.userId
|
|
27
|
+
import com.facebook.react.bridge.Arguments
|
|
28
|
+
import com.facebook.react.bridge.Promise
|
|
29
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
30
|
+
import com.facebook.react.bridge.ReactMethod
|
|
31
|
+
import kotlinx.coroutines.CoroutineScope
|
|
32
|
+
import kotlinx.coroutines.Dispatchers
|
|
33
|
+
import kotlinx.coroutines.launch
|
|
34
|
+
import java.util.UUID
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "Shared Instance Error", name = "CourierSharedModule", reactContext = reactContext) {
|
|
38
|
+
|
|
39
|
+
// Listeners
|
|
40
|
+
private var authenticationListeners = mutableMapOf<String, CourierAuthenticationListener>()
|
|
41
|
+
private var inboxListeners = mutableMapOf<String, CourierInboxListener>()
|
|
42
|
+
|
|
43
|
+
@ReactMethod
|
|
44
|
+
fun addListener(type: String?) {
|
|
45
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ReactMethod
|
|
49
|
+
fun removeListeners(type: Int?) {
|
|
50
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Client
|
|
54
|
+
|
|
55
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
56
|
+
fun getClient(): String? {
|
|
57
|
+
val options = Courier.shared.client?.options ?: return null
|
|
58
|
+
return options.toJson()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Authentication
|
|
62
|
+
|
|
63
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
64
|
+
fun getUserId(): String? {
|
|
65
|
+
return Courier.shared.userId
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
69
|
+
fun getTenantId(): String? {
|
|
70
|
+
return Courier.shared.tenantId
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
74
|
+
fun getIsUserSignedIn(): String {
|
|
75
|
+
return Courier.shared.isUserSignedIn.toString()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@ReactMethod
|
|
79
|
+
fun signIn(accessToken: String, clientKey: String?, userId: String, tenantId: String?, showLogs: Boolean, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
80
|
+
Courier.shared.signIn(
|
|
81
|
+
userId = userId,
|
|
82
|
+
tenantId = tenantId,
|
|
83
|
+
accessToken = accessToken,
|
|
84
|
+
clientKey = clientKey,
|
|
85
|
+
showLogs = showLogs
|
|
86
|
+
)
|
|
87
|
+
promise.resolve(null)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@ReactMethod
|
|
91
|
+
fun signOut(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
92
|
+
Courier.shared.signOut()
|
|
93
|
+
promise.resolve(null)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
97
|
+
fun addAuthenticationListener(listenerId: String): String {
|
|
98
|
+
|
|
99
|
+
// Create the listener
|
|
100
|
+
val listener = Courier.shared.addAuthenticationListener { userId ->
|
|
101
|
+
reactApplicationContext.sendEvent(
|
|
102
|
+
eventName = listenerId,
|
|
103
|
+
value = userId
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Add the listener to the map
|
|
108
|
+
authenticationListeners[listenerId] = listener
|
|
109
|
+
|
|
110
|
+
return listenerId
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
115
|
+
fun removeAuthenticationListener(listenerId: String): String {
|
|
116
|
+
|
|
117
|
+
val listener = authenticationListeners[listenerId]
|
|
118
|
+
|
|
119
|
+
// Disable the listener
|
|
120
|
+
listener?.remove()
|
|
121
|
+
|
|
122
|
+
// Remove the id from the map
|
|
123
|
+
authenticationListeners.remove(listenerId)
|
|
124
|
+
|
|
125
|
+
return listenerId
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
130
|
+
fun removeAllAuthenticationListeners(): String? {
|
|
131
|
+
authenticationListeners.values.forEach { it.remove() }
|
|
132
|
+
authenticationListeners.clear()
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Push
|
|
137
|
+
|
|
138
|
+
@ReactMethod
|
|
139
|
+
fun getAllTokens(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
140
|
+
val tokens = Courier.shared.tokens
|
|
141
|
+
val resultMap = Arguments.createMap()
|
|
142
|
+
tokens.forEach { (key, value) ->
|
|
143
|
+
resultMap.putString(key, value)
|
|
144
|
+
}
|
|
145
|
+
promise.resolve(resultMap)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@ReactMethod
|
|
149
|
+
fun getToken(provider: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
150
|
+
val token = Courier.shared.getToken(provider)
|
|
151
|
+
promise.resolve(token)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@ReactMethod
|
|
155
|
+
fun setToken(provider: String, token: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
156
|
+
try {
|
|
157
|
+
Courier.shared.setToken(provider, token)
|
|
158
|
+
promise.resolve(null)
|
|
159
|
+
} catch (e: Exception) {
|
|
160
|
+
promise.apiError(e)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Inbox
|
|
165
|
+
|
|
166
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
167
|
+
fun getInboxPaginationLimit(): String {
|
|
168
|
+
return Courier.shared.inboxPaginationLimit.toString()
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
172
|
+
fun setInboxPaginationLimit(limit: Double): String {
|
|
173
|
+
Courier.shared.inboxPaginationLimit = limit.toInt()
|
|
174
|
+
return Courier.shared.inboxPaginationLimit.toString()
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@ReactMethod
|
|
178
|
+
fun openMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
179
|
+
try {
|
|
180
|
+
Courier.shared.openMessage(messageId)
|
|
181
|
+
promise.resolve(null)
|
|
182
|
+
} catch (e: Exception) {
|
|
183
|
+
promise.apiError(e)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@ReactMethod
|
|
188
|
+
fun archiveMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
189
|
+
try {
|
|
190
|
+
Courier.shared.archiveMessage(messageId)
|
|
191
|
+
promise.resolve(null)
|
|
192
|
+
} catch (e: Exception) {
|
|
193
|
+
promise.apiError(e)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@ReactMethod
|
|
198
|
+
fun clickMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
199
|
+
try {
|
|
200
|
+
Courier.shared.clickMessage(messageId)
|
|
201
|
+
promise.resolve(null)
|
|
202
|
+
} catch (e: Exception) {
|
|
203
|
+
promise.apiError(e)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
@ReactMethod
|
|
208
|
+
fun readMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
209
|
+
try {
|
|
210
|
+
Courier.shared.readMessage(messageId)
|
|
211
|
+
promise.resolve(null)
|
|
212
|
+
} catch (e: Exception) {
|
|
213
|
+
promise.apiError(e)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
@ReactMethod
|
|
218
|
+
fun unreadMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
219
|
+
try {
|
|
220
|
+
Courier.shared.unreadMessage(messageId)
|
|
221
|
+
promise.resolve(null)
|
|
222
|
+
} catch (e: Exception) {
|
|
223
|
+
promise.apiError(e)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@ReactMethod
|
|
228
|
+
fun readAllInboxMessages(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
229
|
+
try {
|
|
230
|
+
Courier.shared.readAllInboxMessages()
|
|
231
|
+
promise.resolve(null)
|
|
232
|
+
} catch (e: Exception) {
|
|
233
|
+
promise.apiError(e)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
238
|
+
fun addInboxListener(loadingId: String, errorId: String, messagesId: String): String {
|
|
239
|
+
|
|
240
|
+
val listener = Courier.shared.addInboxListener(
|
|
241
|
+
onInitialLoad = {
|
|
242
|
+
|
|
243
|
+
reactApplicationContext.sendEvent(
|
|
244
|
+
eventName = loadingId,
|
|
245
|
+
value = null
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
},
|
|
249
|
+
onError = { e ->
|
|
250
|
+
|
|
251
|
+
reactApplicationContext.sendEvent(
|
|
252
|
+
eventName = errorId,
|
|
253
|
+
value = e.message ?: "Courier Inbox Error"
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
},
|
|
257
|
+
onMessagesChanged = { messages: List<InboxMessage>, unreadMessageCount: Int, totalMessageCount: Int, canPaginate: Boolean ->
|
|
258
|
+
|
|
259
|
+
val json = Arguments.createMap()
|
|
260
|
+
json.putArray("messages", messages.toList().map { it.toJson() }.toWritableArray())
|
|
261
|
+
json.putInt("unreadMessageCount", unreadMessageCount)
|
|
262
|
+
json.putInt("totalMessageCount", totalMessageCount)
|
|
263
|
+
json.putBoolean("canPaginate", canPaginate)
|
|
264
|
+
|
|
265
|
+
reactApplicationContext.sendEvent(
|
|
266
|
+
eventName = messagesId,
|
|
267
|
+
value = json
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
// Add listener
|
|
274
|
+
val id = UUID.randomUUID().toString()
|
|
275
|
+
inboxListeners[id] = listener
|
|
276
|
+
|
|
277
|
+
return id
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
282
|
+
fun removeInboxListener(listenerId: String): String {
|
|
283
|
+
val listener = inboxListeners[listenerId]
|
|
284
|
+
listener?.remove()
|
|
285
|
+
inboxListeners.remove(listenerId)
|
|
286
|
+
return listenerId
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
290
|
+
fun removeAllInboxListeners(): String? {
|
|
291
|
+
inboxListeners.values.forEach { it.remove() }
|
|
292
|
+
inboxListeners.clear()
|
|
293
|
+
return null
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
@ReactMethod
|
|
297
|
+
fun refreshInbox(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
298
|
+
Courier.shared.refreshInbox()
|
|
299
|
+
promise.resolve(null)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
@ReactMethod
|
|
303
|
+
fun fetchNextPageOfMessages(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
304
|
+
try {
|
|
305
|
+
val messages = Courier.shared.fetchNextInboxPage()
|
|
306
|
+
promise.resolve(messages.map { it.toJson() }.toWritableArray())
|
|
307
|
+
} catch (e: Exception) {
|
|
308
|
+
promise.apiError(e)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import android.provider.Settings
|
|
5
|
+
import com.courier.android.Courier
|
|
6
|
+
import com.courier.android.modules.isPushPermissionGranted
|
|
7
|
+
import com.courier.android.modules.requestNotificationPermission
|
|
8
|
+
import com.courier.android.utils.error
|
|
9
|
+
import com.courier.android.utils.pushNotification
|
|
10
|
+
import com.courier.android.utils.trackPushNotificationClick
|
|
11
|
+
import com.facebook.react.bridge.Promise
|
|
12
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
13
|
+
import com.facebook.react.bridge.ReactMethod
|
|
14
|
+
import com.google.firebase.messaging.RemoteMessage
|
|
15
|
+
import org.json.JSONObject
|
|
16
|
+
|
|
17
|
+
class CourierSystemModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "System Error", name = "CourierSystemModule", reactContext = reactContext) {
|
|
18
|
+
|
|
19
|
+
@ReactMethod
|
|
20
|
+
fun addListener(type: String?) {
|
|
21
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@ReactMethod
|
|
25
|
+
fun removeListeners(type: Int?) {
|
|
26
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@ReactMethod
|
|
30
|
+
fun registerPushNotificationClickedOnKilledState() {
|
|
31
|
+
reactActivity?.let { activity ->
|
|
32
|
+
checkIntentForPushNotificationClick(activity.intent)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private fun checkIntentForPushNotificationClick(intent: Intent?) {
|
|
37
|
+
intent?.trackPushNotificationClick { message ->
|
|
38
|
+
postPushNotificationClicked(message)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private fun postPushNotificationClicked(message: RemoteMessage) {
|
|
43
|
+
reactApplicationContext.sendEvent(
|
|
44
|
+
eventName = CourierEvents.Push.CLICKED_EVENT,
|
|
45
|
+
value = JSONObject(message.pushNotification).toString()
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@ReactMethod
|
|
50
|
+
fun requestNotificationPermission(promise: Promise) {
|
|
51
|
+
|
|
52
|
+
reactActivity?.let { activity ->
|
|
53
|
+
Courier.shared.requestNotificationPermission(activity)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
promise.resolve("unknown")
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@ReactMethod
|
|
61
|
+
fun getNotificationPermissionStatus(promise: Promise) {
|
|
62
|
+
|
|
63
|
+
reactActivity?.let { context ->
|
|
64
|
+
|
|
65
|
+
val isGranted = Courier.shared.isPushPermissionGranted(context)
|
|
66
|
+
val status = if (isGranted) "authorized" else "denied"
|
|
67
|
+
promise.resolve(status)
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
promise.resolve("unknown")
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
77
|
+
fun openSettingsForApp(): String? {
|
|
78
|
+
// TODO: Move this to the native package in the future
|
|
79
|
+
val context = reactApplicationContext
|
|
80
|
+
try {
|
|
81
|
+
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
|
82
|
+
intent.data = android.net.Uri.parse("package:" + context.packageName)
|
|
83
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
84
|
+
context.startActivity(intent)
|
|
85
|
+
} catch (e: Exception) {
|
|
86
|
+
Courier.shared.client?.error(e.toString())
|
|
87
|
+
}
|
|
88
|
+
return null
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import com.courier.android.Courier
|
|
4
|
+
import com.courier.android.models.CourierAgent
|
|
5
|
+
import com.facebook.react.ReactActivity
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
9
|
+
|
|
10
|
+
abstract class ReactNativeModule(val tag: String, private val name: String, reactContext: ReactApplicationContext): ReactContextBaseJavaModule(reactContext) {
|
|
11
|
+
|
|
12
|
+
override fun getName() = name
|
|
13
|
+
|
|
14
|
+
val reactActivity: ReactActivity? get() = currentActivity as? ReactActivity
|
|
15
|
+
|
|
16
|
+
init {
|
|
17
|
+
|
|
18
|
+
// User Agent is used to ensure we know the SDK
|
|
19
|
+
// the requests come from
|
|
20
|
+
Courier.agent = CourierAgent.ReactNativeAndroid(version = "4.1.0")
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
internal fun Promise.rejectMissingContext() {
|
|
25
|
+
reject("Missing Context", tag, null)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
internal fun Promise.rejectMissingClient() {
|
|
29
|
+
reject("Missing Client", tag, null)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
internal fun Promise.apiError(throwable: Throwable) {
|
|
33
|
+
reject(throwable.message, tag, throwable)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
@@ -16,6 +16,7 @@ import com.facebook.react.bridge.ReadableMap
|
|
|
16
16
|
import com.facebook.react.bridge.WritableArray
|
|
17
17
|
import com.facebook.react.bridge.WritableMap
|
|
18
18
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
19
|
+
import com.google.gson.GsonBuilder
|
|
19
20
|
|
|
20
21
|
internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
|
|
21
22
|
getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, value)
|
|
@@ -108,12 +109,7 @@ internal fun InboxMessage.toWritableMap(): WritableMap {
|
|
|
108
109
|
map.putBoolean("archived", isArchived)
|
|
109
110
|
|
|
110
111
|
val trackingIds = Arguments.createMap()
|
|
111
|
-
trackingIds.putString("archiveTrackingId", archiveTrackingId)
|
|
112
|
-
trackingIds.putString("openTrackingId", openTrackingId)
|
|
113
112
|
trackingIds.putString("clickTrackingId", clickTrackingId)
|
|
114
|
-
trackingIds.putString("deliverTrackingId", deliverTrackingId)
|
|
115
|
-
trackingIds.putString("unreadTrackingId", unreadTrackingId)
|
|
116
|
-
trackingIds.putString("readTrackingId", readTrackingId)
|
|
117
113
|
|
|
118
114
|
map.putMap("trackingIds", trackingIds)
|
|
119
115
|
|
|
@@ -218,3 +214,7 @@ internal fun ReadableMap.toInfoViewStyle(context: Context): CourierStyles.InfoVi
|
|
|
218
214
|
)
|
|
219
215
|
|
|
220
216
|
}
|
|
217
|
+
|
|
218
|
+
internal fun Any.toJson(): String {
|
|
219
|
+
return GsonBuilder().setPrettyPrinting().create().toJson(this)
|
|
220
|
+
}
|
|
@@ -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", "
|
|
20
|
+
s.dependency "Courier_iOS", "4.4.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.
|