@trycourier/courier-react-native 2.3.2 → 2.4.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/android/src/main/java/com/courierreactnative/CourierEvents.kt +0 -10
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +34 -41
- package/ios/CourierReactNativeModule.m +4 -2
- package/ios/CourierReactNativeModule.swift +71 -69
- package/lib/commonjs/index.js +82 -80
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierAuthenticationListener.js +9 -5
- package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js +3 -6
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
- package/lib/commonjs/utils.js +45 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/index.js +84 -81
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierAuthenticationListener.js +9 -5
- package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js +3 -6
- package/lib/module/models/CourierInboxListener.js.map +1 -1
- package/lib/module/utils.js +37 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/index.d.ts +1 -6
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/CourierAuthenticationListener.d.ts +2 -1
- package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +1 -1
- package/lib/typescript/models/CourierInboxListener.d.ts +4 -4
- package/lib/typescript/models/CourierInboxListener.d.ts.map +1 -1
- package/lib/typescript/utils.d.ts +21 -0
- package/lib/typescript/utils.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/index.tsx +100 -99
- package/src/models/CourierAuthenticationListener.tsx +8 -4
- package/src/models/CourierInboxListener.tsx +5 -10
- package/src/utils.tsx +48 -0
|
@@ -10,19 +10,9 @@ internal class CourierEvents {
|
|
|
10
10
|
const val DEBUG_LOG = "courierDebugEvent"
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
object Auth {
|
|
14
|
-
const val USER_CHANGED = "courierAuthUserChanged"
|
|
15
|
-
}
|
|
16
|
-
|
|
17
13
|
object Push {
|
|
18
14
|
const val CLICKED_EVENT = "pushNotificationClicked"
|
|
19
15
|
const val DELIVERED_EVENT = "pushNotificationDelivered"
|
|
20
16
|
}
|
|
21
17
|
|
|
22
|
-
object Inbox {
|
|
23
|
-
const val INITIAL_LOADING = "inboxInitialLoad"
|
|
24
|
-
const val ERROR = "inboxError"
|
|
25
|
-
const val MESSAGES_CHANGED = "inboxMessagesChanged"
|
|
26
|
-
}
|
|
27
|
-
|
|
28
18
|
}
|
|
@@ -18,13 +18,9 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
18
18
|
override fun getName() = "CourierReactNativeModule"
|
|
19
19
|
private val reactActivity: ReactActivity? get() = currentActivity as? ReactActivity
|
|
20
20
|
|
|
21
|
-
//
|
|
22
|
-
private var
|
|
23
|
-
private var
|
|
24
|
-
|
|
25
|
-
// Inbox Listeners
|
|
26
|
-
private var inboxListener: CourierInboxListener? = null
|
|
27
|
-
private var inboxListeners: MutableList<String> = mutableListOf()
|
|
21
|
+
// Listeners
|
|
22
|
+
private var authListeners = mutableMapOf<String, CourierAuthenticationListener>()
|
|
23
|
+
private var inboxListeners = mutableMapOf<String, CourierInboxListener>()
|
|
28
24
|
|
|
29
25
|
init {
|
|
30
26
|
|
|
@@ -135,19 +131,21 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
135
131
|
}
|
|
136
132
|
|
|
137
133
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
138
|
-
fun addAuthenticationListener(): String {
|
|
134
|
+
fun addAuthenticationListener(authId: String): String {
|
|
139
135
|
|
|
140
|
-
|
|
136
|
+
// Create the listener
|
|
137
|
+
val listener = Courier.shared.addAuthenticationListener { userId ->
|
|
141
138
|
|
|
142
|
-
authListener = Courier.shared.addAuthenticationListener { userId ->
|
|
143
139
|
reactApplicationContext.sendEvent(
|
|
144
|
-
eventName =
|
|
140
|
+
eventName = authId,
|
|
145
141
|
value = userId
|
|
146
142
|
)
|
|
143
|
+
|
|
147
144
|
}
|
|
148
145
|
|
|
146
|
+
// Add the listener to the map
|
|
149
147
|
val id = UUID.randomUUID().toString()
|
|
150
|
-
authListeners
|
|
148
|
+
authListeners[id] = listener
|
|
151
149
|
|
|
152
150
|
return id
|
|
153
151
|
|
|
@@ -156,17 +154,14 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
156
154
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
157
155
|
fun removeAuthenticationListener(listenerId: String): String {
|
|
158
156
|
|
|
159
|
-
//
|
|
160
|
-
val
|
|
161
|
-
if (index != -1) {
|
|
162
|
-
authListeners.removeAt(index)
|
|
163
|
-
}
|
|
157
|
+
// Get the listener
|
|
158
|
+
val listener = authListeners[listenerId]
|
|
164
159
|
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
160
|
+
// Remove the listener
|
|
161
|
+
listener?.remove()
|
|
162
|
+
|
|
163
|
+
// Remove the listener
|
|
164
|
+
authListeners.remove(listenerId)
|
|
170
165
|
|
|
171
166
|
return listenerId
|
|
172
167
|
|
|
@@ -223,23 +218,24 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
223
218
|
}
|
|
224
219
|
|
|
225
220
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
226
|
-
fun addInboxListener(): String {
|
|
227
|
-
|
|
228
|
-
// Remove the old listener
|
|
229
|
-
inboxListener?.remove()
|
|
221
|
+
fun addInboxListener(loadingId: String, errorId: String, messagesId: String): String {
|
|
230
222
|
|
|
231
|
-
|
|
223
|
+
val listener = Courier.shared.addInboxListener(
|
|
232
224
|
onInitialLoad = {
|
|
225
|
+
|
|
233
226
|
reactApplicationContext.sendEvent(
|
|
234
|
-
eventName =
|
|
227
|
+
eventName = loadingId,
|
|
235
228
|
value = null
|
|
236
229
|
)
|
|
230
|
+
|
|
237
231
|
},
|
|
238
232
|
onError = { e ->
|
|
233
|
+
|
|
239
234
|
reactApplicationContext.sendEvent(
|
|
240
|
-
eventName =
|
|
235
|
+
eventName = errorId,
|
|
241
236
|
value = e.message ?: "Courier Inbox Error"
|
|
242
237
|
)
|
|
238
|
+
|
|
243
239
|
},
|
|
244
240
|
onMessagesChanged = { messages: List<InboxMessage>, unreadMessageCount: Int, totalMessageCount: Int, canPaginate: Boolean ->
|
|
245
241
|
|
|
@@ -250,7 +246,7 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
250
246
|
json.putBoolean("canPaginate", canPaginate)
|
|
251
247
|
|
|
252
248
|
reactApplicationContext.sendEvent(
|
|
253
|
-
eventName =
|
|
249
|
+
eventName = messagesId,
|
|
254
250
|
value = json
|
|
255
251
|
)
|
|
256
252
|
|
|
@@ -259,7 +255,7 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
259
255
|
|
|
260
256
|
// Add listener
|
|
261
257
|
val id = UUID.randomUUID().toString()
|
|
262
|
-
inboxListeners
|
|
258
|
+
inboxListeners[id] = listener
|
|
263
259
|
|
|
264
260
|
return id
|
|
265
261
|
|
|
@@ -268,17 +264,14 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
268
264
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
269
265
|
fun removeInboxListener(listenerId: String): String {
|
|
270
266
|
|
|
271
|
-
//
|
|
272
|
-
val
|
|
273
|
-
if (index != -1) {
|
|
274
|
-
inboxListeners.removeAt(index)
|
|
275
|
-
}
|
|
267
|
+
// Get the listener
|
|
268
|
+
val listener = inboxListeners[listenerId]
|
|
276
269
|
|
|
277
|
-
//
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
270
|
+
// Remove the listener
|
|
271
|
+
listener?.remove()
|
|
272
|
+
|
|
273
|
+
// Remove the listener
|
|
274
|
+
inboxListeners.remove(listenerId)
|
|
282
275
|
|
|
283
276
|
return listenerId
|
|
284
277
|
|
|
@@ -28,7 +28,7 @@ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
|
28
28
|
)
|
|
29
29
|
|
|
30
30
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
31
|
-
addAuthenticationListener
|
|
31
|
+
addAuthenticationListener: (NSString*)authId
|
|
32
32
|
)
|
|
33
33
|
|
|
34
34
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
@@ -76,7 +76,9 @@ RCT_EXTERN_METHOD(
|
|
|
76
76
|
)
|
|
77
77
|
|
|
78
78
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
79
|
-
addInboxListener
|
|
79
|
+
addInboxListener: (NSString*)loadingId
|
|
80
|
+
withErrorId: (NSString*)errorId
|
|
81
|
+
withMessagesId: (NSString*)messagesId
|
|
80
82
|
)
|
|
81
83
|
|
|
82
84
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
@@ -9,28 +9,14 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
9
9
|
internal static let DEBUG_LOG = "courierDebugEvent"
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
class AuthEvents {
|
|
13
|
-
internal static let USER_CHANGED = "courierAuthUserChanged"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
12
|
class PushEvents {
|
|
17
13
|
internal static let CLICKED_EVENT = "pushNotificationClicked"
|
|
18
14
|
internal static let DELIVERED_EVENT = "pushNotificationDelivered"
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
internal static let MESSAGES_CHANGED = "inboxMessagesChanged"
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Auth Listeners
|
|
28
|
-
private var authListener: CourierAuthenticationListener? = nil
|
|
29
|
-
private var authListeners: [String] = []
|
|
30
|
-
|
|
31
|
-
// Inbox Listeners
|
|
32
|
-
private var inboxListener: CourierInboxListener? = nil
|
|
33
|
-
private var inboxListeners: [String] = []
|
|
17
|
+
// Listeners
|
|
18
|
+
private var authListeners: [String: CourierAuthenticationListenerWrapper] = [:]
|
|
19
|
+
private var inboxListeners: [String: CourierInboxListenerWrapper] = [:]
|
|
34
20
|
|
|
35
21
|
private var hasDebuggingListeners = false
|
|
36
22
|
|
|
@@ -105,8 +91,8 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
105
91
|
}
|
|
106
92
|
|
|
107
93
|
do {
|
|
108
|
-
|
|
109
|
-
|
|
94
|
+
broadcastEvent(
|
|
95
|
+
name: name,
|
|
110
96
|
body: try message.toString()
|
|
111
97
|
)
|
|
112
98
|
} catch {
|
|
@@ -114,6 +100,19 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
114
100
|
}
|
|
115
101
|
|
|
116
102
|
}
|
|
103
|
+
|
|
104
|
+
private func broadcastEvent(name: String, body: Any?) {
|
|
105
|
+
|
|
106
|
+
if (!supportedEvents().contains(name)) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
sendEvent(
|
|
111
|
+
withName: name,
|
|
112
|
+
body: body
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
}
|
|
117
116
|
|
|
118
117
|
@objc private func pushNotificationClicked(notification: Notification) {
|
|
119
118
|
|
|
@@ -196,24 +195,22 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
196
195
|
return Courier.shared.userId
|
|
197
196
|
}
|
|
198
197
|
|
|
199
|
-
@objc
|
|
198
|
+
@objc(addAuthenticationListener:)
|
|
199
|
+
func addAuthenticationListener(authId: String) -> String {
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// Set the new listener
|
|
205
|
-
authListener = Courier.shared.addAuthenticationListener { [weak self] userId in
|
|
206
|
-
|
|
207
|
-
self?.sendEvent(
|
|
208
|
-
withName: CourierReactNativeModule.AuthEvents.USER_CHANGED,
|
|
201
|
+
let listener = Courier.shared.addAuthenticationListener { [weak self] userId in
|
|
202
|
+
self?.broadcastEvent(
|
|
203
|
+
name: authId,
|
|
209
204
|
body: userId
|
|
210
205
|
)
|
|
211
|
-
|
|
212
206
|
}
|
|
213
207
|
|
|
214
|
-
// Add the listener to the arrau
|
|
215
208
|
let id = UUID().uuidString
|
|
216
|
-
|
|
209
|
+
|
|
210
|
+
authListeners[id] = CourierAuthenticationListenerWrapper(
|
|
211
|
+
authId: authId,
|
|
212
|
+
listener: listener
|
|
213
|
+
)
|
|
217
214
|
|
|
218
215
|
return id
|
|
219
216
|
|
|
@@ -224,16 +221,13 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
224
221
|
|
|
225
222
|
let id = listenerId as String
|
|
226
223
|
|
|
227
|
-
|
|
228
|
-
if let index = authListeners.firstIndex(of: id) {
|
|
229
|
-
authListeners.remove(at: index)
|
|
230
|
-
}
|
|
224
|
+
let wrapper = authListeners[id]
|
|
231
225
|
|
|
232
|
-
//
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
226
|
+
// Disable the listener
|
|
227
|
+
wrapper?.listener.remove()
|
|
228
|
+
|
|
229
|
+
// Remove the id from the map
|
|
230
|
+
authListeners.removeValue(forKey: id)
|
|
237
231
|
|
|
238
232
|
return id
|
|
239
233
|
|
|
@@ -318,25 +312,23 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
318
312
|
|
|
319
313
|
}
|
|
320
314
|
|
|
321
|
-
@objc
|
|
322
|
-
|
|
323
|
-
// Remove the old listener
|
|
324
|
-
inboxListener?.remove()
|
|
315
|
+
@objc(addInboxListener: withErrorId: withMessagesId:)
|
|
316
|
+
func addInboxListener(loadingId: String, errorId: String, messagesId: String) -> String {
|
|
325
317
|
|
|
326
318
|
// Create the new listener
|
|
327
|
-
|
|
319
|
+
let listener = Courier.shared.addInboxListener(
|
|
328
320
|
onInitialLoad: { [weak self] in
|
|
329
321
|
|
|
330
|
-
self?.
|
|
331
|
-
|
|
322
|
+
self?.broadcastEvent(
|
|
323
|
+
name: loadingId,
|
|
332
324
|
body: nil
|
|
333
325
|
)
|
|
334
326
|
|
|
335
327
|
},
|
|
336
328
|
onError: { [weak self] error in
|
|
337
329
|
|
|
338
|
-
self?.
|
|
339
|
-
|
|
330
|
+
self?.broadcastEvent(
|
|
331
|
+
name: errorId,
|
|
340
332
|
body: String(describing: error)
|
|
341
333
|
)
|
|
342
334
|
|
|
@@ -350,17 +342,23 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
350
342
|
"canPaginate": canPaginate
|
|
351
343
|
]
|
|
352
344
|
|
|
353
|
-
self?.
|
|
354
|
-
|
|
345
|
+
self?.broadcastEvent(
|
|
346
|
+
name: messagesId,
|
|
355
347
|
body: json
|
|
356
348
|
)
|
|
357
349
|
|
|
358
350
|
}
|
|
359
351
|
)
|
|
360
352
|
|
|
361
|
-
|
|
353
|
+
let wrapper = CourierInboxListenerWrapper(
|
|
354
|
+
loadingId: loadingId,
|
|
355
|
+
errorId: errorId,
|
|
356
|
+
messagesId: messagesId,
|
|
357
|
+
listener: listener
|
|
358
|
+
)
|
|
359
|
+
|
|
362
360
|
let id = UUID().uuidString
|
|
363
|
-
inboxListeners
|
|
361
|
+
inboxListeners[id] = wrapper
|
|
364
362
|
|
|
365
363
|
return id
|
|
366
364
|
|
|
@@ -371,16 +369,13 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
371
369
|
|
|
372
370
|
let id = listenerId as String
|
|
373
371
|
|
|
374
|
-
|
|
375
|
-
if let index = inboxListeners.firstIndex(of: id) {
|
|
376
|
-
inboxListeners.remove(at: index)
|
|
377
|
-
}
|
|
372
|
+
let wrapper = inboxListeners[id]
|
|
378
373
|
|
|
379
|
-
//
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
374
|
+
// Disable the listener
|
|
375
|
+
wrapper?.listener.remove()
|
|
376
|
+
|
|
377
|
+
// Remove the id from the map
|
|
378
|
+
inboxListeners.removeValue(forKey: id)
|
|
384
379
|
|
|
385
380
|
return id
|
|
386
381
|
|
|
@@ -450,7 +445,6 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
450
445
|
@objc(putUserPreferencesTopic: withStatus: withHasCustomRouting: withCustomRouting: withResolver: withRejecter:)
|
|
451
446
|
func putUserPreferencesTopic(topicId: NSString, status: NSString, hasCustomRouting: Bool, customRouting: [NSString], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
452
447
|
|
|
453
|
-
|
|
454
448
|
Courier.shared.putUserPreferencesTopic(
|
|
455
449
|
topicId: topicId as String,
|
|
456
450
|
status: CourierUserPreferencesStatus(rawValue: status as String) ?? .unknown,
|
|
@@ -467,15 +461,23 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
467
461
|
}
|
|
468
462
|
|
|
469
463
|
override func supportedEvents() -> [String]! {
|
|
470
|
-
|
|
464
|
+
|
|
465
|
+
// Built in events
|
|
466
|
+
var events = [
|
|
471
467
|
CourierReactNativeModule.LogEvents.DEBUG_LOG,
|
|
472
|
-
CourierReactNativeModule.AuthEvents.USER_CHANGED,
|
|
473
468
|
CourierReactNativeModule.PushEvents.CLICKED_EVENT,
|
|
474
|
-
CourierReactNativeModule.PushEvents.DELIVERED_EVENT
|
|
475
|
-
CourierReactNativeModule.InboxEvents.INITIAL_LOADING,
|
|
476
|
-
CourierReactNativeModule.InboxEvents.ERROR,
|
|
477
|
-
CourierReactNativeModule.InboxEvents.MESSAGES_CHANGED
|
|
469
|
+
CourierReactNativeModule.PushEvents.DELIVERED_EVENT
|
|
478
470
|
]
|
|
471
|
+
|
|
472
|
+
// Add the custom events
|
|
473
|
+
let inboxIds = inboxListeners.flatMap { [$0.value.loadingId, $0.value.errorId, $0.value.messagesId] }
|
|
474
|
+
events.append(contentsOf: inboxIds)
|
|
475
|
+
|
|
476
|
+
let authIds = authListeners.flatMap { [$0.value.authId] }
|
|
477
|
+
events.append(contentsOf: authIds)
|
|
478
|
+
|
|
479
|
+
return events
|
|
480
|
+
|
|
479
481
|
}
|
|
480
482
|
|
|
481
483
|
@objc override static func requiresMainQueueSetup() -> Bool {
|
package/lib/commonjs/index.js
CHANGED
|
@@ -92,6 +92,7 @@ var _reactNative = require("react-native");
|
|
|
92
92
|
var _CourierInboxListener = require("./models/CourierInboxListener");
|
|
93
93
|
var _CourierPushListener = require("./models/CourierPushListener");
|
|
94
94
|
var _CourierAuthenticationListener = require("./models/CourierAuthenticationListener");
|
|
95
|
+
var _utils = require("./utils");
|
|
95
96
|
var _CourierInboxView = require("./views/CourierInboxView");
|
|
96
97
|
var _CourierUserPreferencesChannel = require("./models/CourierUserPreferencesChannel");
|
|
97
98
|
var _CourierUserPreferencesStatus = require("./models/CourierUserPreferencesStatus");
|
|
@@ -112,18 +113,14 @@ const CourierReactNativeModules = _reactNative.NativeModules.CourierReactNativeM
|
|
|
112
113
|
});
|
|
113
114
|
const CourierEventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.CourierReactNativeModule);
|
|
114
115
|
class Courier {
|
|
115
|
-
PUSH_NOTIFICATION_CLICKED = 'pushNotificationClicked';
|
|
116
|
-
PUSH_NOTIFICATION_DELIVERED = 'pushNotificationDelivered';
|
|
117
116
|
_isDebugging = false;
|
|
117
|
+
authListeners = new Map();
|
|
118
118
|
inboxListeners = new Map();
|
|
119
119
|
constructor() {
|
|
120
120
|
// Sets the initial SDK values
|
|
121
121
|
// Defaults to React Native level debugging
|
|
122
122
|
// and will show all foreground notification styles in iOS
|
|
123
123
|
this.setDefaults();
|
|
124
|
-
|
|
125
|
-
// Register for inbox listener changes
|
|
126
|
-
this.registerInboxListenerEvents();
|
|
127
124
|
}
|
|
128
125
|
|
|
129
126
|
// Returns the public shared instance
|
|
@@ -152,7 +149,7 @@ class Courier {
|
|
|
152
149
|
// Set a new listener
|
|
153
150
|
// listener needs to be registered first to catch the event
|
|
154
151
|
if (isDebugging) {
|
|
155
|
-
this.debugListener = CourierEventEmitter.addListener(
|
|
152
|
+
this.debugListener = CourierEventEmitter.addListener(_utils.Events.Log.DEBUG_LOG, event => {
|
|
156
153
|
console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
|
|
157
154
|
});
|
|
158
155
|
}
|
|
@@ -168,30 +165,6 @@ class Courier {
|
|
|
168
165
|
return this._isDebugging;
|
|
169
166
|
}
|
|
170
167
|
|
|
171
|
-
/**
|
|
172
|
-
* Register inbox listener events
|
|
173
|
-
*/
|
|
174
|
-
registerInboxListenerEvents() {
|
|
175
|
-
CourierEventEmitter.addListener('inboxInitialLoad', () => {
|
|
176
|
-
this.inboxListeners.forEach((value, _) => {
|
|
177
|
-
var _value$onInitialLoad;
|
|
178
|
-
(_value$onInitialLoad = value.onInitialLoad) === null || _value$onInitialLoad === void 0 ? void 0 : _value$onInitialLoad.call(value);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
CourierEventEmitter.addListener('inboxError', event => {
|
|
182
|
-
this.inboxListeners.forEach((value, _) => {
|
|
183
|
-
var _value$onError;
|
|
184
|
-
(_value$onError = value.onError) === null || _value$onError === void 0 ? void 0 : _value$onError.call(value, event);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
CourierEventEmitter.addListener('inboxMessagesChanged', event => {
|
|
188
|
-
this.inboxListeners.forEach((value, _) => {
|
|
189
|
-
var _value$onMessagesChan;
|
|
190
|
-
(_value$onMessagesChan = value.onMessagesChanged) === null || _value$onMessagesChan === void 0 ? void 0 : _value$onMessagesChan.call(value, event.messages, event.unreadMessageCount, event.totalMessageCount, event.canPaginate);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
168
|
/**
|
|
196
169
|
* Sets the notification presentation options for iOS
|
|
197
170
|
*/
|
|
@@ -246,45 +219,23 @@ class Courier {
|
|
|
246
219
|
*/
|
|
247
220
|
addPushNotificationListener(props) {
|
|
248
221
|
const pushListener = new _CourierPushListener.CourierPushListener();
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
if (props.onPushNotificationDelivered) {
|
|
260
|
-
pushListener.onNotificationDeliveredListener = _reactNative.DeviceEventEmitter.addListener(this.PUSH_NOTIFICATION_DELIVERED, event => {
|
|
261
|
-
try {
|
|
262
|
-
props.onPushNotificationDelivered(JSON.parse(event));
|
|
263
|
-
} catch (error) {
|
|
264
|
-
console.log(error);
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
}
|
|
222
|
+
if (props.onPushNotificationClicked) {
|
|
223
|
+
pushListener.onNotificationClickedListener = _utils.Utils.addEventListener(_utils.Events.Push.CLICKED, CourierEventEmitter, event => {
|
|
224
|
+
try {
|
|
225
|
+
props.onPushNotificationClicked(JSON.parse(event));
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.log(error);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
268
230
|
}
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
if (props.onPushNotificationDelivered) {
|
|
280
|
-
pushListener.onNotificationDeliveredListener = CourierEventEmitter.addListener(this.PUSH_NOTIFICATION_DELIVERED, event => {
|
|
281
|
-
try {
|
|
282
|
-
props.onPushNotificationDelivered(JSON.parse(event));
|
|
283
|
-
} catch (error) {
|
|
284
|
-
console.log(error);
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}
|
|
231
|
+
if (props.onPushNotificationDelivered) {
|
|
232
|
+
pushListener.onNotificationDeliveredListener = _utils.Utils.addEventListener(_utils.Events.Push.DELIVERED, CourierEventEmitter, event => {
|
|
233
|
+
try {
|
|
234
|
+
props.onPushNotificationDelivered(JSON.parse(event));
|
|
235
|
+
} catch (error) {
|
|
236
|
+
console.log(error);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
288
239
|
}
|
|
289
240
|
|
|
290
241
|
// When listener is registered
|
|
@@ -321,19 +272,41 @@ class Courier {
|
|
|
321
272
|
* Listens to authentication changes for the current user
|
|
322
273
|
*/
|
|
323
274
|
addAuthenticationListener(props) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
275
|
+
// Event listener id
|
|
276
|
+
const authId = _utils.Utils.generateUUID();
|
|
277
|
+
|
|
278
|
+
// Get the id
|
|
279
|
+
const id = CourierReactNativeModules.addAuthenticationListener(authId);
|
|
280
|
+
|
|
281
|
+
// Create the listener
|
|
282
|
+
const listener = new _CourierAuthenticationListener.CourierAuthenticationListener(id);
|
|
283
|
+
|
|
284
|
+
// Add the event listener
|
|
285
|
+
listener.onUserChanged = _utils.Utils.addEventListener(authId, CourierEventEmitter, event => props.onUserChanged(event));
|
|
286
|
+
|
|
287
|
+
// Add listener to manager
|
|
288
|
+
this.authListeners.set(id, listener);
|
|
289
|
+
return listener;
|
|
330
290
|
}
|
|
331
291
|
|
|
332
292
|
/**
|
|
333
293
|
* Removes an authentication listener
|
|
334
294
|
*/
|
|
335
295
|
removeAuthenticationListener(props) {
|
|
336
|
-
|
|
296
|
+
// Remove the native listener
|
|
297
|
+
CourierReactNativeModules.removeAuthenticationListener(props.listenerId);
|
|
298
|
+
|
|
299
|
+
// Remove the listener
|
|
300
|
+
if (this.authListeners.has(props.listenerId)) {
|
|
301
|
+
var _listener$onUserChang;
|
|
302
|
+
// Get the listener
|
|
303
|
+
const listener = this.authListeners.get(props.listenerId);
|
|
304
|
+
listener === null || listener === void 0 || (_listener$onUserChang = listener.onUserChanged) === null || _listener$onUserChang === void 0 ? void 0 : _listener$onUserChang.remove();
|
|
305
|
+
|
|
306
|
+
// Remove the listener
|
|
307
|
+
this.authListeners.delete(props.listenerId);
|
|
308
|
+
}
|
|
309
|
+
return props.listenerId;
|
|
337
310
|
}
|
|
338
311
|
|
|
339
312
|
/**
|
|
@@ -368,14 +341,35 @@ class Courier {
|
|
|
368
341
|
* Listens to changes for the inbox itself
|
|
369
342
|
*/
|
|
370
343
|
addInboxListener(props) {
|
|
344
|
+
const listenerIds = {
|
|
345
|
+
loading: _utils.Utils.generateUUID(),
|
|
346
|
+
error: _utils.Utils.generateUUID(),
|
|
347
|
+
messages: _utils.Utils.generateUUID()
|
|
348
|
+
};
|
|
349
|
+
|
|
371
350
|
// Set the listener id
|
|
372
|
-
const id = CourierReactNativeModules.addInboxListener();
|
|
351
|
+
const id = CourierReactNativeModules.addInboxListener(listenerIds.loading, listenerIds.error, listenerIds.messages);
|
|
373
352
|
|
|
374
353
|
// Create the initial listeners
|
|
375
354
|
const listener = new _CourierInboxListener.CourierInboxListener(id);
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
355
|
+
if (props.onInitialLoad) {
|
|
356
|
+
listener.onInitialLoad = _utils.Utils.addEventListener(listenerIds.loading, CourierEventEmitter, _ => {
|
|
357
|
+
var _props$onInitialLoad;
|
|
358
|
+
(_props$onInitialLoad = props.onInitialLoad) === null || _props$onInitialLoad === void 0 ? void 0 : _props$onInitialLoad.call(props);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
if (props.onError) {
|
|
362
|
+
listener.onError = _utils.Utils.addEventListener(listenerIds.error, CourierEventEmitter, event => {
|
|
363
|
+
var _props$onError;
|
|
364
|
+
(_props$onError = props.onError) === null || _props$onError === void 0 ? void 0 : _props$onError.call(props, event);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
if (props.onMessagesChanged) {
|
|
368
|
+
listener.onMessagesChanged = _utils.Utils.addEventListener(listenerIds.messages, CourierEventEmitter, event => {
|
|
369
|
+
var _props$onMessagesChan;
|
|
370
|
+
(_props$onMessagesChan = props.onMessagesChanged) === null || _props$onMessagesChan === void 0 ? void 0 : _props$onMessagesChan.call(props, event.messages, event.unreadMessageCount, event.totalMessageCount, event.canPaginate);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
379
373
|
|
|
380
374
|
// Add listener to manager
|
|
381
375
|
this.inboxListeners.set(id, listener);
|
|
@@ -389,8 +383,16 @@ class Courier {
|
|
|
389
383
|
// Call native code
|
|
390
384
|
CourierReactNativeModules.removeInboxListener(props.listenerId);
|
|
391
385
|
|
|
392
|
-
// Remove the
|
|
386
|
+
// Remove the listener
|
|
393
387
|
if (this.inboxListeners.has(props.listenerId)) {
|
|
388
|
+
var _listener$onInitialLo, _listener$onError, _listener$onMessagesC;
|
|
389
|
+
// Remove emitters
|
|
390
|
+
const listener = this.inboxListeners.get(props.listenerId);
|
|
391
|
+
listener === null || listener === void 0 || (_listener$onInitialLo = listener.onInitialLoad) === null || _listener$onInitialLo === void 0 ? void 0 : _listener$onInitialLo.remove();
|
|
392
|
+
listener === null || listener === void 0 || (_listener$onError = listener.onError) === null || _listener$onError === void 0 ? void 0 : _listener$onError.remove();
|
|
393
|
+
listener === null || listener === void 0 || (_listener$onMessagesC = listener.onMessagesChanged) === null || _listener$onMessagesC === void 0 ? void 0 : _listener$onMessagesC.remove();
|
|
394
|
+
|
|
395
|
+
// Remove the listener
|
|
394
396
|
this.inboxListeners.delete(props.listenerId);
|
|
395
397
|
}
|
|
396
398
|
return props.listenerId;
|