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