@trycourier/courier-react-native 3.2.2 → 4.1.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/README.md +14 -3
- package/android/build.gradle +4 -1
- package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +441 -0
- package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -2
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +4 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +9 -3
- package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +312 -0
- package/android/src/main/java/com/courierreactnative/CourierSystemModule.kt +91 -0
- package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +36 -0
- package/android/src/main/java/com/courierreactnative/{Extensions.kt → Utils.kt} +5 -5
- package/courier-react-native.podspec +1 -1
- package/ios/CourierClientModule.swift +450 -0
- package/ios/CourierInboxReactNativeManager.swift +17 -9
- package/ios/CourierReactNativeDelegate.m +21 -35
- package/ios/CourierReactNativeEventEmitter.swift +25 -0
- package/ios/CourierReactNativeModule.m +192 -23
- package/ios/CourierSharedModule.swift +412 -0
- package/ios/CourierSystemModule.swift +136 -0
- package/ios/Utils.swift +103 -115
- package/lib/commonjs/Broadcaster.js +30 -0
- package/lib/commonjs/Broadcaster.js.map +1 -0
- package/lib/commonjs/Modules.js +25 -0
- package/lib/commonjs/Modules.js.map +1 -0
- package/lib/commonjs/client/BrandClient.js +25 -0
- package/lib/commonjs/client/BrandClient.js.map +1 -0
- package/lib/commonjs/client/ClientModule.js +21 -0
- package/lib/commonjs/client/ClientModule.js.map +1 -0
- package/lib/commonjs/client/CourierClient.js +33 -0
- package/lib/commonjs/client/CourierClient.js.map +1 -0
- package/lib/commonjs/client/InboxClient.js +116 -0
- package/lib/commonjs/client/InboxClient.js.map +1 -0
- package/lib/commonjs/client/PreferenceClient.js +73 -0
- package/lib/commonjs/client/PreferenceClient.js.map +1 -0
- package/lib/commonjs/client/TokenClient.js +36 -0
- package/lib/commonjs/client/TokenClient.js.map +1 -0
- package/lib/commonjs/client/TrackingClient.js +25 -0
- package/lib/commonjs/client/TrackingClient.js.map +1 -0
- package/lib/commonjs/index.js +418 -186
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/Android_CourierSheet.js.map +1 -1
- package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/commonjs/models/CourierBrand.js +2 -0
- package/lib/commonjs/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
- package/lib/commonjs/models/CourierButton.js.map +1 -1
- package/lib/commonjs/models/CourierDevice.js +2 -0
- package/lib/commonjs/models/CourierDevice.js.map +1 -0
- package/lib/commonjs/models/CourierFont.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js +2 -2
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
- package/lib/commonjs/models/{CourierUserPreferencesTopic.js → CourierInboxMessages.js} +1 -1
- package/lib/commonjs/models/CourierInboxMessages.js.map +1 -0
- package/lib/commonjs/models/CourierInboxTheme.js.map +1 -1
- package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -1
- package/lib/commonjs/models/CourierPaging.js.map +1 -1
- package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -1
- package/lib/commonjs/models/CourierPushListener.js +7 -3
- package/lib/commonjs/models/CourierPushListener.js.map +1 -1
- package/lib/commonjs/models/CourierPushProvider.js.map +1 -1
- package/lib/commonjs/models/CourierTrackingEvent.js +16 -0
- package/lib/commonjs/models/CourierTrackingEvent.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferences.js +54 -0
- package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
- package/lib/commonjs/models/InboxAction.js.map +1 -1
- package/lib/commonjs/models/InboxMessage.js.map +1 -1
- package/lib/commonjs/models/iOS_CourierCell.js.map +1 -1
- package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -1
- package/lib/commonjs/utils.js +9 -17
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/views/CourierInboxView.js +3 -3
- package/lib/commonjs/views/CourierInboxView.js.map +1 -1
- package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
- package/lib/module/Broadcaster.js +23 -0
- package/lib/module/Broadcaster.js.map +1 -0
- package/lib/module/Modules.js +18 -0
- package/lib/module/Modules.js.map +1 -0
- package/lib/module/client/BrandClient.js +18 -0
- package/lib/module/client/BrandClient.js.map +1 -0
- package/lib/module/client/ClientModule.js +14 -0
- package/lib/module/client/ClientModule.js.map +1 -0
- package/lib/module/client/CourierClient.js +26 -0
- package/lib/module/client/CourierClient.js.map +1 -0
- package/lib/module/client/InboxClient.js +109 -0
- package/lib/module/client/InboxClient.js.map +1 -0
- package/lib/module/client/PreferenceClient.js +66 -0
- package/lib/module/client/PreferenceClient.js.map +1 -0
- package/lib/module/client/TokenClient.js +29 -0
- package/lib/module/client/TokenClient.js.map +1 -0
- package/lib/module/client/TrackingClient.js +18 -0
- package/lib/module/client/TrackingClient.js.map +1 -0
- package/lib/module/index.js +383 -185
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/Android_CourierSheet.js.map +1 -1
- package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/module/models/CourierBrand.js +2 -0
- package/lib/module/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
- package/lib/module/models/CourierButton.js.map +1 -1
- package/lib/module/models/CourierDevice.js +2 -0
- package/lib/module/models/CourierDevice.js.map +1 -0
- package/lib/module/models/CourierFont.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js +1 -1
- package/lib/module/models/CourierInboxListener.js.map +1 -1
- package/lib/module/models/CourierInboxMessages.js +2 -0
- package/lib/module/models/CourierInboxMessages.js.map +1 -0
- package/lib/module/models/CourierInboxTheme.js.map +1 -1
- package/lib/module/models/CourierInfoViewStyle.js.map +1 -1
- package/lib/module/models/CourierPaging.js.map +1 -1
- package/lib/module/models/CourierPreferencesTheme.js.map +1 -1
- package/lib/module/models/CourierPushListener.js +7 -3
- package/lib/module/models/CourierPushListener.js.map +1 -1
- package/lib/module/models/CourierPushProvider.js.map +1 -1
- package/lib/module/models/CourierTrackingEvent.js +9 -0
- package/lib/module/models/CourierTrackingEvent.js.map +1 -0
- package/lib/module/models/CourierUserPreferences.js +53 -1
- package/lib/module/models/CourierUserPreferences.js.map +1 -1
- package/lib/module/models/InboxAction.js.map +1 -1
- package/lib/module/models/InboxMessage.js.map +1 -1
- package/lib/module/models/iOS_CourierCell.js.map +1 -1
- package/lib/module/models/iOS_CourierSheet.js.map +1 -1
- package/lib/module/utils.js +7 -16
- package/lib/module/utils.js.map +1 -1
- package/lib/module/views/CourierInboxView.js +3 -3
- package/lib/module/views/CourierInboxView.js.map +1 -1
- package/lib/module/views/CourierPreferencesView.js.map +1 -1
- package/lib/typescript/src/Broadcaster.d.ts +14 -0
- package/lib/typescript/src/Broadcaster.d.ts.map +1 -0
- package/lib/typescript/src/Modules.d.ts +8 -0
- package/lib/typescript/src/Modules.d.ts.map +1 -0
- package/lib/typescript/src/client/BrandClient.d.ts +15 -0
- package/lib/typescript/src/client/BrandClient.d.ts.map +1 -0
- package/lib/typescript/src/client/ClientModule.d.ts +8 -0
- package/lib/typescript/src/client/ClientModule.d.ts.map +1 -0
- package/lib/typescript/src/client/CourierClient.d.ts +31 -0
- package/lib/typescript/src/client/CourierClient.d.ts.map +1 -0
- package/lib/typescript/src/client/InboxClient.d.ts +94 -0
- package/lib/typescript/src/client/InboxClient.d.ts.map +1 -0
- package/lib/typescript/src/client/PreferenceClient.d.ts +39 -0
- package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -0
- package/lib/typescript/src/client/TokenClient.d.ts +28 -0
- package/lib/typescript/src/client/TokenClient.d.ts.map +1 -0
- package/lib/typescript/src/client/TrackingClient.d.ts +17 -0
- package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +300 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierBrand.d.ts +20 -0
- package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierButton.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierDevice.d.ts +9 -0
- package/lib/typescript/src/models/CourierDevice.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierFont.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInboxMessages.d.ts +23 -0
- package/lib/typescript/src/models/CourierInboxMessages.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPaging.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPushListener.d.ts +8 -0
- package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPushProvider.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierTrackingEvent.d.ts +8 -0
- package/lib/typescript/src/models/CourierTrackingEvent.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierUserPreferences.d.ts +35 -0
- package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -0
- package/lib/typescript/src/models/InboxAction.d.ts.map +1 -0
- package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -0
- package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -0
- package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +14 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -0
- package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/Broadcaster.tsx +32 -0
- package/src/Modules.tsx +28 -0
- package/src/client/BrandClient.tsx +23 -0
- package/src/client/ClientModule.tsx +21 -0
- package/src/client/CourierClient.tsx +49 -0
- package/src/client/InboxClient.tsx +114 -0
- package/src/client/PreferenceClient.tsx +77 -0
- package/src/client/TokenClient.tsx +34 -0
- package/src/client/TrackingClient.tsx +23 -0
- package/src/index.tsx +398 -205
- package/src/models/CourierBrand.tsx +24 -0
- package/src/models/CourierDevice.tsx +8 -0
- package/src/models/CourierInboxListener.tsx +1 -1
- package/src/models/CourierInboxMessages.tsx +28 -0
- package/src/models/CourierPushListener.tsx +11 -6
- package/src/models/CourierTrackingEvent.tsx +7 -0
- package/src/models/CourierUserPreferences.tsx +70 -3
- package/src/utils.tsx +7 -23
- package/src/views/CourierInboxView.tsx +3 -3
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +0 -393
- package/ios/CourierReactNativeModule.swift +0 -524
- package/lib/commonjs/models/CourierUserPreferencesChannel.js +0 -17
- package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +0 -1
- package/lib/commonjs/models/CourierUserPreferencesStatus.js +0 -15
- package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +0 -1
- package/lib/module/models/CourierUserPreferencesChannel.js +0 -10
- package/lib/module/models/CourierUserPreferencesChannel.js.map +0 -1
- package/lib/module/models/CourierUserPreferencesStatus.js +0 -8
- package/lib/module/models/CourierUserPreferencesStatus.js.map +0 -1
- package/lib/module/models/CourierUserPreferencesTopic.js +0 -2
- package/lib/typescript/index.d.ts +0 -199
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/models/Android_CourierSheet.d.ts.map +0 -1
- package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +0 -1
- package/lib/typescript/models/CourierButton.d.ts.map +0 -1
- package/lib/typescript/models/CourierFont.d.ts.map +0 -1
- package/lib/typescript/models/CourierInboxListener.d.ts.map +0 -1
- package/lib/typescript/models/CourierInboxTheme.d.ts.map +0 -1
- package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +0 -1
- package/lib/typescript/models/CourierPaging.d.ts.map +0 -1
- package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +0 -1
- package/lib/typescript/models/CourierPushListener.d.ts +0 -7
- package/lib/typescript/models/CourierPushListener.d.ts.map +0 -1
- package/lib/typescript/models/CourierPushProvider.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferences.d.ts +0 -7
- package/lib/typescript/models/CourierUserPreferences.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +0 -9
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +0 -7
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +0 -13
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +0 -1
- package/lib/typescript/models/InboxAction.d.ts.map +0 -1
- package/lib/typescript/models/InboxMessage.d.ts.map +0 -1
- package/lib/typescript/models/iOS_CourierCell.d.ts.map +0 -1
- package/lib/typescript/models/iOS_CourierSheet.d.ts.map +0 -1
- package/lib/typescript/utils.d.ts +0 -21
- package/lib/typescript/utils.d.ts.map +0 -1
- package/lib/typescript/views/CourierInboxView.d.ts.map +0 -1
- package/lib/typescript/views/CourierPreferencesView.d.ts.map +0 -1
- package/src/models/CourierUserPreferencesChannel.tsx +0 -8
- package/src/models/CourierUserPreferencesStatus.tsx +0 -6
- package/src/models/CourierUserPreferencesTopic.tsx +0 -13
- /package/lib/typescript/{models → src/models}/Android_CourierSheet.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierAuthenticationListener.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierButton.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierFont.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierInboxListener.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierInboxTheme.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierInfoViewStyle.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierPaging.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierPreferencesTheme.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierPushProvider.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/InboxAction.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/InboxMessage.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/iOS_CourierCell.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/iOS_CourierSheet.d.ts +0 -0
- /package/lib/typescript/{views → src/views}/CourierInboxView.d.ts +0 -0
- /package/lib/typescript/{views → src/views}/CourierPreferencesView.d.ts +0 -0
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
2
|
|
|
3
|
-
@interface RCT_EXTERN_MODULE(
|
|
3
|
+
@interface RCT_EXTERN_MODULE(CourierSharedModule, NSObject)
|
|
4
4
|
|
|
5
5
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
6
|
-
|
|
6
|
+
getClient
|
|
7
7
|
)
|
|
8
8
|
|
|
9
9
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
10
|
-
|
|
10
|
+
getUserId
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
14
|
+
getTenantId
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
18
|
+
getIsUserSignedIn
|
|
11
19
|
)
|
|
12
20
|
|
|
13
21
|
RCT_EXTERN_METHOD(
|
|
@@ -15,6 +23,7 @@ RCT_EXTERN_METHOD(
|
|
|
15
23
|
withClientKey: (NSString*)clientKey
|
|
16
24
|
withUserId: (NSString*)userId
|
|
17
25
|
withTenantId: (NSString*)tenantId
|
|
26
|
+
withShowLogs: (BOOL*)showLogs
|
|
18
27
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
19
28
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
20
29
|
)
|
|
@@ -25,54 +34,71 @@ RCT_EXTERN_METHOD(
|
|
|
25
34
|
)
|
|
26
35
|
|
|
27
36
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
28
|
-
|
|
37
|
+
addAuthenticationListener: (NSString*)authId
|
|
29
38
|
)
|
|
30
39
|
|
|
31
40
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
32
|
-
|
|
41
|
+
removeAuthenticationListener: (NSString*)listenerId
|
|
33
42
|
)
|
|
34
43
|
|
|
35
44
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
36
|
-
|
|
45
|
+
removeAllAuthenticationListeners
|
|
37
46
|
)
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
RCT_EXTERN_METHOD(
|
|
49
|
+
getAllTokens: (RCTPromiseResolveBlock)resolve
|
|
50
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
41
51
|
)
|
|
42
52
|
|
|
43
53
|
RCT_EXTERN_METHOD(
|
|
44
|
-
|
|
54
|
+
getToken: (NSString*)provider
|
|
55
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
45
56
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
46
57
|
)
|
|
47
58
|
|
|
48
59
|
RCT_EXTERN_METHOD(
|
|
49
|
-
|
|
60
|
+
setToken: (NSString*)provider
|
|
61
|
+
withToken: (NSString*)token
|
|
62
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
50
63
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
51
64
|
)
|
|
52
65
|
|
|
66
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
67
|
+
getInboxPaginationLimit
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
71
|
+
setInboxPaginationLimit: (double)limit
|
|
72
|
+
)
|
|
73
|
+
|
|
53
74
|
RCT_EXTERN_METHOD(
|
|
54
|
-
|
|
55
|
-
withToken: (NSString*)token
|
|
75
|
+
openMessage: (NSString*)messageId
|
|
56
76
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
57
77
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
58
78
|
)
|
|
59
79
|
|
|
60
80
|
RCT_EXTERN_METHOD(
|
|
61
|
-
|
|
81
|
+
archiveMessage: (NSString*)messageId
|
|
62
82
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
63
83
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
64
84
|
)
|
|
65
85
|
|
|
66
|
-
|
|
86
|
+
RCT_EXTERN_METHOD(
|
|
67
87
|
clickMessage: (NSString*)messageId
|
|
88
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
89
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
68
90
|
)
|
|
69
91
|
|
|
70
|
-
|
|
92
|
+
RCT_EXTERN_METHOD(
|
|
71
93
|
readMessage: (NSString*)messageId
|
|
94
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
95
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
72
96
|
)
|
|
73
97
|
|
|
74
|
-
|
|
98
|
+
RCT_EXTERN_METHOD(
|
|
75
99
|
unreadMessage: (NSString*)messageId
|
|
100
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
101
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
76
102
|
)
|
|
77
103
|
|
|
78
104
|
RCT_EXTERN_METHOD(
|
|
@@ -90,6 +116,10 @@ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
|
90
116
|
removeInboxListener: (NSString*)listenerId
|
|
91
117
|
)
|
|
92
118
|
|
|
119
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
120
|
+
removeAllInboxListeners
|
|
121
|
+
)
|
|
122
|
+
|
|
93
123
|
RCT_EXTERN_METHOD(
|
|
94
124
|
refreshInbox: (RCTPromiseResolveBlock)resolve
|
|
95
125
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
@@ -100,37 +130,176 @@ RCT_EXTERN_METHOD(
|
|
|
100
130
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
101
131
|
)
|
|
102
132
|
|
|
133
|
+
+ (BOOL)requiresMainQueueSetup
|
|
134
|
+
{
|
|
135
|
+
return YES;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@end
|
|
139
|
+
|
|
140
|
+
@interface RCT_EXTERN_MODULE(CourierClientModule, NSObject)
|
|
141
|
+
|
|
103
142
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
104
|
-
|
|
143
|
+
addClient: (NSDictionary*)options
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
147
|
+
removeClient: (NSString*)clientId
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
RCT_EXTERN_METHOD(
|
|
151
|
+
putUserToken: (NSString*)clientId
|
|
152
|
+
withToken: (NSString*)token
|
|
153
|
+
withProvider: (NSString*)provider
|
|
154
|
+
withDevice: (NSDictionary*)device
|
|
155
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
156
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
RCT_EXTERN_METHOD(
|
|
160
|
+
deleteUserToken: (NSString*)clientId
|
|
161
|
+
withToken: (NSString*)token
|
|
162
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
163
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
RCT_EXTERN_METHOD(
|
|
167
|
+
getBrand: (NSString*)clientId
|
|
168
|
+
withBrandId: (NSString*)brandId
|
|
169
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
170
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
105
171
|
)
|
|
106
172
|
|
|
107
173
|
RCT_EXTERN_METHOD(
|
|
108
|
-
|
|
174
|
+
getMessages: (NSString*)clientId
|
|
175
|
+
withPaginationLimit: (double)paginationLimit
|
|
176
|
+
withStartCursor: (NSString*)startCursor
|
|
109
177
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
110
178
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
111
179
|
)
|
|
112
180
|
|
|
113
181
|
RCT_EXTERN_METHOD(
|
|
114
|
-
|
|
182
|
+
getArchivedMessages: (NSString*)clientId
|
|
183
|
+
withPaginationLimit: (double)paginationLimit
|
|
184
|
+
withStartCursor: (NSString*)startCursor
|
|
115
185
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
116
186
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
117
187
|
)
|
|
118
188
|
|
|
119
189
|
RCT_EXTERN_METHOD(
|
|
120
|
-
|
|
190
|
+
getMessageById: (NSString*)clientId
|
|
191
|
+
withMessageId: (NSString*)messageId
|
|
121
192
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
122
193
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
123
194
|
)
|
|
124
195
|
|
|
125
196
|
RCT_EXTERN_METHOD(
|
|
126
|
-
|
|
197
|
+
getUnreadMessageCount: (NSString*)clientId
|
|
198
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
199
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
RCT_EXTERN_METHOD(
|
|
203
|
+
openMessage: (NSString*)clientId
|
|
204
|
+
withMessageId: (NSString*)messageId
|
|
205
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
206
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
RCT_EXTERN_METHOD(
|
|
210
|
+
readMessage: (NSString*)clientId
|
|
211
|
+
withMessageId: (NSString*)messageId
|
|
212
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
213
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
RCT_EXTERN_METHOD(
|
|
217
|
+
unreadMessage: (NSString*)clientId
|
|
218
|
+
withMessageId: (NSString*)messageId
|
|
219
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
220
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
RCT_EXTERN_METHOD(
|
|
224
|
+
clickMessage: (NSString*)clientId
|
|
225
|
+
withMessageId: (NSString*)messageId
|
|
226
|
+
withTrackingId: (NSString*)trackingId
|
|
227
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
228
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
RCT_EXTERN_METHOD(
|
|
232
|
+
archiveMessage: (NSString*)clientId
|
|
233
|
+
withMessageId: (NSString*)messageId
|
|
234
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
235
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
RCT_EXTERN_METHOD(
|
|
239
|
+
readAllMessages: (NSString*)clientId
|
|
240
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
241
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
RCT_EXTERN_METHOD(
|
|
245
|
+
getUserPreferences: (NSString*)clientId
|
|
246
|
+
withPaginationCursor: (NSString*)paginationCursor
|
|
247
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
248
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
RCT_EXTERN_METHOD(
|
|
252
|
+
getUserPreferenceTopic: (NSString*)clientId
|
|
253
|
+
withTopicId: (NSString*)topicId
|
|
254
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
255
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
RCT_EXTERN_METHOD(
|
|
259
|
+
putUserPreferenceTopic: (NSString*)clientId
|
|
260
|
+
withTopicId: (NSString*)topicId
|
|
127
261
|
withStatus: (NSString*)status
|
|
128
|
-
withHasCustomRouting: (BOOL
|
|
129
|
-
withCustomRouting: (NSArray
|
|
262
|
+
withHasCustomRouting: (BOOL)hasCustomRouting
|
|
263
|
+
withCustomRouting: (NSArray<NSString*>*)customRouting
|
|
130
264
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
131
265
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
132
266
|
)
|
|
133
267
|
|
|
268
|
+
RCT_EXTERN_METHOD(
|
|
269
|
+
postTrackingUrl: (NSString*)clientId
|
|
270
|
+
withUrl: (NSString*)url
|
|
271
|
+
withEvent: (NSString*)event
|
|
272
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
273
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
+ (BOOL)requiresMainQueueSetup
|
|
277
|
+
{
|
|
278
|
+
return YES;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@end
|
|
282
|
+
|
|
283
|
+
@interface RCT_EXTERN_MODULE(CourierSystemModule, NSObject)
|
|
284
|
+
|
|
285
|
+
RCT_EXTERN_METHOD(
|
|
286
|
+
openSettingsForApp
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
290
|
+
setIOSForegroundPresentationOptions: (NSDictionary*)params
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
RCT_EXTERN_METHOD(
|
|
294
|
+
getNotificationPermissionStatus: (RCTPromiseResolveBlock)resolve
|
|
295
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
RCT_EXTERN_METHOD(
|
|
299
|
+
requestNotificationPermission: (RCTPromiseResolveBlock)resolve
|
|
300
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
301
|
+
)
|
|
302
|
+
|
|
134
303
|
RCT_EXTERN_METHOD(
|
|
135
304
|
registerPushNotificationClickedOnKilledState
|
|
136
305
|
)
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import Courier_iOS
|
|
2
|
+
|
|
3
|
+
@objc(CourierSharedModule)
|
|
4
|
+
class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
5
|
+
|
|
6
|
+
private var nativeEmitters = [String]()
|
|
7
|
+
private var authenticationListeners: [String: CourierAuthenticationListener] = [:]
|
|
8
|
+
private var inboxListeners: [String: CourierInboxListener] = [:]
|
|
9
|
+
|
|
10
|
+
override func stopObserving() {
|
|
11
|
+
removeAllAuthenticationListeners()
|
|
12
|
+
removeAllInboxListeners()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// MARK: Client
|
|
16
|
+
|
|
17
|
+
@objc func getClient() -> String? {
|
|
18
|
+
|
|
19
|
+
guard let options = Courier.shared.client?.options else {
|
|
20
|
+
return nil
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
do {
|
|
24
|
+
|
|
25
|
+
let dictionary = [
|
|
26
|
+
"jwt": options.jwt as Any,
|
|
27
|
+
"clientKey": options.clientKey as Any,
|
|
28
|
+
"userId": options.userId as Any,
|
|
29
|
+
"connectionId": options.connectionId as Any,
|
|
30
|
+
"tenantId": options.tenantId as Any,
|
|
31
|
+
"showLogs": options.showLogs as Any
|
|
32
|
+
]
|
|
33
|
+
.compactMapValues { $0 }
|
|
34
|
+
|
|
35
|
+
let jsonData = try JSONSerialization.data(
|
|
36
|
+
withJSONObject: dictionary,
|
|
37
|
+
options: .prettyPrinted
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
guard let jsonString = String(data: jsonData, encoding: .utf8) else {
|
|
41
|
+
return nil
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return jsonString
|
|
45
|
+
|
|
46
|
+
} catch {
|
|
47
|
+
return nil
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// MARK: Authentication
|
|
53
|
+
|
|
54
|
+
@objc func getUserId() -> String? {
|
|
55
|
+
return Courier.shared.userId
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@objc func getTenantId() -> String? {
|
|
59
|
+
return Courier.shared.tenantId
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@objc func getIsUserSignedIn() -> String {
|
|
63
|
+
return String(Courier.shared.isUserSignedIn)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@objc(signIn:withClientKey:withUserId:withTenantId:withShowLogs:withResolver:withRejecter:)
|
|
67
|
+
func signIn(accessToken: NSString, clientKey: NSString?, userId: NSString, tenantId: NSString?, showLogs: Bool, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
68
|
+
|
|
69
|
+
let userId = userId as String
|
|
70
|
+
let tenantId = tenantId as? String
|
|
71
|
+
let accessToken = accessToken as String
|
|
72
|
+
let clientKey = clientKey as? String
|
|
73
|
+
|
|
74
|
+
Task {
|
|
75
|
+
|
|
76
|
+
await Courier.shared.signIn(
|
|
77
|
+
userId: userId,
|
|
78
|
+
tenantId: tenantId,
|
|
79
|
+
accessToken: accessToken,
|
|
80
|
+
clientKey: clientKey,
|
|
81
|
+
showLogs: showLogs
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
resolve(nil)
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@objc(signOut:withRejecter:)
|
|
91
|
+
func signOut(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
92
|
+
|
|
93
|
+
Task {
|
|
94
|
+
await Courier.shared.signOut()
|
|
95
|
+
resolve(nil)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@objc(addAuthenticationListener:)
|
|
101
|
+
func addAuthenticationListener(listenerId: String) -> String {
|
|
102
|
+
|
|
103
|
+
nativeEmitters.append(listenerId)
|
|
104
|
+
|
|
105
|
+
let listener = Courier.shared.addAuthenticationListener { [weak self] userId in
|
|
106
|
+
self?.broadcast(
|
|
107
|
+
name: listenerId,
|
|
108
|
+
body: userId
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
authenticationListeners[listenerId] = listener
|
|
113
|
+
|
|
114
|
+
return listenerId
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@objc(removeAuthenticationListener:)
|
|
119
|
+
func removeAuthenticationListener(listenerId: NSString) -> String {
|
|
120
|
+
|
|
121
|
+
let id = listenerId as String
|
|
122
|
+
|
|
123
|
+
let listener = authenticationListeners[id]
|
|
124
|
+
|
|
125
|
+
// Disable the listener
|
|
126
|
+
listener?.remove()
|
|
127
|
+
|
|
128
|
+
// Remove the id from the map
|
|
129
|
+
authenticationListeners.removeValue(forKey: id)
|
|
130
|
+
|
|
131
|
+
return id
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@discardableResult @objc func removeAllAuthenticationListeners() -> String? {
|
|
136
|
+
|
|
137
|
+
for value in authenticationListeners.values {
|
|
138
|
+
value.remove()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
authenticationListeners.removeAll()
|
|
142
|
+
|
|
143
|
+
return nil
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// MARK: Push
|
|
148
|
+
|
|
149
|
+
@objc(getAllTokens:withRejecter:)
|
|
150
|
+
func getAllTokens(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
151
|
+
|
|
152
|
+
Task {
|
|
153
|
+
|
|
154
|
+
let tokens = await Courier.shared.tokens
|
|
155
|
+
resolve(tokens)
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@objc(getToken:withResolver:withRejecter:)
|
|
162
|
+
func getToken(provider: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
163
|
+
|
|
164
|
+
let provider = provider as String
|
|
165
|
+
|
|
166
|
+
Task {
|
|
167
|
+
|
|
168
|
+
let token = await Courier.shared.getToken(for: provider)
|
|
169
|
+
resolve(token)
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@objc(setToken:withToken:withResolver:withRejecter:)
|
|
176
|
+
func setToken(provider: NSString, token: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
177
|
+
|
|
178
|
+
let provider = provider as String
|
|
179
|
+
let token = token as String
|
|
180
|
+
|
|
181
|
+
Task {
|
|
182
|
+
do {
|
|
183
|
+
try await Courier.shared.setToken(
|
|
184
|
+
for: provider,
|
|
185
|
+
token: token
|
|
186
|
+
)
|
|
187
|
+
resolve(nil)
|
|
188
|
+
} catch {
|
|
189
|
+
Rejections.sharedError(reject, error: error)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// MARK: Inbox
|
|
196
|
+
|
|
197
|
+
@objc func getInboxPaginationLimit() -> String {
|
|
198
|
+
return String(describing: Courier.shared.inboxPaginationLimit)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@objc(setInboxPaginationLimit:)
|
|
202
|
+
func setInboxPaginationLimit(limit: Double) -> String {
|
|
203
|
+
Courier.shared.inboxPaginationLimit = Int(limit)
|
|
204
|
+
return String(describing: Courier.shared.inboxPaginationLimit)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
@objc(openMessage:withResolver:withRejecter:)
|
|
208
|
+
func openMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
209
|
+
|
|
210
|
+
let id = messageId as String
|
|
211
|
+
|
|
212
|
+
Task {
|
|
213
|
+
do {
|
|
214
|
+
try await Courier.shared.openMessage(id)
|
|
215
|
+
resolve(nil)
|
|
216
|
+
} catch {
|
|
217
|
+
Rejections.sharedError(reject, error: error)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@objc(archiveMessage:withResolver:withRejecter:)
|
|
224
|
+
func archiveMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
225
|
+
|
|
226
|
+
let id = messageId as String
|
|
227
|
+
|
|
228
|
+
Task {
|
|
229
|
+
do {
|
|
230
|
+
try await Courier.shared.archiveMessage(id)
|
|
231
|
+
resolve(nil)
|
|
232
|
+
} catch {
|
|
233
|
+
Rejections.sharedError(reject, error: error)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@objc(clickMessage:withResolver:withRejecter:)
|
|
240
|
+
func clickMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
241
|
+
|
|
242
|
+
let id = messageId as String
|
|
243
|
+
|
|
244
|
+
Task {
|
|
245
|
+
do {
|
|
246
|
+
try await Courier.shared.clickMessage(id)
|
|
247
|
+
resolve(nil)
|
|
248
|
+
} catch {
|
|
249
|
+
Rejections.sharedError(reject, error: error)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@objc(readMessage:withResolver:withRejecter:)
|
|
256
|
+
func readMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
257
|
+
|
|
258
|
+
let id = messageId as String
|
|
259
|
+
|
|
260
|
+
Task {
|
|
261
|
+
do {
|
|
262
|
+
try await Courier.shared.readMessage(id)
|
|
263
|
+
resolve(nil)
|
|
264
|
+
} catch {
|
|
265
|
+
Rejections.sharedError(reject, error: error)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@objc(unreadMessage:withResolver:withRejecter:)
|
|
272
|
+
func unreadMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
273
|
+
|
|
274
|
+
let id = messageId as String
|
|
275
|
+
|
|
276
|
+
Task {
|
|
277
|
+
do {
|
|
278
|
+
try await Courier.shared.unreadMessage(id)
|
|
279
|
+
resolve(nil)
|
|
280
|
+
} catch {
|
|
281
|
+
Rejections.sharedError(reject, error: error)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@objc(readAllInboxMessages:withRejecter:)
|
|
288
|
+
func readAllInboxMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
289
|
+
|
|
290
|
+
Task {
|
|
291
|
+
do {
|
|
292
|
+
try await Courier.shared.readAllInboxMessages()
|
|
293
|
+
resolve(nil)
|
|
294
|
+
} catch {
|
|
295
|
+
Rejections.sharedError(reject, error: error)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@objc(addInboxListener: withErrorId: withMessagesId:)
|
|
302
|
+
func addInboxListener(loadingId: String, errorId: String, messagesId: String) -> String {
|
|
303
|
+
|
|
304
|
+
// Add the events
|
|
305
|
+
nativeEmitters.append(contentsOf: [loadingId, errorId, messagesId])
|
|
306
|
+
|
|
307
|
+
// Create the new listener
|
|
308
|
+
let listener = Courier.shared.addInboxListener(
|
|
309
|
+
onInitialLoad: { [weak self] in
|
|
310
|
+
self?.broadcast(
|
|
311
|
+
name: loadingId,
|
|
312
|
+
body: nil
|
|
313
|
+
)
|
|
314
|
+
},
|
|
315
|
+
onError: { [weak self] error in
|
|
316
|
+
self?.broadcast(
|
|
317
|
+
name: errorId,
|
|
318
|
+
body: String(describing: error)
|
|
319
|
+
)
|
|
320
|
+
},
|
|
321
|
+
onMessagesChanged: { [weak self] messages, unreadMessageCount, totalMessageCount, canPaginate in
|
|
322
|
+
|
|
323
|
+
do {
|
|
324
|
+
|
|
325
|
+
let json: [String: Any] = [
|
|
326
|
+
"messages": try messages.map { try $0.toJson() ?? "" },
|
|
327
|
+
"unreadMessageCount": unreadMessageCount,
|
|
328
|
+
"totalMessageCount": totalMessageCount,
|
|
329
|
+
"canPaginate": canPaginate
|
|
330
|
+
]
|
|
331
|
+
|
|
332
|
+
self?.broadcast(
|
|
333
|
+
name: messagesId,
|
|
334
|
+
body: json
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
} catch {
|
|
338
|
+
|
|
339
|
+
Courier.shared.client?.error(error.localizedDescription)
|
|
340
|
+
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
}
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
let id = UUID().uuidString
|
|
347
|
+
inboxListeners[id] = listener
|
|
348
|
+
|
|
349
|
+
return id
|
|
350
|
+
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
@objc(removeInboxListener:)
|
|
354
|
+
func removeInboxListener(listenerId: NSString) -> String {
|
|
355
|
+
|
|
356
|
+
let id = listenerId as String
|
|
357
|
+
|
|
358
|
+
let listener = inboxListeners[id]
|
|
359
|
+
|
|
360
|
+
// Disable the listener
|
|
361
|
+
listener?.remove()
|
|
362
|
+
|
|
363
|
+
// Remove the id from the map
|
|
364
|
+
inboxListeners.removeValue(forKey: id)
|
|
365
|
+
|
|
366
|
+
return id
|
|
367
|
+
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
@discardableResult @objc func removeAllInboxListeners() -> String? {
|
|
371
|
+
|
|
372
|
+
for value in inboxListeners.values {
|
|
373
|
+
value.remove()
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
inboxListeners.removeAll()
|
|
377
|
+
|
|
378
|
+
return nil
|
|
379
|
+
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
@objc(refreshInbox: withRejecter:)
|
|
383
|
+
func refreshInbox(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
384
|
+
|
|
385
|
+
Task {
|
|
386
|
+
await Courier.shared.refreshInbox()
|
|
387
|
+
resolve(nil)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
@objc(fetchNextPageOfMessages: withRejecter:)
|
|
393
|
+
func fetchNextPageOfMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
394
|
+
|
|
395
|
+
Task {
|
|
396
|
+
|
|
397
|
+
do {
|
|
398
|
+
let messages = try await Courier.shared.fetchNextInboxPage()
|
|
399
|
+
resolve(try messages.map { try $0.toJson() ?? "" })
|
|
400
|
+
} catch {
|
|
401
|
+
Rejections.sharedError(reject, error: error)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
override func supportedEvents() -> [String]! {
|
|
409
|
+
return nativeEmitters
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
}
|