@trycourier/courier-react-native 3.2.1 → 4.0.4
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 +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/CourierReactNativePackage.kt +9 -3
- package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +321 -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 +18 -35
- package/ios/CourierReactNativeEventEmitter.swift +25 -0
- package/ios/CourierReactNativeModule.m +192 -23
- package/ios/CourierSharedModule.swift +425 -0
- package/ios/CourierSystemModule.swift +147 -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
package/lib/module/index.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import { Platform
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
2
|
|
|
3
3
|
// Imports
|
|
4
4
|
import { CourierInboxListener } from './models/CourierInboxListener';
|
|
5
5
|
import { CourierPushListener } from './models/CourierPushListener';
|
|
6
6
|
import { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
|
|
7
|
+
import { Modules } from './Modules';
|
|
8
|
+
import Broadcaster from './Broadcaster';
|
|
9
|
+
import { CourierClient } from './client/CourierClient';
|
|
7
10
|
import { Events, Utils } from './utils';
|
|
11
|
+
export { CourierClient } from './client/CourierClient';
|
|
12
|
+
export { BrandClient } from './client/BrandClient';
|
|
13
|
+
export { CourierBrandResponse } from './models/CourierBrand';
|
|
14
|
+
export { CourierDevice } from './models/CourierDevice';
|
|
8
15
|
|
|
9
16
|
// Exports
|
|
10
17
|
export { CourierInboxView } from './views/CourierInboxView';
|
|
11
18
|
export { CourierPreferencesView } from './views/CourierPreferencesView';
|
|
12
19
|
export { CourierInboxListener } from './models/CourierInboxListener';
|
|
13
20
|
export { CourierPushListener } from './models/CourierPushListener';
|
|
21
|
+
export { CourierUserPreferencesTopic } from './models/CourierUserPreferences';
|
|
14
22
|
export { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
|
|
15
|
-
export { CourierUserPreferencesChannel } from './models/
|
|
16
|
-
export { CourierUserPreferencesStatus } from './models/
|
|
23
|
+
export { CourierUserPreferencesChannel } from './models/CourierUserPreferences';
|
|
24
|
+
export { CourierUserPreferencesStatus } from './models/CourierUserPreferences';
|
|
25
|
+
export { CourierTrackingEvent } from './models/CourierTrackingEvent';
|
|
17
26
|
export { CourierPushProvider } from './models/CourierPushProvider';
|
|
18
27
|
export { CourierFont } from './models/CourierFont';
|
|
19
28
|
export { CourierButton } from './models/CourierButton';
|
|
@@ -22,25 +31,26 @@ export { iOS_CourierCell } from './models/iOS_CourierCell';
|
|
|
22
31
|
export { iOS_CourierSheet } from './models/iOS_CourierSheet';
|
|
23
32
|
export { CourierInboxButtonStyle, CourierInboxTextStyle, CourierInboxUnreadIndicatorStyle, CourierInboxTheme } from './models/CourierInboxTheme';
|
|
24
33
|
export { CourierPreferencesTheme, CourierPreferencesMode, CourierPreferencesChannel } from './models/CourierPreferencesTheme';
|
|
25
|
-
const LINKING_ERROR = `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
26
|
-
ios: "- You have run 'pod install'\n",
|
|
27
|
-
default: ''
|
|
28
|
-
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
29
|
-
const CourierReactNativeModules = NativeModules.CourierReactNativeModule ? NativeModules.CourierReactNativeModule : new Proxy({}, {
|
|
30
|
-
get() {
|
|
31
|
-
throw new Error(LINKING_ERROR);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
const CourierEventEmitter = new NativeEventEmitter(NativeModules.CourierReactNativeModule);
|
|
35
34
|
class Courier {
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// Singleton
|
|
36
|
+
|
|
37
|
+
// Listeners
|
|
38
|
+
authenticationListeners = new Map();
|
|
38
39
|
inboxListeners = new Map();
|
|
40
|
+
pushListeners = new Map();
|
|
41
|
+
|
|
42
|
+
// Broadcasting
|
|
43
|
+
systemBroadcaster = new Broadcaster(Modules.System);
|
|
44
|
+
sharedBroadcaster = new Broadcaster(Modules.Shared);
|
|
39
45
|
constructor() {
|
|
40
46
|
// Sets the initial SDK values
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
// will show all foreground notification styles in iOS
|
|
48
|
+
Courier.setIOSForegroundPresentationOptions({
|
|
49
|
+
options: ['sound', 'badge', 'list', 'banner']
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Attach the push notification listeners
|
|
53
|
+
this.attachPushNotificationListeners();
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
// Returns the public shared instance
|
|
@@ -50,222 +60,408 @@ class Courier {
|
|
|
50
60
|
}
|
|
51
61
|
return this._sharedInstance;
|
|
52
62
|
}
|
|
53
|
-
async setDefaults() {
|
|
54
|
-
this.setIsDebugging(__DEV__);
|
|
55
|
-
this.iOSForegroundPresentationOptions({
|
|
56
|
-
options: ['sound', 'badge', 'list', 'banner']
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*/
|
|
64
|
-
setIsDebugging(isDebugging) {
|
|
65
|
-
var _this$debugListener;
|
|
66
|
-
// Remove the existing listener if needed
|
|
67
|
-
(_this$debugListener = this.debugListener) === null || _this$debugListener === void 0 ? void 0 : _this$debugListener.remove();
|
|
64
|
+
// Debugging
|
|
65
|
+
|
|
66
|
+
isDebugging = __DEV__;
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (isDebugging) {
|
|
72
|
-
|
|
73
|
-
console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
|
|
74
|
-
});
|
|
68
|
+
// Show a log to the console
|
|
69
|
+
static log(message) {
|
|
70
|
+
if (Courier.shared.isDebugging) {
|
|
71
|
+
console.log(message);
|
|
75
72
|
}
|
|
76
|
-
CourierReactNativeModules.setDebugMode(isDebugging);
|
|
77
|
-
this._isDebugging = isDebugging;
|
|
78
|
-
return this._isDebugging;
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
// System (Static)
|
|
76
|
+
|
|
77
|
+
attachPushNotificationListeners() {
|
|
78
|
+
var _this$pushNotificatio, _this$pushNotificatio2;
|
|
79
|
+
// Remove existing listeners
|
|
80
|
+
// Only allows one subscription to be active
|
|
81
|
+
(_this$pushNotificatio = this.pushNotificationClickedEmitter) === null || _this$pushNotificatio === void 0 ? void 0 : _this$pushNotificatio.remove();
|
|
82
|
+
(_this$pushNotificatio2 = this.pushNotificationDeliveredEmitter) === null || _this$pushNotificatio2 === void 0 ? void 0 : _this$pushNotificatio2.remove();
|
|
83
|
+
|
|
84
|
+
// When a push notification is clicked
|
|
85
|
+
this.pushNotificationClickedEmitter = this.systemBroadcaster.addListener(Events.Push.CLICKED, event => {
|
|
86
|
+
try {
|
|
87
|
+
const message = JSON.parse(event);
|
|
88
|
+
this.pushListeners.forEach(listener => {
|
|
89
|
+
if (listener.onPushNotificationClicked) {
|
|
90
|
+
listener.onPushNotificationClicked(message);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
} catch (error) {
|
|
94
|
+
Courier.log(`Error parsing push notification clicked event: ${error}`);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// When a push notification is delivered
|
|
99
|
+
this.pushNotificationDeliveredEmitter = this.systemBroadcaster.addListener(Events.Push.DELIVERED, event => {
|
|
100
|
+
try {
|
|
101
|
+
const message = JSON.parse(event);
|
|
102
|
+
this.pushListeners.forEach(listener => {
|
|
103
|
+
if (listener.onPushNotificationDelivered) {
|
|
104
|
+
listener.onPushNotificationDelivered(message);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
} catch (error) {
|
|
108
|
+
Courier.log(`Error parsing push notification delivered event: ${error}`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
86
111
|
}
|
|
87
112
|
|
|
88
113
|
/**
|
|
89
|
-
* Sets the
|
|
114
|
+
* Sets the iOS foreground presentation options for push notifications.
|
|
115
|
+
* This method only works on iOS devices.
|
|
116
|
+
* @param props An object containing an array of iOSForegroundPresentationOptions.
|
|
117
|
+
* @returns A string indicating the result of the operation. Returns 'unsupported' on non-iOS platforms.
|
|
90
118
|
*/
|
|
91
|
-
|
|
119
|
+
static setIOSForegroundPresentationOptions(props) {
|
|
92
120
|
// Only works on iOS
|
|
93
121
|
if (Platform.OS !== 'ios') return 'unsupported';
|
|
94
122
|
const normalizedParams = Array.from(new Set(props.options));
|
|
95
|
-
return
|
|
123
|
+
return Modules.System.setIOSForegroundPresentationOptions({
|
|
96
124
|
options: normalizedParams
|
|
97
125
|
});
|
|
98
126
|
}
|
|
99
127
|
|
|
100
128
|
/**
|
|
101
|
-
*
|
|
129
|
+
* Retrieves the current notification permission status.
|
|
130
|
+
* @returns A Promise that resolves to a string representing the current notification permission status.
|
|
102
131
|
*/
|
|
103
|
-
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
getTokenForProvider(props) {
|
|
107
|
-
return CourierReactNativeModules.getToken(props.provider);
|
|
132
|
+
static async getNotificationPermissionStatus() {
|
|
133
|
+
return await Modules.System.getNotificationPermissionStatus();
|
|
108
134
|
}
|
|
109
135
|
|
|
110
136
|
/**
|
|
111
|
-
*
|
|
137
|
+
* Requests permission to send push notifications to the user.
|
|
138
|
+
* @returns A Promise that resolves to a string indicating the result of the permission request.
|
|
112
139
|
*/
|
|
113
|
-
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
setTokenForProvider(props) {
|
|
117
|
-
return CourierReactNativeModules.setToken(props.provider, props.token);
|
|
140
|
+
static async requestNotificationPermission() {
|
|
141
|
+
return await Modules.System.requestNotificationPermission();
|
|
118
142
|
}
|
|
119
143
|
|
|
120
144
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
145
|
+
* Opens the settings page for the current app.
|
|
146
|
+
* This can be used to direct users to enable notifications if they've previously denied permission.
|
|
123
147
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
static openSettingsForApp() {
|
|
149
|
+
Modules.System.openSettingsForApp();
|
|
126
150
|
}
|
|
127
151
|
|
|
128
|
-
|
|
129
|
-
* Requests notification permissions
|
|
130
|
-
* This will show a dialog asking the user for permission
|
|
131
|
-
* Only supported on iOS
|
|
132
|
-
*/
|
|
133
|
-
requestNotificationPermission() {
|
|
134
|
-
return CourierReactNativeModules.requestNotificationPermission();
|
|
135
|
-
}
|
|
152
|
+
// Client
|
|
136
153
|
|
|
137
154
|
/**
|
|
138
|
-
*
|
|
155
|
+
* Gets the current CourierClient instance.
|
|
156
|
+
* @returns {CourierClient | undefined} The current CourierClient instance, or undefined if not initialized.
|
|
139
157
|
*/
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
props.onPushNotificationClicked(JSON.parse(event));
|
|
146
|
-
} catch (error) {
|
|
147
|
-
console.log(error);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
158
|
+
get client() {
|
|
159
|
+
const client = Modules.Shared.getClient() ?? undefined;
|
|
160
|
+
if (!client) {
|
|
161
|
+
return undefined;
|
|
150
162
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// When listener is registered
|
|
162
|
-
// Attempt to fetch the last message that was clicked
|
|
163
|
-
// This is needed for when the app is killed and the
|
|
164
|
-
// user launched the app by clicking on a notifications
|
|
165
|
-
CourierReactNativeModules.registerPushNotificationClickedOnKilledState();
|
|
166
|
-
return pushListener;
|
|
163
|
+
const clientObj = JSON.parse(client);
|
|
164
|
+
return new CourierClient({
|
|
165
|
+
userId: clientObj.userId,
|
|
166
|
+
showLogs: clientObj.showLogs,
|
|
167
|
+
jwt: clientObj.jwt,
|
|
168
|
+
clientKey: clientObj.clientKey,
|
|
169
|
+
connectionId: clientObj.connectionId,
|
|
170
|
+
tenantId: clientObj.tenantId
|
|
171
|
+
});
|
|
167
172
|
}
|
|
168
173
|
|
|
174
|
+
// Authentication
|
|
175
|
+
|
|
169
176
|
/**
|
|
170
|
-
* Gets the user
|
|
171
|
-
*
|
|
177
|
+
* Gets the current user ID.
|
|
178
|
+
* @returns {string | undefined} The current user ID, or undefined if not set.
|
|
172
179
|
*/
|
|
173
180
|
get userId() {
|
|
174
|
-
return
|
|
181
|
+
return Modules.Shared.getUserId() ?? undefined;
|
|
175
182
|
}
|
|
176
183
|
|
|
177
184
|
/**
|
|
178
|
-
* Gets the tenant
|
|
185
|
+
* Gets the current tenant ID.
|
|
186
|
+
* @returns {string | undefined} The current tenant ID, or undefined if not set.
|
|
179
187
|
*/
|
|
180
188
|
get tenantId() {
|
|
181
|
-
return
|
|
189
|
+
return Modules.Shared.getTenantId() ?? undefined;
|
|
182
190
|
}
|
|
183
191
|
|
|
184
192
|
/**
|
|
185
|
-
*
|
|
193
|
+
* Checks if a user is currently signed in.
|
|
194
|
+
* @returns {boolean} True if a user is signed in, false otherwise.
|
|
186
195
|
*/
|
|
187
|
-
|
|
188
|
-
|
|
196
|
+
get isUserSignedIn() {
|
|
197
|
+
const isSignedIn = Modules.Shared.getIsUserSignedIn() ?? 'false';
|
|
198
|
+
return isSignedIn.toLowerCase() === 'true';
|
|
189
199
|
}
|
|
190
200
|
|
|
191
201
|
/**
|
|
192
|
-
*
|
|
202
|
+
* Signs out the current user.
|
|
203
|
+
* @returns {Promise<void>} A promise that resolves when the sign out process is complete.
|
|
193
204
|
*/
|
|
194
|
-
signOut() {
|
|
195
|
-
return
|
|
205
|
+
async signOut() {
|
|
206
|
+
return await Modules.Shared.signOut();
|
|
196
207
|
}
|
|
197
208
|
|
|
198
209
|
/**
|
|
199
|
-
*
|
|
210
|
+
* Signs in a user with the provided credentials.
|
|
211
|
+
* @param {Object} props - The sign-in properties.
|
|
212
|
+
* @param {string} props.accessToken - The access token for authentication.
|
|
213
|
+
* @param {string} [props.clientKey] - The client key (optional).
|
|
214
|
+
* @param {string} props.userId - The user ID.
|
|
215
|
+
* @param {string} [props.tenantId] - The tenant ID (optional).
|
|
216
|
+
* @param {boolean} [props.showLogs] - Whether to show debug logs (defaults to __DEV__).
|
|
217
|
+
* @returns {Promise<void>} A promise that resolves when the sign-in process is complete.
|
|
200
218
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
219
|
+
async signIn(props) {
|
|
220
|
+
this.isDebugging = props.showLogs ?? __DEV__;
|
|
221
|
+
return await Modules.Shared.signIn(props.accessToken, props.clientKey ?? null, props.userId, props.tenantId ?? null, this.isDebugging);
|
|
222
|
+
}
|
|
204
223
|
|
|
205
|
-
|
|
206
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Adds an authentication listener to monitor user changes.
|
|
226
|
+
* @param {Object} props - The listener properties.
|
|
227
|
+
* @param {function} props.onUserChanged - Callback function triggered when the user changes.
|
|
228
|
+
* @returns {CourierAuthenticationListener} The created authentication listener.
|
|
229
|
+
*/
|
|
230
|
+
addAuthenticationListener(props) {
|
|
231
|
+
// Create a listener
|
|
232
|
+
const listenerId = `authentication_${Utils.generateUUID()}`;
|
|
233
|
+
const id = Modules.Shared.addAuthenticationListener(listenerId);
|
|
207
234
|
|
|
208
|
-
//
|
|
235
|
+
// Attach the listener
|
|
209
236
|
const listener = new CourierAuthenticationListener(id);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
listener.onUserChanged = Utils.addEventListener(authId, CourierEventEmitter, event => props.onUserChanged(event));
|
|
213
|
-
|
|
214
|
-
// Add listener to manager
|
|
215
|
-
this.authListeners.set(id, listener);
|
|
237
|
+
listener.onUserChanged = this.sharedBroadcaster.addListener(listenerId, event => props.onUserChanged(event));
|
|
238
|
+
this.authenticationListeners.set(id, listener);
|
|
216
239
|
return listener;
|
|
217
240
|
}
|
|
218
241
|
|
|
219
242
|
/**
|
|
220
|
-
* Removes
|
|
243
|
+
* Removes a specific authentication listener.
|
|
244
|
+
* @param {Object} props - The removal properties.
|
|
245
|
+
* @param {string} props.listenerId - The ID of the listener to remove.
|
|
246
|
+
* @returns {string} The ID of the removed listener.
|
|
221
247
|
*/
|
|
222
248
|
removeAuthenticationListener(props) {
|
|
223
249
|
// Remove the native listener
|
|
224
|
-
|
|
250
|
+
Modules.Shared.removeAuthenticationListener(props.listenerId);
|
|
225
251
|
|
|
226
252
|
// Remove the listener
|
|
227
|
-
if (this.
|
|
253
|
+
if (this.authenticationListeners.has(props.listenerId)) {
|
|
228
254
|
var _listener$onUserChang;
|
|
229
|
-
|
|
230
|
-
const listener = this.authListeners.get(props.listenerId);
|
|
255
|
+
const listener = this.authenticationListeners.get(props.listenerId);
|
|
231
256
|
listener === null || listener === void 0 || (_listener$onUserChang = listener.onUserChanged) === null || _listener$onUserChang === void 0 ? void 0 : _listener$onUserChang.remove();
|
|
257
|
+
this.authenticationListeners.delete(props.listenerId);
|
|
258
|
+
}
|
|
259
|
+
return props.listenerId;
|
|
260
|
+
}
|
|
232
261
|
|
|
233
|
-
|
|
234
|
-
|
|
262
|
+
/**
|
|
263
|
+
* Removes all authentication listeners.
|
|
264
|
+
* This method clears all registered authentication listeners, both native and JavaScript.
|
|
265
|
+
*/
|
|
266
|
+
removeAllAuthenticationListeners() {
|
|
267
|
+
// Remove all native listeners
|
|
268
|
+
Modules.Shared.removeAllAuthenticationListeners();
|
|
269
|
+
|
|
270
|
+
// Iterate through all authentication listeners
|
|
271
|
+
this.authenticationListeners.forEach(listener => {
|
|
272
|
+
var _listener$onUserChang2;
|
|
273
|
+
(_listener$onUserChang2 = listener.onUserChanged) === null || _listener$onUserChang2 === void 0 ? void 0 : _listener$onUserChang2.remove();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Clear the map of authentication listeners
|
|
277
|
+
this.authenticationListeners.clear();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Push
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Retrieves all push notification tokens.
|
|
284
|
+
* @returns {Promise<Map<string, string>>} A promise that resolves to a Map of provider keys to tokens.
|
|
285
|
+
*/
|
|
286
|
+
async getAllTokens() {
|
|
287
|
+
const tokensObject = await Modules.Shared.getAllTokens();
|
|
288
|
+
const tokensMap = new Map();
|
|
289
|
+
for (const [key, value] of Object.entries(tokensObject)) {
|
|
290
|
+
tokensMap.set(key, value);
|
|
291
|
+
}
|
|
292
|
+
return tokensMap;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Retrieves the push notification token for a specific key.
|
|
297
|
+
* @param {Object} props - The properties object.
|
|
298
|
+
* @param {string} props.key - The key associated with the token.
|
|
299
|
+
* @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
|
|
300
|
+
*/
|
|
301
|
+
async getToken(props) {
|
|
302
|
+
return await Modules.Shared.getToken(props.key);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Retrieves the push notification token for a specific provider.
|
|
307
|
+
* @param {Object} props - The properties object.
|
|
308
|
+
* @param {CourierPushProvider} props.provider - The push notification provider.
|
|
309
|
+
* @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
|
|
310
|
+
*/
|
|
311
|
+
async getTokenForProvider(props) {
|
|
312
|
+
return await Modules.Shared.getToken(props.provider);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Sets the push notification token for a specific key.
|
|
317
|
+
* @param {Object} props - The properties object.
|
|
318
|
+
* @param {string} props.key - The key to associate with the token.
|
|
319
|
+
* @param {string} props.token - The push notification token.
|
|
320
|
+
* @returns {Promise<void>} A promise that resolves when the token is set.
|
|
321
|
+
*/
|
|
322
|
+
async setToken(props) {
|
|
323
|
+
return await Modules.Shared.setToken(props.key, props.token);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Sets the push notification token for a specific provider.
|
|
328
|
+
* @param {Object} props - The properties object.
|
|
329
|
+
* @param {CourierPushProvider} props.provider - The push notification provider.
|
|
330
|
+
* @param {string} props.token - The push notification token.
|
|
331
|
+
* @returns {Promise<void>} A promise that resolves when the token is set.
|
|
332
|
+
*/
|
|
333
|
+
async setTokenForProvider(props) {
|
|
334
|
+
return await Modules.Shared.setToken(props.provider, props.token);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Adds a push notification listener.
|
|
339
|
+
* @param {Object} props - The properties object.
|
|
340
|
+
* @param {function} [props.onPushNotificationClicked] - Callback function triggered when a push notification is clicked.
|
|
341
|
+
* @param {function} [props.onPushNotificationDelivered] - Callback function triggered when a push notification is delivered.
|
|
342
|
+
* @returns {CourierPushListener} The created push notification listener.
|
|
343
|
+
*/
|
|
344
|
+
addPushNotificationListener(props) {
|
|
345
|
+
const listenerId = `push_${Utils.generateUUID()}`;
|
|
346
|
+
const pushListener = new CourierPushListener(listenerId, props.onPushNotificationClicked, props.onPushNotificationDelivered);
|
|
347
|
+
|
|
348
|
+
// Cache the listener
|
|
349
|
+
this.pushListeners.set(listenerId, pushListener);
|
|
350
|
+
|
|
351
|
+
// When listener is registered
|
|
352
|
+
// Attempt to fetch the last message that was clicked
|
|
353
|
+
// This is needed for when the app is killed and the
|
|
354
|
+
// user launched the app by clicking on a notifications
|
|
355
|
+
Modules.System.registerPushNotificationClickedOnKilledState();
|
|
356
|
+
return pushListener;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Removes a specific push notification listener.
|
|
361
|
+
* @param {Object} props - The properties object.
|
|
362
|
+
* @param {string} props.listenerId - The ID of the listener to remove.
|
|
363
|
+
* @returns {string} The ID of the removed listener.
|
|
364
|
+
*/
|
|
365
|
+
removePushNotificationListener(props) {
|
|
366
|
+
if (this.pushListeners.has(props.listenerId)) {
|
|
367
|
+
this.pushListeners.delete(props.listenerId);
|
|
235
368
|
}
|
|
236
369
|
return props.listenerId;
|
|
237
370
|
}
|
|
238
371
|
|
|
239
372
|
/**
|
|
240
|
-
*
|
|
373
|
+
* Removes all push notification listeners.
|
|
374
|
+
*/
|
|
375
|
+
removeAllPushNotificationListeners() {
|
|
376
|
+
this.pushListeners.forEach(listener => {
|
|
377
|
+
listener.remove();
|
|
378
|
+
});
|
|
379
|
+
this.pushListeners.clear();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Inbox
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Gets the current pagination limit for inbox messages.
|
|
386
|
+
* @returns {number} The current pagination limit.
|
|
387
|
+
*/
|
|
388
|
+
get inboxPaginationLimit() {
|
|
389
|
+
return Modules.Shared.getInboxPaginationLimit();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Sets the pagination limit for inbox messages.
|
|
394
|
+
* @param {number} limit - The new pagination limit to set.
|
|
241
395
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
396
|
+
set inboxPaginationLimit(limit) {
|
|
397
|
+
Modules.Shared.setInboxPaginationLimit(limit);
|
|
244
398
|
}
|
|
245
399
|
|
|
246
400
|
/**
|
|
247
|
-
*
|
|
401
|
+
* Opens a specific message in the inbox.
|
|
402
|
+
* @param {Object} props - The properties object.
|
|
403
|
+
* @param {string} props.messageId - The ID of the message to open.
|
|
404
|
+
* @returns {Promise<void>} A promise that resolves when the message is opened.
|
|
248
405
|
*/
|
|
249
|
-
|
|
250
|
-
return
|
|
406
|
+
async openMessage(props) {
|
|
407
|
+
return await Modules.Shared.openMessage(props.messageId);
|
|
251
408
|
}
|
|
252
409
|
|
|
253
410
|
/**
|
|
254
|
-
*
|
|
411
|
+
* Registers a click event for a specific message in the inbox.
|
|
412
|
+
* @param {Object} props - The properties object.
|
|
413
|
+
* @param {string} props.messageId - The ID of the message that was clicked.
|
|
414
|
+
* @returns {Promise<void>} A promise that resolves when the click is registered.
|
|
255
415
|
*/
|
|
256
|
-
|
|
257
|
-
return
|
|
416
|
+
async clickMessage(props) {
|
|
417
|
+
return await Modules.Shared.clickMessage(props.messageId);
|
|
258
418
|
}
|
|
259
419
|
|
|
260
420
|
/**
|
|
261
|
-
*
|
|
421
|
+
* Marks a specific message as read in the inbox.
|
|
422
|
+
* @param {Object} props - The properties object.
|
|
423
|
+
* @param {string} props.messageId - The ID of the message to mark as read.
|
|
424
|
+
* @returns {Promise<void>} A promise that resolves when the message is marked as read.
|
|
262
425
|
*/
|
|
263
|
-
|
|
264
|
-
return
|
|
426
|
+
async readMessage(props) {
|
|
427
|
+
return await Modules.Shared.readMessage(props.messageId);
|
|
265
428
|
}
|
|
266
429
|
|
|
267
430
|
/**
|
|
268
|
-
*
|
|
431
|
+
* Marks a specific message as unread in the inbox.
|
|
432
|
+
* @param {Object} props - The properties object.
|
|
433
|
+
* @param {string} props.messageId - The ID of the message to mark as unread.
|
|
434
|
+
* @returns {Promise<void>} A promise that resolves when the message is marked as unread.
|
|
435
|
+
*/
|
|
436
|
+
async unreadMessage(props) {
|
|
437
|
+
return await Modules.Shared.unreadMessage(props.messageId);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Archives a specific message in the inbox.
|
|
442
|
+
* @param {Object} props - The properties object.
|
|
443
|
+
* @param {string} props.messageId - The ID of the message to archive.
|
|
444
|
+
* @returns {Promise<void>} A promise that resolves when the message is archived.
|
|
445
|
+
*/
|
|
446
|
+
async archiveMessage(props) {
|
|
447
|
+
return await Modules.Shared.archiveMessage(props.messageId);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Marks all messages in the inbox as read.
|
|
452
|
+
* @returns {Promise<void>} A promise that resolves when all messages are marked as read.
|
|
453
|
+
*/
|
|
454
|
+
async readAllInboxMessages() {
|
|
455
|
+
return await Modules.Shared.readAllInboxMessages();
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Adds a listener for inbox changes.
|
|
460
|
+
* @param {Object} props - The properties object.
|
|
461
|
+
* @param {Function} [props.onInitialLoad] - Callback function called when the inbox is initially loaded.
|
|
462
|
+
* @param {Function} [props.onError] - Callback function called when an error occurs. Receives the error message as a parameter.
|
|
463
|
+
* @param {Function} [props.onMessagesChanged] - Callback function called when messages change. Receives updated messages, unread count, total count, and pagination status.
|
|
464
|
+
* @returns {CourierInboxListener} A listener object that can be used to remove the listener later.
|
|
269
465
|
*/
|
|
270
466
|
addInboxListener(props) {
|
|
271
467
|
const listenerIds = {
|
|
@@ -275,21 +471,31 @@ class Courier {
|
|
|
275
471
|
};
|
|
276
472
|
|
|
277
473
|
// Set the listener id
|
|
278
|
-
const id =
|
|
474
|
+
const id = Modules.Shared.addInboxListener(listenerIds.loading, listenerIds.error, listenerIds.messages);
|
|
279
475
|
|
|
280
476
|
// Create the initial listeners
|
|
281
477
|
const listener = new CourierInboxListener(id);
|
|
282
|
-
listener.onInitialLoad =
|
|
478
|
+
listener.onInitialLoad = this.sharedBroadcaster.addListener(listenerIds.loading, _ => {
|
|
283
479
|
var _props$onInitialLoad;
|
|
284
480
|
(_props$onInitialLoad = props.onInitialLoad) === null || _props$onInitialLoad === void 0 ? void 0 : _props$onInitialLoad.call(props);
|
|
285
481
|
});
|
|
286
|
-
listener.onError =
|
|
482
|
+
listener.onError = this.sharedBroadcaster.addListener(listenerIds.error, event => {
|
|
287
483
|
var _props$onError;
|
|
288
484
|
(_props$onError = props.onError) === null || _props$onError === void 0 ? void 0 : _props$onError.call(props, event);
|
|
289
485
|
});
|
|
290
|
-
listener.onMessagesChanged =
|
|
486
|
+
listener.onMessagesChanged = this.sharedBroadcaster.addListener(listenerIds.messages, event => {
|
|
291
487
|
var _props$onMessagesChan;
|
|
292
|
-
|
|
488
|
+
// Convert JSON strings to InboxMessage objects
|
|
489
|
+
const convertedMessages = event.messages.map(jsonString => {
|
|
490
|
+
try {
|
|
491
|
+
const parsedMessage = JSON.parse(jsonString);
|
|
492
|
+
return parsedMessage;
|
|
493
|
+
} catch (error) {
|
|
494
|
+
Courier.log(`Error parsing message: ${error}`);
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
}).filter(message => message !== null);
|
|
498
|
+
(_props$onMessagesChan = props.onMessagesChanged) === null || _props$onMessagesChan === void 0 ? void 0 : _props$onMessagesChan.call(props, convertedMessages, event.unreadMessageCount, event.totalMessageCount, event.canPaginate);
|
|
293
499
|
});
|
|
294
500
|
|
|
295
501
|
// Add listener to manager
|
|
@@ -298,11 +504,14 @@ class Courier {
|
|
|
298
504
|
}
|
|
299
505
|
|
|
300
506
|
/**
|
|
301
|
-
* Removes
|
|
507
|
+
* Removes a specific inbox listener.
|
|
508
|
+
* @param {Object} props - The properties object.
|
|
509
|
+
* @param {string} props.listenerId - The ID of the listener to remove.
|
|
510
|
+
* @returns {string} The ID of the removed listener.
|
|
302
511
|
*/
|
|
303
512
|
removeInboxListener(props) {
|
|
304
513
|
// Call native code
|
|
305
|
-
|
|
514
|
+
Modules.Shared.removeInboxListener(props.listenerId);
|
|
306
515
|
|
|
307
516
|
// Remove the listener
|
|
308
517
|
if (this.inboxListeners.has(props.listenerId)) {
|
|
@@ -320,49 +529,38 @@ class Courier {
|
|
|
320
529
|
}
|
|
321
530
|
|
|
322
531
|
/**
|
|
323
|
-
*
|
|
324
|
-
* Useful for pull to refresh
|
|
532
|
+
* Removes all inbox listeners.
|
|
325
533
|
*/
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Sets the pagination limit
|
|
340
|
-
* Min = 1
|
|
341
|
-
* Max = 100
|
|
342
|
-
*/
|
|
343
|
-
setInboxPaginationLimit(props) {
|
|
344
|
-
CourierReactNativeModules.setInboxPaginationLimit(props.limit);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Get all available preferences
|
|
349
|
-
*/
|
|
350
|
-
async getUserPreferences(props) {
|
|
351
|
-
return CourierReactNativeModules.getUserPreferences((props === null || props === void 0 ? void 0 : props.paginationCursor) ?? "");
|
|
534
|
+
removeAllInboxListeners() {
|
|
535
|
+
// Call native code
|
|
536
|
+
Modules.Shared.removeAllInboxListeners();
|
|
537
|
+
|
|
538
|
+
// Remove all items from inboxListeners
|
|
539
|
+
this.inboxListeners.forEach(listener => {
|
|
540
|
+
var _listener$onInitialLo2, _listener$onError2, _listener$onMessagesC2;
|
|
541
|
+
listener === null || listener === void 0 || (_listener$onInitialLo2 = listener.onInitialLoad) === null || _listener$onInitialLo2 === void 0 ? void 0 : _listener$onInitialLo2.remove();
|
|
542
|
+
listener === null || listener === void 0 || (_listener$onError2 = listener.onError) === null || _listener$onError2 === void 0 ? void 0 : _listener$onError2.remove();
|
|
543
|
+
listener === null || listener === void 0 || (_listener$onMessagesC2 = listener.onMessagesChanged) === null || _listener$onMessagesC2 === void 0 ? void 0 : _listener$onMessagesC2.remove();
|
|
544
|
+
});
|
|
545
|
+
this.inboxListeners.clear();
|
|
352
546
|
}
|
|
353
547
|
|
|
354
548
|
/**
|
|
355
|
-
*
|
|
549
|
+
* Refreshes the inbox.
|
|
550
|
+
* Useful for pull-to-refresh functionality.
|
|
551
|
+
* @returns {Promise<void>} A promise that resolves when the inbox is refreshed.
|
|
356
552
|
*/
|
|
357
|
-
async
|
|
358
|
-
return
|
|
553
|
+
async refreshInbox() {
|
|
554
|
+
return Modules.Shared.refreshInbox();
|
|
359
555
|
}
|
|
360
556
|
|
|
361
557
|
/**
|
|
362
|
-
*
|
|
558
|
+
* Fetches the next page of inbox messages.
|
|
559
|
+
* @returns {Promise<InboxMessage[]>} A promise that resolves with an array of fetched inbox messages.
|
|
363
560
|
*/
|
|
364
|
-
async
|
|
365
|
-
|
|
561
|
+
async fetchNextPageOfMessages() {
|
|
562
|
+
const messages = await Modules.Shared.fetchNextPageOfMessages();
|
|
563
|
+
return messages.map(message => JSON.parse(message));
|
|
366
564
|
}
|
|
367
565
|
}
|
|
368
566
|
export default Courier;
|