@trycourier/courier-react-native 5.4.3 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +2 -2
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +298 -303
- package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +194 -165
- package/android/src/main/java/com/courierreactnative/Utils.kt +1 -1
- package/courier-react-native.podspec +1 -1
- package/ios/CourierReactNativeDelegate.m +12 -8
- package/ios/CourierReactNativeEventEmitter.swift +1 -1
- package/ios/CourierReactNativeModule.m +3 -5
- package/ios/CourierSharedModule.swift +88 -112
- package/lib/commonjs/index.js +75 -93
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js +1 -0
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
- package/lib/commonjs/models/InboxAction.js +22 -0
- package/lib/commonjs/models/InboxAction.js.map +1 -1
- package/lib/commonjs/models/InboxMessage.js +64 -0
- package/lib/commonjs/models/InboxMessage.js.map +1 -1
- package/lib/commonjs/models/InboxMessageEvent.js +2 -0
- package/lib/commonjs/models/InboxMessageEvent.js.map +1 -0
- package/lib/commonjs/views/CourierInboxView.js +6 -4
- package/lib/commonjs/views/CourierInboxView.js.map +1 -1
- package/lib/example/src/App.js +11 -0
- package/lib/example/src/Emitter.js +11 -0
- package/lib/example/src/Env.js +6 -0
- package/lib/example/src/Home.js +67 -0
- package/lib/example/src/Poke.js +75 -0
- package/lib/example/src/Tabs.js +36 -0
- package/lib/example/src/Utils.js +71 -0
- package/lib/example/src/pages/Auth.js +224 -0
- package/lib/example/src/pages/Inbox.js +38 -0
- package/lib/example/src/pages/Preferences.js +13 -0
- package/lib/example/src/pages/PreferencesStack.js +11 -0
- package/lib/example/src/pages/Push.js +93 -0
- package/lib/example/src/pages/Styles.js +26 -0
- package/lib/example/src/pages/Tests.js +1068 -0
- package/lib/example/src/pages/inbox/InboxCustom.js +141 -0
- package/lib/example/src/pages/inbox/InboxDefault.js +22 -0
- package/lib/example/src/pages/inbox/InboxStyled.js +220 -0
- package/lib/example/src/pages/preferences/PreferencesCustom.js +91 -0
- package/lib/example/src/pages/preferences/PreferencesDefault.js +17 -0
- package/lib/example/src/pages/preferences/PreferencesDetail.js +127 -0
- package/lib/example/src/pages/preferences/PreferencesStyled.js +110 -0
- package/lib/module/index.js +67 -90
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js +1 -0
- package/lib/module/models/CourierInboxListener.js.map +1 -1
- package/lib/module/models/InboxAction.js +16 -1
- package/lib/module/models/InboxAction.js.map +1 -1
- package/lib/module/models/InboxMessage.js +61 -1
- package/lib/module/models/InboxMessage.js.map +1 -1
- package/lib/module/models/InboxMessageEvent.js +2 -0
- package/lib/module/models/InboxMessageEvent.js.map +1 -0
- package/lib/module/views/CourierInboxView.js +6 -4
- package/lib/module/views/CourierInboxView.js.map +1 -1
- package/lib/package.json +171 -0
- package/lib/src/Broadcaster.js +24 -0
- package/lib/src/Modules.js +26 -0
- package/lib/src/client/BrandClient.js +17 -0
- package/lib/src/client/ClientModule.js +14 -0
- package/lib/src/client/CourierClient.js +31 -0
- package/lib/src/client/InboxClient.js +99 -0
- package/lib/src/client/PreferenceClient.js +63 -0
- package/lib/src/client/TokenClient.js +27 -0
- package/lib/src/client/TrackingClient.js +17 -0
- package/lib/src/index.js +567 -0
- package/lib/src/models/Android_CourierSheet.js +1 -0
- package/lib/src/models/CourierAuthenticationListener.js +14 -0
- package/lib/src/models/CourierBrand.js +1 -0
- package/lib/src/models/CourierButton.js +1 -0
- package/lib/src/models/CourierDevice.js +1 -0
- package/lib/src/models/CourierFont.js +1 -0
- package/lib/src/models/CourierInboxListener.js +20 -0
- package/lib/src/models/CourierInboxMessages.js +1 -0
- package/lib/src/models/CourierInboxTheme.js +1 -0
- package/lib/src/models/CourierInfoViewStyle.js +1 -0
- package/lib/src/models/CourierPaging.js +1 -0
- package/lib/src/models/CourierPreferencesTheme.js +1 -0
- package/lib/src/models/CourierPushListener.js +14 -0
- package/lib/src/models/CourierPushProvider.js +8 -0
- package/lib/src/models/CourierTrackingEvent.js +8 -0
- package/lib/src/models/CourierUserPreferences.js +51 -0
- package/lib/src/models/InboxAction.js +1 -0
- package/lib/src/models/InboxMessage.js +1 -0
- package/lib/src/models/InboxMessageFeed.js +1 -0
- package/lib/src/models/InboxMessageSet.js +1 -0
- package/lib/src/models/iOS_CourierCell.js +1 -0
- package/lib/src/models/iOS_CourierSheet.js +1 -0
- package/lib/src/utils.js +27 -0
- package/lib/src/views/CourierInboxView.js +75 -0
- package/lib/src/views/CourierPreferencesView.js +33 -0
- package/lib/typescript/src/index.d.ts +16 -20
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierInboxListener.d.ts +4 -7
- package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -1
- package/lib/typescript/src/models/InboxAction.d.ts +8 -4
- package/lib/typescript/src/models/InboxAction.d.ts.map +1 -1
- package/lib/typescript/src/models/InboxMessage.d.ts +28 -14
- package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -1
- package/lib/typescript/src/models/InboxMessageEvent.d.ts +2 -0
- package/lib/typescript/src/models/InboxMessageEvent.d.ts.map +1 -0
- package/lib/typescript/src/models/InboxMessageFeed.d.ts +1 -1
- package/lib/typescript/src/models/InboxMessageFeed.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/index.tsx +61 -99
- package/src/models/CourierInboxListener.tsx +10 -13
- package/src/models/InboxAction.tsx +28 -4
- package/src/models/InboxMessage.tsx +102 -14
- package/src/models/InboxMessageEvent.tsx +1 -0
- package/src/models/InboxMessageFeed.tsx +1 -1
- package/src/views/CourierInboxView.tsx +4 -4
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcuserdata/mike.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/CourierReactNative.xcodeproj/xcuserdata/mike.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
|
@@ -15,7 +15,13 @@ import kotlinx.coroutines.Dispatchers
|
|
|
15
15
|
import kotlinx.coroutines.launch
|
|
16
16
|
import java.util.UUID
|
|
17
17
|
|
|
18
|
-
class CourierClientModule(
|
|
18
|
+
class CourierClientModule(
|
|
19
|
+
reactContext: ReactApplicationContext
|
|
20
|
+
) : ReactNativeModule(
|
|
21
|
+
tag = "Client Error",
|
|
22
|
+
name = "CourierClientModule",
|
|
23
|
+
reactContext = reactContext
|
|
24
|
+
) {
|
|
19
25
|
|
|
20
26
|
private var clients: MutableMap<String, CourierClient> = mutableMapOf()
|
|
21
27
|
|
|
@@ -31,7 +37,6 @@ class CourierClientModule(reactContext: ReactApplicationContext): ReactNativeMod
|
|
|
31
37
|
|
|
32
38
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
33
39
|
fun addClient(options: ReadableMap): String {
|
|
34
|
-
|
|
35
40
|
val userId = options.getString("userId")
|
|
36
41
|
val showLogs = if (options.hasKey("showLogs")) options.getBoolean("showLogs") else null
|
|
37
42
|
|
|
@@ -52,7 +57,6 @@ class CourierClientModule(reactContext: ReactApplicationContext): ReactNativeMod
|
|
|
52
57
|
clients[uuid] = client
|
|
53
58
|
|
|
54
59
|
return uuid
|
|
55
|
-
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
@@ -64,378 +68,369 @@ class CourierClientModule(reactContext: ReactApplicationContext): ReactNativeMod
|
|
|
64
68
|
// Tokens
|
|
65
69
|
|
|
66
70
|
@ReactMethod
|
|
67
|
-
fun putUserToken(clientId: String, token: String, provider: String, device: ReadableMap?, promise: Promise)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
fun putUserToken(clientId: String, token: String, provider: String, device: ReadableMap?, promise: Promise) {
|
|
72
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
73
|
+
val client = clients[clientId]
|
|
74
|
+
if (client == null) {
|
|
75
|
+
promise.rejectMissingClient()
|
|
76
|
+
return@launch
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (reactActivity == null) {
|
|
80
|
+
promise.rejectMissingContext()
|
|
81
|
+
return@launch
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
val courierDevice = device?.let {
|
|
85
|
+
CourierDevice(
|
|
86
|
+
appId = it.getString("appId"),
|
|
87
|
+
adId = it.getString("adId"),
|
|
88
|
+
deviceId = it.getString("deviceId"),
|
|
89
|
+
platform = it.getString("platform"),
|
|
90
|
+
manufacturer = it.getString("manufacturer"),
|
|
91
|
+
model = it.getString("model")
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
client.tokens.putUserToken(
|
|
97
|
+
token = token,
|
|
98
|
+
provider = provider,
|
|
99
|
+
device = courierDevice ?: CourierDevice.current(reactActivity!!)
|
|
100
|
+
)
|
|
101
|
+
promise.resolve(null)
|
|
102
|
+
} catch (e: Exception) {
|
|
103
|
+
promise.apiError(e)
|
|
104
|
+
}
|
|
78
105
|
}
|
|
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
106
|
}
|
|
103
107
|
|
|
104
108
|
@ReactMethod
|
|
105
|
-
fun deleteUserToken(clientId: String, token: String, promise: Promise)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
promise.apiError(e)
|
|
109
|
+
fun deleteUserToken(clientId: String, token: String, promise: Promise) {
|
|
110
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
111
|
+
val client = clients[clientId]
|
|
112
|
+
if (client == null) {
|
|
113
|
+
promise.rejectMissingClient()
|
|
114
|
+
return@launch
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
client.tokens.deleteUserToken(token = token)
|
|
119
|
+
promise.resolve(null)
|
|
120
|
+
} catch (e: Exception) {
|
|
121
|
+
promise.apiError(e)
|
|
122
|
+
}
|
|
120
123
|
}
|
|
121
|
-
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
// Brands
|
|
125
127
|
|
|
126
128
|
@ReactMethod
|
|
127
|
-
fun getBrand(clientId: String, brandId: String, promise: Promise)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
fun getBrand(clientId: String, brandId: String, promise: Promise) {
|
|
130
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
131
|
+
val client = clients[clientId]
|
|
132
|
+
if (client == null) {
|
|
133
|
+
promise.rejectMissingClient()
|
|
134
|
+
return@launch
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
val brand = client.brands.getBrand(brandId = brandId)
|
|
139
|
+
val json = brand.toJson()
|
|
140
|
+
promise.resolve(json)
|
|
141
|
+
} catch (e: Exception) {
|
|
142
|
+
promise.apiError(e)
|
|
143
|
+
}
|
|
133
144
|
}
|
|
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
145
|
}
|
|
146
146
|
|
|
147
147
|
// Inbox
|
|
148
148
|
|
|
149
149
|
@ReactMethod
|
|
150
|
-
fun getMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
fun getMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) {
|
|
151
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
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
|
+
}
|
|
156
168
|
}
|
|
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
169
|
}
|
|
170
170
|
|
|
171
171
|
@ReactMethod
|
|
172
|
-
fun getArchivedMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
172
|
+
fun getArchivedMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) {
|
|
173
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
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
|
+
}
|
|
189
190
|
}
|
|
190
|
-
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
@ReactMethod
|
|
194
|
-
fun getMessageById(clientId: String, messageId: String, promise: Promise)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
promise.apiError(e)
|
|
194
|
+
fun getMessageById(clientId: String, messageId: String, promise: Promise) {
|
|
195
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
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(messageId = messageId)
|
|
204
|
+
val json = res.toJson()
|
|
205
|
+
promise.resolve(json)
|
|
206
|
+
} catch (e: Exception) {
|
|
207
|
+
promise.apiError(e)
|
|
208
|
+
}
|
|
210
209
|
}
|
|
211
|
-
|
|
212
210
|
}
|
|
213
211
|
|
|
214
212
|
@ReactMethod
|
|
215
|
-
fun getUnreadMessageCount(clientId: String, promise: Promise)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
213
|
+
fun getUnreadMessageCount(clientId: String, promise: Promise) {
|
|
214
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
215
|
+
val client = clients[clientId]
|
|
216
|
+
if (client == null) {
|
|
217
|
+
promise.rejectMissingClient()
|
|
218
|
+
return@launch
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
val count = client.inbox.getUnreadMessageCount()
|
|
223
|
+
promise.resolve(count)
|
|
224
|
+
} catch (e: Exception) {
|
|
225
|
+
promise.apiError(e)
|
|
226
|
+
}
|
|
221
227
|
}
|
|
222
|
-
|
|
223
|
-
try {
|
|
224
|
-
val count = client.inbox.getUnreadMessageCount()
|
|
225
|
-
promise.resolve(count)
|
|
226
|
-
} catch (e: Exception) {
|
|
227
|
-
promise.apiError(e)
|
|
228
|
-
}
|
|
229
|
-
|
|
230
228
|
}
|
|
231
229
|
|
|
232
230
|
@ReactMethod
|
|
233
|
-
fun openMessage(clientId: String, messageId: String, promise: Promise)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
promise.apiError(e)
|
|
231
|
+
fun openMessage(clientId: String, messageId: String, promise: Promise) {
|
|
232
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
233
|
+
val client = clients[clientId]
|
|
234
|
+
if (client == null) {
|
|
235
|
+
promise.rejectMissingClient()
|
|
236
|
+
return@launch
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
client.inbox.open(messageId = messageId)
|
|
241
|
+
promise.resolve(null)
|
|
242
|
+
} catch (e: Exception) {
|
|
243
|
+
promise.apiError(e)
|
|
244
|
+
}
|
|
248
245
|
}
|
|
249
|
-
|
|
250
246
|
}
|
|
251
247
|
|
|
252
248
|
@ReactMethod
|
|
253
|
-
fun readMessage(clientId: String, messageId: String, promise: Promise)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
promise.apiError(e)
|
|
249
|
+
fun readMessage(clientId: String, messageId: String, promise: Promise) {
|
|
250
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
251
|
+
val client = clients[clientId]
|
|
252
|
+
if (client == null) {
|
|
253
|
+
promise.rejectMissingClient()
|
|
254
|
+
return@launch
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
client.inbox.read(messageId = messageId)
|
|
259
|
+
promise.resolve(null)
|
|
260
|
+
} catch (e: Exception) {
|
|
261
|
+
promise.apiError(e)
|
|
262
|
+
}
|
|
268
263
|
}
|
|
269
|
-
|
|
270
264
|
}
|
|
271
265
|
|
|
272
266
|
@ReactMethod
|
|
273
|
-
fun unreadMessage(clientId: String, messageId: String, promise: Promise)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
267
|
+
fun unreadMessage(clientId: String, messageId: String, promise: Promise) {
|
|
268
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
269
|
+
val client = clients[clientId]
|
|
270
|
+
if (client == null) {
|
|
271
|
+
promise.rejectMissingClient()
|
|
272
|
+
return@launch
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
client.inbox.unread(messageId = messageId)
|
|
277
|
+
promise.resolve(null)
|
|
278
|
+
} catch (e: Exception) {
|
|
279
|
+
promise.apiError(e)
|
|
280
|
+
}
|
|
279
281
|
}
|
|
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
282
|
}
|
|
291
283
|
|
|
292
284
|
@ReactMethod
|
|
293
|
-
fun clickMessage(clientId: String, messageId: String, trackingId: String, promise: Promise)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
285
|
+
fun clickMessage(clientId: String, messageId: String, trackingId: String, promise: Promise) {
|
|
286
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
287
|
+
val client = clients[clientId]
|
|
288
|
+
if (client == null) {
|
|
289
|
+
promise.rejectMissingClient()
|
|
290
|
+
return@launch
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
try {
|
|
294
|
+
client.inbox.click(
|
|
295
|
+
messageId = messageId,
|
|
296
|
+
trackingId = trackingId
|
|
297
|
+
)
|
|
298
|
+
promise.resolve(null)
|
|
299
|
+
} catch (e: Exception) {
|
|
300
|
+
promise.apiError(e)
|
|
301
|
+
}
|
|
299
302
|
}
|
|
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
303
|
}
|
|
312
304
|
|
|
313
305
|
@ReactMethod
|
|
314
|
-
fun archiveMessage(clientId: String, messageId: String, promise: Promise)
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
promise.apiError(e)
|
|
306
|
+
fun archiveMessage(clientId: String, messageId: String, promise: Promise) {
|
|
307
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
308
|
+
val client = clients[clientId]
|
|
309
|
+
if (client == null) {
|
|
310
|
+
promise.rejectMissingClient()
|
|
311
|
+
return@launch
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
try {
|
|
315
|
+
client.inbox.archive(messageId = messageId)
|
|
316
|
+
promise.resolve(null)
|
|
317
|
+
} catch (e: Exception) {
|
|
318
|
+
promise.apiError(e)
|
|
319
|
+
}
|
|
329
320
|
}
|
|
330
|
-
|
|
331
321
|
}
|
|
332
322
|
|
|
333
323
|
@ReactMethod
|
|
334
|
-
fun readAllMessages(clientId: String, promise: Promise)
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
324
|
+
fun readAllMessages(clientId: String, promise: Promise) {
|
|
325
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
326
|
+
val client = clients[clientId]
|
|
327
|
+
if (client == null) {
|
|
328
|
+
promise.rejectMissingClient()
|
|
329
|
+
return@launch
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
try {
|
|
333
|
+
client.inbox.readAll()
|
|
334
|
+
promise.resolve(null)
|
|
335
|
+
} catch (e: Exception) {
|
|
336
|
+
promise.apiError(e)
|
|
337
|
+
}
|
|
347
338
|
}
|
|
348
|
-
|
|
349
339
|
}
|
|
350
340
|
|
|
351
341
|
// Preferences
|
|
352
342
|
|
|
353
343
|
@ReactMethod
|
|
354
|
-
fun getUserPreferences(clientId: String, paginationCursor: String?, promise: Promise)
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
344
|
+
fun getUserPreferences(clientId: String, paginationCursor: String?, promise: Promise) {
|
|
345
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
346
|
+
val client = clients[clientId]
|
|
347
|
+
if (client == null) {
|
|
348
|
+
promise.rejectMissingClient()
|
|
349
|
+
return@launch
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
try {
|
|
353
|
+
val res = client.preferences.getUserPreferences(
|
|
354
|
+
paginationCursor = paginationCursor
|
|
355
|
+
)
|
|
356
|
+
val json = res.toJson()
|
|
357
|
+
promise.resolve(json)
|
|
358
|
+
} catch (e: Exception) {
|
|
359
|
+
promise.apiError(e)
|
|
360
|
+
}
|
|
360
361
|
}
|
|
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
362
|
}
|
|
373
363
|
|
|
374
364
|
@ReactMethod
|
|
375
|
-
fun getUserPreferenceTopic(clientId: String, topicId: String, promise: Promise)
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
promise.apiError(e)
|
|
365
|
+
fun getUserPreferenceTopic(clientId: String, topicId: String, promise: Promise) {
|
|
366
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
367
|
+
val client = clients[clientId]
|
|
368
|
+
if (client == null) {
|
|
369
|
+
promise.rejectMissingClient()
|
|
370
|
+
return@launch
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
try {
|
|
374
|
+
val res = client.preferences.getUserPreferenceTopic(topicId = topicId)
|
|
375
|
+
val json = res.toJson()
|
|
376
|
+
promise.resolve(json)
|
|
377
|
+
} catch (e: Exception) {
|
|
378
|
+
promise.apiError(e)
|
|
379
|
+
}
|
|
391
380
|
}
|
|
392
|
-
|
|
393
381
|
}
|
|
394
382
|
|
|
395
383
|
@ReactMethod
|
|
396
|
-
fun putUserPreferenceTopic(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
client
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
384
|
+
fun putUserPreferenceTopic(
|
|
385
|
+
clientId: String,
|
|
386
|
+
topicId: String,
|
|
387
|
+
status: String,
|
|
388
|
+
hasCustomRouting: Boolean,
|
|
389
|
+
customRouting: ReadableArray,
|
|
390
|
+
promise: Promise
|
|
391
|
+
) {
|
|
392
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
393
|
+
val client = clients[clientId]
|
|
394
|
+
if (client == null) {
|
|
395
|
+
promise.rejectMissingClient()
|
|
396
|
+
return@launch
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
try {
|
|
400
|
+
client.preferences.putUserPreferenceTopic(
|
|
401
|
+
topicId = topicId,
|
|
402
|
+
status = CourierPreferenceStatus.fromString(status),
|
|
403
|
+
hasCustomRouting = hasCustomRouting,
|
|
404
|
+
customRouting = customRouting.toArrayList()
|
|
405
|
+
.map { CourierPreferenceChannel.fromString(it as String) }
|
|
406
|
+
)
|
|
407
|
+
promise.resolve(null)
|
|
408
|
+
} catch (e: Exception) {
|
|
409
|
+
promise.apiError(e)
|
|
410
|
+
}
|
|
414
411
|
}
|
|
415
|
-
|
|
416
412
|
}
|
|
417
413
|
|
|
418
414
|
// Tracking
|
|
419
415
|
|
|
420
416
|
@ReactMethod
|
|
421
|
-
fun postTrackingUrl(clientId: String, url: String, event: String, promise: Promise)
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
417
|
+
fun postTrackingUrl(clientId: String, url: String, event: String, promise: Promise) {
|
|
418
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
419
|
+
val client = clients[clientId]
|
|
420
|
+
if (client == null) {
|
|
421
|
+
promise.rejectMissingClient()
|
|
422
|
+
return@launch
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
try {
|
|
426
|
+
client.tracking.postTrackingUrl(
|
|
427
|
+
url = url,
|
|
428
|
+
event = CourierTrackingEvent.valueOf(event.uppercase())
|
|
429
|
+
)
|
|
430
|
+
promise.resolve(null)
|
|
431
|
+
} catch (e: Exception) {
|
|
432
|
+
promise.apiError(e)
|
|
433
|
+
}
|
|
427
434
|
}
|
|
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
435
|
}
|
|
440
|
-
|
|
441
436
|
}
|