@trycourier/courier-react-native 5.4.3 → 5.5.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.
Files changed (113) hide show
  1. package/android/build.gradle +2 -2
  2. package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +41 -42
  3. package/android/src/main/java/com/courierreactnative/Utils.kt +1 -1
  4. package/courier-react-native.podspec +1 -1
  5. package/ios/CourierReactNativeDelegate.m +12 -8
  6. package/ios/CourierReactNativeEventEmitter.swift +1 -1
  7. package/ios/CourierReactNativeModule.m +3 -5
  8. package/ios/CourierSharedModule.swift +88 -112
  9. package/lib/commonjs/index.js +75 -93
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/models/CourierInboxListener.js +1 -0
  12. package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
  13. package/lib/commonjs/models/InboxAction.js +22 -0
  14. package/lib/commonjs/models/InboxAction.js.map +1 -1
  15. package/lib/commonjs/models/InboxMessage.js +64 -0
  16. package/lib/commonjs/models/InboxMessage.js.map +1 -1
  17. package/lib/commonjs/models/InboxMessageEvent.js +2 -0
  18. package/lib/commonjs/models/InboxMessageEvent.js.map +1 -0
  19. package/lib/commonjs/views/CourierInboxView.js +6 -4
  20. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  21. package/lib/example/src/App.js +11 -0
  22. package/lib/example/src/Emitter.js +11 -0
  23. package/lib/example/src/Env.js +6 -0
  24. package/lib/example/src/Home.js +67 -0
  25. package/lib/example/src/Poke.js +75 -0
  26. package/lib/example/src/Tabs.js +36 -0
  27. package/lib/example/src/Utils.js +71 -0
  28. package/lib/example/src/pages/Auth.js +224 -0
  29. package/lib/example/src/pages/Inbox.js +38 -0
  30. package/lib/example/src/pages/Preferences.js +13 -0
  31. package/lib/example/src/pages/PreferencesStack.js +11 -0
  32. package/lib/example/src/pages/Push.js +93 -0
  33. package/lib/example/src/pages/Styles.js +26 -0
  34. package/lib/example/src/pages/Tests.js +1068 -0
  35. package/lib/example/src/pages/inbox/InboxCustom.js +141 -0
  36. package/lib/example/src/pages/inbox/InboxDefault.js +22 -0
  37. package/lib/example/src/pages/inbox/InboxStyled.js +220 -0
  38. package/lib/example/src/pages/preferences/PreferencesCustom.js +91 -0
  39. package/lib/example/src/pages/preferences/PreferencesDefault.js +17 -0
  40. package/lib/example/src/pages/preferences/PreferencesDetail.js +127 -0
  41. package/lib/example/src/pages/preferences/PreferencesStyled.js +110 -0
  42. package/lib/module/index.js +67 -90
  43. package/lib/module/index.js.map +1 -1
  44. package/lib/module/models/CourierInboxListener.js +1 -0
  45. package/lib/module/models/CourierInboxListener.js.map +1 -1
  46. package/lib/module/models/InboxAction.js +16 -1
  47. package/lib/module/models/InboxAction.js.map +1 -1
  48. package/lib/module/models/InboxMessage.js +61 -1
  49. package/lib/module/models/InboxMessage.js.map +1 -1
  50. package/lib/module/models/InboxMessageEvent.js +2 -0
  51. package/lib/module/models/InboxMessageEvent.js.map +1 -0
  52. package/lib/module/views/CourierInboxView.js +6 -4
  53. package/lib/module/views/CourierInboxView.js.map +1 -1
  54. package/lib/package.json +171 -0
  55. package/lib/src/Broadcaster.js +24 -0
  56. package/lib/src/Modules.js +26 -0
  57. package/lib/src/client/BrandClient.js +17 -0
  58. package/lib/src/client/ClientModule.js +14 -0
  59. package/lib/src/client/CourierClient.js +31 -0
  60. package/lib/src/client/InboxClient.js +99 -0
  61. package/lib/src/client/PreferenceClient.js +63 -0
  62. package/lib/src/client/TokenClient.js +27 -0
  63. package/lib/src/client/TrackingClient.js +17 -0
  64. package/lib/src/index.js +567 -0
  65. package/lib/src/models/Android_CourierSheet.js +1 -0
  66. package/lib/src/models/CourierAuthenticationListener.js +14 -0
  67. package/lib/src/models/CourierBrand.js +1 -0
  68. package/lib/src/models/CourierButton.js +1 -0
  69. package/lib/src/models/CourierDevice.js +1 -0
  70. package/lib/src/models/CourierFont.js +1 -0
  71. package/lib/src/models/CourierInboxListener.js +20 -0
  72. package/lib/src/models/CourierInboxMessages.js +1 -0
  73. package/lib/src/models/CourierInboxTheme.js +1 -0
  74. package/lib/src/models/CourierInfoViewStyle.js +1 -0
  75. package/lib/src/models/CourierPaging.js +1 -0
  76. package/lib/src/models/CourierPreferencesTheme.js +1 -0
  77. package/lib/src/models/CourierPushListener.js +14 -0
  78. package/lib/src/models/CourierPushProvider.js +8 -0
  79. package/lib/src/models/CourierTrackingEvent.js +8 -0
  80. package/lib/src/models/CourierUserPreferences.js +51 -0
  81. package/lib/src/models/InboxAction.js +1 -0
  82. package/lib/src/models/InboxMessage.js +1 -0
  83. package/lib/src/models/InboxMessageFeed.js +1 -0
  84. package/lib/src/models/InboxMessageSet.js +1 -0
  85. package/lib/src/models/iOS_CourierCell.js +1 -0
  86. package/lib/src/models/iOS_CourierSheet.js +1 -0
  87. package/lib/src/utils.js +27 -0
  88. package/lib/src/views/CourierInboxView.js +75 -0
  89. package/lib/src/views/CourierPreferencesView.js +33 -0
  90. package/lib/typescript/src/index.d.ts +16 -20
  91. package/lib/typescript/src/index.d.ts.map +1 -1
  92. package/lib/typescript/src/models/CourierInboxListener.d.ts +4 -7
  93. package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -1
  94. package/lib/typescript/src/models/InboxAction.d.ts +8 -4
  95. package/lib/typescript/src/models/InboxAction.d.ts.map +1 -1
  96. package/lib/typescript/src/models/InboxMessage.d.ts +28 -14
  97. package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -1
  98. package/lib/typescript/src/models/InboxMessageEvent.d.ts +2 -0
  99. package/lib/typescript/src/models/InboxMessageEvent.d.ts.map +1 -0
  100. package/lib/typescript/src/models/InboxMessageFeed.d.ts +1 -1
  101. package/lib/typescript/src/models/InboxMessageFeed.d.ts.map +1 -1
  102. package/package.json +3 -2
  103. package/src/index.tsx +61 -99
  104. package/src/models/CourierInboxListener.tsx +10 -13
  105. package/src/models/InboxAction.tsx +28 -4
  106. package/src/models/InboxMessage.tsx +102 -14
  107. package/src/models/InboxMessageEvent.tsx +1 -0
  108. package/src/models/InboxMessageFeed.tsx +1 -1
  109. package/src/views/CourierInboxView.tsx +4 -4
  110. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  111. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  112. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcuserdata/mike.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  113. package/ios/CourierReactNative.xcodeproj/xcuserdata/mike.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
@@ -103,14 +103,14 @@ dependencies {
103
103
  // For < 0.71, this will be from the local maven repo
104
104
  // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
105
105
  //noinspection GradleDynamicVersion
106
- implementation "com.facebook.react:react-native:+"
106
+ implementation "com.facebook.react:react-android:0.73.7"
107
107
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
108
108
 
109
109
  // For converting to json
110
110
  implementation 'com.google.code.gson:gson:2.11.0'
111
111
 
112
112
  // Courier Core SDK
113
- api 'com.github.trycourier:courier-android:5.1.11'
113
+ api 'com.github.trycourier:courier-android:5.2.0'
114
114
  api 'androidx.recyclerview:recyclerview:1.3.2'
115
115
 
116
116
  }
@@ -241,8 +241,17 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
241
241
  }
242
242
 
243
243
  @ReactMethod
244
- fun addInboxListener(listenerId: String, loadingId: String, errorId: String, unreadCountId: String, feedId: String, archiveId: String, pageAddedId: String, messageChangedId: String, messageAddedId: String, messageRemovedId: String, promise: Promise) {
245
-
244
+ fun addInboxListener(
245
+ listenerId: String,
246
+ loadingId: String,
247
+ errorId: String,
248
+ unreadCountId: String,
249
+ totalCountId: String,
250
+ messagesChangedId: String,
251
+ pageAddedId: String,
252
+ messageEventId: String,
253
+ promise: Promise
254
+ ) = CoroutineScope(Dispatchers.Main).launch {
246
255
  val listener = Courier.shared.addInboxListener(
247
256
  onLoading = { isRefresh ->
248
257
  reactApplicationContext.sendEvent(
@@ -262,66 +271,56 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
262
271
  value = unreadCount
263
272
  )
264
273
  },
265
- onFeedChanged = { messageSet ->
266
- reactApplicationContext.sendEvent(
267
- eventName = feedId,
268
- value = messageSet.toJson()
269
- )
270
- },
271
- onArchiveChanged = { messageSet ->
274
+ onTotalCountChanged = { totalCount, feed ->
275
+ val json = Arguments.createMap().apply {
276
+ putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
277
+ putInt("totalCount", totalCount)
278
+ }
272
279
  reactApplicationContext.sendEvent(
273
- eventName = archiveId,
274
- value = messageSet.toJson()
275
- )
276
- },
277
- onPageAdded = { feed, messageSet ->
278
- val json = Arguments.createMap()
279
- json.putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archived")
280
- json.putArray("messages", messageSet.messages.map { it.toJson() }.toWritableArray())
281
- json.putInt("totalMessageCount", messageSet.totalCount)
282
- json.putBoolean("canPaginate", messageSet.canPaginate)
283
- reactApplicationContext.sendEvent(
284
- eventName = pageAddedId,
280
+ eventName = totalCountId,
285
281
  value = json
286
282
  )
287
283
  },
288
- onMessageAdded = { feed, index, message ->
289
- val json = Arguments.createMap()
290
- json.putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archived")
291
- json.putInt("index", index)
292
- json.putString("message", message.toJson())
284
+ onMessagesChanged = { messages, canPaginate, feed ->
285
+ val json = Arguments.createMap().apply {
286
+ putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
287
+ putArray("messages", messages.map { it.toJson() }.toWritableArray())
288
+ putBoolean("canPaginate", canPaginate)
289
+ }
293
290
  reactApplicationContext.sendEvent(
294
- eventName = messageAddedId,
291
+ eventName = messagesChangedId,
295
292
  value = json
296
293
  )
297
294
  },
298
- onMessageChanged = { feed, index, message ->
299
- val json = Arguments.createMap()
300
- json.putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archived")
301
- json.putInt("index", index)
302
- json.putString("message", message.toJson())
295
+ onPageAdded = { messages, canPaginate, isFirstPage, feed ->
296
+ val json = Arguments.createMap().apply {
297
+ putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
298
+ putArray("messages", messages.map { it.toJson() }.toWritableArray())
299
+ putBoolean("canPaginate", canPaginate)
300
+ putBoolean("isFirstPage", isFirstPage)
301
+ }
303
302
  reactApplicationContext.sendEvent(
304
- eventName = messageChangedId,
303
+ eventName = pageAddedId,
305
304
  value = json
306
305
  )
307
306
  },
308
- onMessageRemoved = { feed, index, message ->
309
- val json = Arguments.createMap()
310
- json.putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archived")
311
- json.putInt("index", index)
312
- json.putString("message", message.toJson())
307
+ onMessageEvent = { message, index, feed, event ->
308
+ val json = Arguments.createMap().apply {
309
+ putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
310
+ putInt("index", index)
311
+ putString("event", event.value)
312
+ putString("message", message.toJson())
313
+ }
313
314
  reactApplicationContext.sendEvent(
314
- eventName = messageRemovedId,
315
+ eventName = messageEventId,
315
316
  value = json
316
317
  )
317
- },
318
+ }
318
319
  )
319
320
 
320
- // Add listener
321
321
  inboxListeners[listenerId] = listener
322
322
 
323
323
  promise.resolve(listenerId)
324
-
325
324
  }
326
325
 
327
326
  private fun InboxMessageSet.toJson(): WritableMap? {
@@ -15,7 +15,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
15
15
  import com.google.gson.GsonBuilder
16
16
 
17
17
  internal object Utils {
18
- val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.4.3")
18
+ val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.5.0")
19
19
  }
20
20
 
21
21
  internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
@@ -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", "5.6.1"
20
+ s.dependency "Courier_iOS", "5.7.4"
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.
@@ -10,10 +10,14 @@
10
10
  #pragma GCC diagnostic ignored "-Wprotocol"
11
11
  #pragma clang diagnostic ignored "-Wprotocol"
12
12
 
13
- @implementation CourierReactNativeDelegate
13
+ @interface CourierReactNativeDelegate ()
14
+
15
+ @property (nonatomic, copy) NSString *iosForegroundNotificationPresentationOptions;
16
+ @property (nonatomic, assign) UNNotificationPresentationOptions notificationPresentationOptions;
14
17
 
15
- NSString *iosForegroundNotificationPresentationOptions = @"iosForegroundNotificationPresentationOptions";
16
- NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNone;
18
+ @end
19
+
20
+ @implementation CourierReactNativeDelegate
17
21
 
18
22
  - (id) init {
19
23
 
@@ -22,7 +26,7 @@ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNon
22
26
  if (self) {
23
27
 
24
28
  // Set the user agent
25
- Courier.agent = [CourierAgent reactNativeIOS:@"5.4.3"];
29
+ Courier.agent = [CourierAgent reactNativeIOS:@"5.5.0"];
26
30
 
27
31
  // Register for remote notifications
28
32
  UIApplication *app = [UIApplication sharedApplication];
@@ -35,7 +39,7 @@ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNon
35
39
  [[NSNotificationCenter defaultCenter]
36
40
  addObserver:self
37
41
  selector:@selector(notificationPresentationOptionsUpdate:)
38
- name:iosForegroundNotificationPresentationOptions
42
+ name:_iosForegroundNotificationPresentationOptions
39
43
  object:nil
40
44
  ];
41
45
 
@@ -47,10 +51,10 @@ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNon
47
51
 
48
52
  - (void) notificationPresentationOptionsUpdate:(NSNotification *) notification
49
53
  {
50
- if ([[notification name] isEqualToString:iosForegroundNotificationPresentationOptions])
54
+ if ([[notification name] isEqualToString:_iosForegroundNotificationPresentationOptions])
51
55
  {
52
56
  NSDictionary *userInfo = notification.userInfo;
53
- notificationPresentationOptions = ((NSNumber *) [userInfo objectForKey:@"options"]).unsignedIntegerValue;
57
+ _notificationPresentationOptions = ((NSNumber *) [userInfo objectForKey:@"options"]).unsignedIntegerValue;
54
58
  }
55
59
  }
56
60
 
@@ -71,7 +75,7 @@ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNon
71
75
  NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
72
76
  [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered" object:nil userInfo:pushNotification];
73
77
 
74
- completionHandler(notificationPresentationOptions);
78
+ completionHandler(self->_notificationPresentationOptions);
75
79
 
76
80
  });
77
81
 
@@ -14,7 +14,7 @@ internal class CourierReactNativeEventEmitter: RCTEventEmitter {
14
14
 
15
15
  // Set the user agent
16
16
  // Used to know the platform performing requests
17
- Courier.agent = CourierAgent.reactNativeIOS("5.4.3")
17
+ Courier.agent = CourierAgent.reactNativeIOS("5.5.0")
18
18
 
19
19
  }
20
20
 
@@ -139,12 +139,10 @@ RCT_EXTERN_METHOD(
139
139
  withLoadingId: (NSString*)loadingId
140
140
  withErrorId: (NSString*)errorId
141
141
  withUnreadCountId: (NSString*)unreadCountId
142
- withFeedId: (NSString*)feedId
143
- withArchiveId: (NSString*)archiveId
142
+ withTotalCountId: (NSString*)totalCountId
143
+ withMessagesChangedId: (NSString*)messagesChangedId
144
144
  withPageAddedId: (NSString*)pageAddedId
145
- withMessageChangedId: (NSString*)messageChangedId
146
- withMessageAddedId: (NSString*)messageAddedId
147
- withMessageRemovedId: (NSString*)messageRemovedId
145
+ withMessageEventId: (NSString*)messageEventId
148
146
  withResolver: (RCTPromiseResolveBlock)resolve
149
147
  withRejecter: (RCTPromiseRejectBlock)reject
150
148
  )
@@ -314,18 +314,27 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
314
314
 
315
315
  }
316
316
 
317
- @objc(addInboxListener:withLoadingId:withErrorId:withUnreadCountId:withFeedId:withArchiveId:withPageAddedId:withMessageChangedId:withMessageAddedId:withMessageRemovedId:withResolver:withRejecter:)
318
- func addInboxListener(listenerId: String, loadingId: String, errorId: String, unreadCountId: String, feedId: String, archiveId: String, pageAddedId: String, messageChangedId: String, messageAddedId: String, messageRemovedId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
319
-
320
- Task {
321
-
322
- // Create the new listener
323
- let listener = await Courier.shared.addInboxListener(
317
+ @objc(addInboxListener:withLoadingId:withErrorId:withUnreadCountId:withTotalCountId:withMessagesChangedId:withPageAddedId:withMessageEventId:withResolver:withRejecter:)
318
+ func addInboxListener(
319
+ listenerId: String,
320
+ loadingId: String,
321
+ errorId: String,
322
+ unreadCountId: String,
323
+ totalCountId: String,
324
+ messagesChangedId: String,
325
+ pageAddedId: String,
326
+ messageEventId: String,
327
+ resolve: @escaping RCTPromiseResolveBlock,
328
+ reject: @escaping RCTPromiseRejectBlock
329
+ ) -> Void {
330
+
331
+ Task {
332
+ let listener = await Courier.shared.addInboxListener(
324
333
  onLoading: { [weak self] isRefresh in
325
- self?.broadcast(
326
- name: loadingId,
327
- body: isRefresh
328
- )
334
+ self?.broadcast(
335
+ name: loadingId,
336
+ body: isRefresh
337
+ )
329
338
  },
330
339
  onError: { [weak self] error in
331
340
  self?.broadcast(
@@ -334,122 +343,89 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
334
343
  )
335
344
  },
336
345
  onUnreadCountChanged: { [weak self] unreadCount in
337
- self?.broadcast(
338
- name: unreadCountId,
339
- body: unreadCount
340
- )
341
- },
342
- onFeedChanged: { [weak self] set in
343
- do {
344
- let json: [String: Any] = [
345
- "messages": try set.messages.map { try $0.toJson() ?? "" },
346
- "totalMessageCount": set.totalCount,
347
- "canPaginate": set.canPaginate
348
- ]
349
346
  self?.broadcast(
350
- name: feedId,
351
- body: json
347
+ name: unreadCountId,
348
+ body: unreadCount
352
349
  )
353
- } catch {
354
- Task {
355
- await Courier.shared.client?.error(error.localizedDescription)
356
- }
357
- }
358
- },
359
- onArchiveChanged: { [weak self] set in
360
- do {
361
- let json: [String: Any] = [
362
- "messages": try set.messages.map { try $0.toJson() ?? "" },
363
- "totalMessageCount": set.totalCount,
364
- "canPaginate": set.canPaginate
365
- ]
366
- self?.broadcast(
367
- name: archiveId,
368
- body: json
369
- )
370
- } catch {
371
- Task {
372
- await Courier.shared.client?.error(error.localizedDescription)
373
- }
374
- }
375
350
  },
376
- onPageAdded: { [weak self] feed, set in
377
- do {
351
+ onTotalCountChanged: { [weak self] totalCount, feed in
352
+ let feedName = (feed == .archive) ? "archive" : "feed"
378
353
  let json: [String: Any] = [
379
- "feed": feed == .archived ? "archived" : "feed",
380
- "messages": try set.messages.map { try $0.toJson() ?? "" },
381
- "totalMessageCount": set.totalCount,
382
- "canPaginate": set.canPaginate
354
+ "totalCount": totalCount,
355
+ "feed": feedName
383
356
  ]
384
357
  self?.broadcast(
385
- name: pageAddedId,
386
- body: json
358
+ name: totalCountId,
359
+ body: json
387
360
  )
388
- } catch {
389
- Task {
390
- await Courier.shared.client?.error(error.localizedDescription)
391
- }
392
- }
393
361
  },
394
- onMessageChanged: { [weak self] feed, index, message in
395
- do {
396
- let json: [String: Any] = [
397
- "feed": feed == .archived ? "archived" : "feed",
398
- "index": index,
399
- "message": try message.toJson() ?? "",
400
- ]
401
- self?.broadcast(
402
- name: messageChangedId,
403
- body: json
404
- )
405
- } catch {
406
- Task {
407
- await Courier.shared.client?.error(error.localizedDescription)
362
+ onMessagesChanged: { [weak self] messages, canPaginate, feed in
363
+ // Convert each InboxMessage to JSON
364
+ do {
365
+ let feedName = (feed == .archive) ? "archive" : "feed"
366
+ let json: [String: Any] = [
367
+ "feed": feedName,
368
+ "canPaginate": canPaginate,
369
+ "messages": try messages.map { try $0.toJson() ?? "" }
370
+ ]
371
+ self?.broadcast(
372
+ name: messagesChangedId,
373
+ body: json
374
+ )
375
+ } catch {
376
+ Task {
377
+ await Courier.shared.client?.error(error.localizedDescription)
378
+ }
408
379
  }
409
- }
410
380
  },
411
- onMessageAdded: { [weak self] feed, index, message in
412
- do {
413
- let json: [String: Any] = [
414
- "feed": feed == .archived ? "archived" : "feed",
415
- "index": index,
416
- "message": try message.toJson() ?? "",
417
- ]
418
- self?.broadcast(
419
- name: messageAddedId,
420
- body: json
421
- )
422
- } catch {
423
- Task {
424
- await Courier.shared.client?.error(error.localizedDescription)
381
+ onPageAdded: { [weak self] messages, canPaginate, isFirstPage, feed in
382
+ // Convert each InboxMessage to JSON
383
+ do {
384
+ let feedName = (feed == .archive) ? "archive" : "feed"
385
+ let json: [String: Any] = [
386
+ "feed": feedName,
387
+ "canPaginate": canPaginate,
388
+ "isFirstPage": isFirstPage,
389
+ "messages": try messages.map { try $0.toJson() ?? "" }
390
+ ]
391
+ self?.broadcast(
392
+ name: pageAddedId,
393
+ body: json
394
+ )
395
+ } catch {
396
+ Task {
397
+ await Courier.shared.client?.error(error.localizedDescription)
398
+ }
425
399
  }
426
- }
427
400
  },
428
- onMessageRemoved: { [weak self] feed, index, message in
429
- do {
430
- let json: [String: Any] = [
431
- "feed": feed == .archived ? "archived" : "feed",
432
- "index": index,
433
- "message": try message.toJson() ?? "",
434
- ]
435
- self?.broadcast(
436
- name: messageRemovedId,
437
- body: json
438
- )
439
- } catch {
440
- Task {
441
- await Courier.shared.client?.error(error.localizedDescription)
401
+ onMessageEvent: { [weak self] message, index, feed, event in
402
+ do {
403
+ let feedName = (feed == .archive) ? "archive" : "feed"
404
+ let eventName = event.rawValue // or handle explicitly as needed
405
+ let json: [String: Any] = [
406
+ "feed": feedName,
407
+ "event": eventName,
408
+ "index": index,
409
+ "message": try message.toJson() ?? ""
410
+ ]
411
+ self?.broadcast(
412
+ name: messageEventId,
413
+ body: json
414
+ )
415
+ } catch {
416
+ Task {
417
+ await Courier.shared.client?.error(error.localizedDescription)
418
+ }
442
419
  }
443
- }
444
420
  }
445
- )
446
-
447
- inboxListeners[listenerId] = listener
421
+ )
448
422
 
449
- resolve(listenerId)
423
+ // Store the listener so you can remove it later if needed
424
+ inboxListeners[listenerId] = listener
450
425
 
451
- }
452
-
426
+ // Resolve with the listenerId so JS knows the registration succeeded
427
+ resolve(listenerId)
428
+ }
453
429
  }
454
430
 
455
431
  @objc(removeInboxListener:withResolver:withRejecter:)
@@ -498,7 +474,7 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
498
474
  func fetchNextPageOfMessages(inboxMessageFeed: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
499
475
  Task {
500
476
  do {
501
- let value: InboxMessageFeed = inboxMessageFeed == "archived" ? .feed : .archived
477
+ let value: InboxMessageFeed = inboxMessageFeed == "archive" ? .feed : .archive
502
478
  let messages = try await Courier.shared.fetchNextInboxPage(value)
503
479
  resolve(try messages.map { try $0.toJson() ?? "" })
504
480
  } catch {