@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.
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +41 -42
- 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
package/android/build.gradle
CHANGED
|
@@ -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-
|
|
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.
|
|
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(
|
|
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
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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 =
|
|
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
|
-
|
|
289
|
-
val json = Arguments.createMap()
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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 =
|
|
291
|
+
eventName = messagesChangedId,
|
|
295
292
|
value = json
|
|
296
293
|
)
|
|
297
294
|
},
|
|
298
|
-
|
|
299
|
-
val json = Arguments.createMap()
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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 =
|
|
303
|
+
eventName = pageAddedId,
|
|
305
304
|
value = json
|
|
306
305
|
)
|
|
307
306
|
},
|
|
308
|
-
|
|
309
|
-
val json = Arguments.createMap()
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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 =
|
|
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.
|
|
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.
|
|
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
|
-
@
|
|
13
|
+
@interface CourierReactNativeDelegate ()
|
|
14
|
+
|
|
15
|
+
@property (nonatomic, copy) NSString *iosForegroundNotificationPresentationOptions;
|
|
16
|
+
@property (nonatomic, assign) UNNotificationPresentationOptions notificationPresentationOptions;
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
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.
|
|
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:
|
|
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:
|
|
54
|
+
if ([[notification name] isEqualToString:_iosForegroundNotificationPresentationOptions])
|
|
51
55
|
{
|
|
52
56
|
NSDictionary *userInfo = notification.userInfo;
|
|
53
|
-
|
|
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(
|
|
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.
|
|
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
|
-
|
|
143
|
-
|
|
142
|
+
withTotalCountId: (NSString*)totalCountId
|
|
143
|
+
withMessagesChangedId: (NSString*)messagesChangedId
|
|
144
144
|
withPageAddedId: (NSString*)pageAddedId
|
|
145
|
-
|
|
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:
|
|
318
|
-
func addInboxListener(
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
-
|
|
351
|
-
|
|
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
|
-
|
|
377
|
-
|
|
351
|
+
onTotalCountChanged: { [weak self] totalCount, feed in
|
|
352
|
+
let feedName = (feed == .archive) ? "archive" : "feed"
|
|
378
353
|
let json: [String: Any] = [
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
"totalMessageCount": set.totalCount,
|
|
382
|
-
"canPaginate": set.canPaginate
|
|
354
|
+
"totalCount": totalCount,
|
|
355
|
+
"feed": feedName
|
|
383
356
|
]
|
|
384
357
|
self?.broadcast(
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
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 == "
|
|
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 {
|