@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.
Files changed (115) hide show
  1. package/android/build.gradle +2 -2
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +298 -303
  4. package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +194 -165
  5. package/android/src/main/java/com/courierreactnative/Utils.kt +1 -1
  6. package/courier-react-native.podspec +1 -1
  7. package/ios/CourierReactNativeDelegate.m +12 -8
  8. package/ios/CourierReactNativeEventEmitter.swift +1 -1
  9. package/ios/CourierReactNativeModule.m +3 -5
  10. package/ios/CourierSharedModule.swift +88 -112
  11. package/lib/commonjs/index.js +75 -93
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/models/CourierInboxListener.js +1 -0
  14. package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
  15. package/lib/commonjs/models/InboxAction.js +22 -0
  16. package/lib/commonjs/models/InboxAction.js.map +1 -1
  17. package/lib/commonjs/models/InboxMessage.js +64 -0
  18. package/lib/commonjs/models/InboxMessage.js.map +1 -1
  19. package/lib/commonjs/models/InboxMessageEvent.js +2 -0
  20. package/lib/commonjs/models/InboxMessageEvent.js.map +1 -0
  21. package/lib/commonjs/views/CourierInboxView.js +6 -4
  22. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  23. package/lib/example/src/App.js +11 -0
  24. package/lib/example/src/Emitter.js +11 -0
  25. package/lib/example/src/Env.js +6 -0
  26. package/lib/example/src/Home.js +67 -0
  27. package/lib/example/src/Poke.js +75 -0
  28. package/lib/example/src/Tabs.js +36 -0
  29. package/lib/example/src/Utils.js +71 -0
  30. package/lib/example/src/pages/Auth.js +224 -0
  31. package/lib/example/src/pages/Inbox.js +38 -0
  32. package/lib/example/src/pages/Preferences.js +13 -0
  33. package/lib/example/src/pages/PreferencesStack.js +11 -0
  34. package/lib/example/src/pages/Push.js +93 -0
  35. package/lib/example/src/pages/Styles.js +26 -0
  36. package/lib/example/src/pages/Tests.js +1068 -0
  37. package/lib/example/src/pages/inbox/InboxCustom.js +141 -0
  38. package/lib/example/src/pages/inbox/InboxDefault.js +22 -0
  39. package/lib/example/src/pages/inbox/InboxStyled.js +220 -0
  40. package/lib/example/src/pages/preferences/PreferencesCustom.js +91 -0
  41. package/lib/example/src/pages/preferences/PreferencesDefault.js +17 -0
  42. package/lib/example/src/pages/preferences/PreferencesDetail.js +127 -0
  43. package/lib/example/src/pages/preferences/PreferencesStyled.js +110 -0
  44. package/lib/module/index.js +67 -90
  45. package/lib/module/index.js.map +1 -1
  46. package/lib/module/models/CourierInboxListener.js +1 -0
  47. package/lib/module/models/CourierInboxListener.js.map +1 -1
  48. package/lib/module/models/InboxAction.js +16 -1
  49. package/lib/module/models/InboxAction.js.map +1 -1
  50. package/lib/module/models/InboxMessage.js +61 -1
  51. package/lib/module/models/InboxMessage.js.map +1 -1
  52. package/lib/module/models/InboxMessageEvent.js +2 -0
  53. package/lib/module/models/InboxMessageEvent.js.map +1 -0
  54. package/lib/module/views/CourierInboxView.js +6 -4
  55. package/lib/module/views/CourierInboxView.js.map +1 -1
  56. package/lib/package.json +171 -0
  57. package/lib/src/Broadcaster.js +24 -0
  58. package/lib/src/Modules.js +26 -0
  59. package/lib/src/client/BrandClient.js +17 -0
  60. package/lib/src/client/ClientModule.js +14 -0
  61. package/lib/src/client/CourierClient.js +31 -0
  62. package/lib/src/client/InboxClient.js +99 -0
  63. package/lib/src/client/PreferenceClient.js +63 -0
  64. package/lib/src/client/TokenClient.js +27 -0
  65. package/lib/src/client/TrackingClient.js +17 -0
  66. package/lib/src/index.js +567 -0
  67. package/lib/src/models/Android_CourierSheet.js +1 -0
  68. package/lib/src/models/CourierAuthenticationListener.js +14 -0
  69. package/lib/src/models/CourierBrand.js +1 -0
  70. package/lib/src/models/CourierButton.js +1 -0
  71. package/lib/src/models/CourierDevice.js +1 -0
  72. package/lib/src/models/CourierFont.js +1 -0
  73. package/lib/src/models/CourierInboxListener.js +20 -0
  74. package/lib/src/models/CourierInboxMessages.js +1 -0
  75. package/lib/src/models/CourierInboxTheme.js +1 -0
  76. package/lib/src/models/CourierInfoViewStyle.js +1 -0
  77. package/lib/src/models/CourierPaging.js +1 -0
  78. package/lib/src/models/CourierPreferencesTheme.js +1 -0
  79. package/lib/src/models/CourierPushListener.js +14 -0
  80. package/lib/src/models/CourierPushProvider.js +8 -0
  81. package/lib/src/models/CourierTrackingEvent.js +8 -0
  82. package/lib/src/models/CourierUserPreferences.js +51 -0
  83. package/lib/src/models/InboxAction.js +1 -0
  84. package/lib/src/models/InboxMessage.js +1 -0
  85. package/lib/src/models/InboxMessageFeed.js +1 -0
  86. package/lib/src/models/InboxMessageSet.js +1 -0
  87. package/lib/src/models/iOS_CourierCell.js +1 -0
  88. package/lib/src/models/iOS_CourierSheet.js +1 -0
  89. package/lib/src/utils.js +27 -0
  90. package/lib/src/views/CourierInboxView.js +75 -0
  91. package/lib/src/views/CourierPreferencesView.js +33 -0
  92. package/lib/typescript/src/index.d.ts +16 -20
  93. package/lib/typescript/src/index.d.ts.map +1 -1
  94. package/lib/typescript/src/models/CourierInboxListener.d.ts +4 -7
  95. package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -1
  96. package/lib/typescript/src/models/InboxAction.d.ts +8 -4
  97. package/lib/typescript/src/models/InboxAction.d.ts.map +1 -1
  98. package/lib/typescript/src/models/InboxMessage.d.ts +28 -14
  99. package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -1
  100. package/lib/typescript/src/models/InboxMessageEvent.d.ts +2 -0
  101. package/lib/typescript/src/models/InboxMessageEvent.d.ts.map +1 -0
  102. package/lib/typescript/src/models/InboxMessageFeed.d.ts +1 -1
  103. package/lib/typescript/src/models/InboxMessageFeed.d.ts.map +1 -1
  104. package/package.json +3 -2
  105. package/src/index.tsx +61 -99
  106. package/src/models/CourierInboxListener.tsx +10 -13
  107. package/src/models/InboxAction.tsx +28 -4
  108. package/src/models/InboxMessage.tsx +102 -14
  109. package/src/models/InboxMessageEvent.tsx +1 -0
  110. package/src/models/InboxMessageFeed.tsx +1 -1
  111. package/src/views/CourierInboxView.tsx +4 -4
  112. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  113. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  114. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcuserdata/mike.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  115. 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(reactContext: ReactApplicationContext): ReactNativeModule(tag = "Client Error", name = "CourierClientModule", reactContext = reactContext) {
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) = 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
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) = 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)
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) = CoroutineScope(Dispatchers.Main).launch {
128
-
129
- val client = clients[clientId]
130
- if (client == null) {
131
- promise.rejectMissingClient()
132
- return@launch
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) = CoroutineScope(Dispatchers.Main).launch {
151
-
152
- val client = clients[clientId]
153
- if (client == null) {
154
- promise.rejectMissingClient()
155
- return@launch
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) = 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)
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) = 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)
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) = CoroutineScope(Dispatchers.Main).launch {
216
-
217
- val client = clients[clientId]
218
- if (client == null) {
219
- promise.rejectMissingClient()
220
- return@launch
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) = 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)
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) = 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)
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) = CoroutineScope(Dispatchers.Main).launch {
274
-
275
- val client = clients[clientId]
276
- if (client == null) {
277
- promise.rejectMissingClient()
278
- return@launch
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) = CoroutineScope(Dispatchers.Main).launch {
294
-
295
- val client = clients[clientId]
296
- if (client == null) {
297
- promise.rejectMissingClient()
298
- return@launch
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) = 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)
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) = 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)
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) = CoroutineScope(Dispatchers.Main).launch {
355
-
356
- val client = clients[clientId]
357
- if (client == null) {
358
- promise.rejectMissingClient()
359
- return@launch
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) = 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)
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(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)
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) = CoroutineScope(Dispatchers.Main).launch {
422
-
423
- val client = clients[clientId]
424
- if (client == null) {
425
- promise.rejectMissingClient()
426
- return@launch
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
  }