@trycourier/courier-react-native 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +0 -3
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +30 -22
- package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +84 -18
- package/courier-react-native.podspec +1 -1
- package/ios/CourierReactNativeModule.m +4 -6
- package/ios/CourierReactNativeModule.swift +17 -11
- package/ios/CourierReactNativeViewManager.swift +122 -41
- package/lib/commonjs/index.js +55 -38
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierPushProvider.js +16 -0
- package/lib/commonjs/models/CourierPushProvider.js.map +1 -0
- package/lib/module/index.js +14 -21
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierPushProvider.js +9 -0
- package/lib/module/models/CourierPushProvider.js.map +1 -0
- package/lib/typescript/index.d.ts +16 -8
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/CourierInboxTheme.d.ts +24 -8
- package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -1
- package/lib/typescript/models/CourierPushProvider.d.ts +8 -0
- package/lib/typescript/models/CourierPushProvider.d.ts.map +1 -0
- package/lib/typescript/views/CourierInboxView.d.ts +1 -1
- package/lib/typescript/views/CourierInboxView.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +16 -26
- package/src/models/CourierInboxTheme.tsx +28 -8
- package/src/models/CourierPushProvider.tsx +7 -0
- package/src/views/CourierInboxView.tsx +1 -1
- package/lib/commonjs/hooks/CourierProvider.js +0 -254
- package/lib/commonjs/hooks/CourierProvider.js.map +0 -1
- package/lib/module/hooks/CourierProvider.js +0 -241
- package/lib/module/hooks/CourierProvider.js.map +0 -1
- package/lib/typescript/hooks/CourierProvider.d.ts +0 -57
- package/lib/typescript/hooks/CourierProvider.d.ts.map +0 -1
- package/src/hooks/CourierProvider.tsx +0 -356
package/src/index.tsx
CHANGED
|
@@ -15,15 +15,17 @@ import { CourierUserPreferences } from './models/CourierUserPreferences';
|
|
|
15
15
|
import { CourierUserPreferencesTopic } from './models/CourierUserPreferencesTopic';
|
|
16
16
|
import { CourierUserPreferencesChannel } from './models/CourierUserPreferencesChannel';
|
|
17
17
|
import { CourierUserPreferencesStatus } from './models/CourierUserPreferencesStatus';
|
|
18
|
+
import { CourierPushProvider } from './models/CourierPushProvider';
|
|
18
19
|
|
|
19
20
|
// Exports
|
|
20
21
|
export { CourierInboxView } from './views/CourierInboxView';
|
|
21
|
-
export { CourierProvider, useCourierAuth, useCourierPush, useCourierInbox } from './hooks/CourierProvider';
|
|
22
22
|
export { CourierInboxListener } from './models/CourierInboxListener';
|
|
23
23
|
export { CourierPushListener } from './models/CourierPushListener';
|
|
24
24
|
export { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
|
|
25
25
|
export { CourierUserPreferencesChannel } from './models/CourierUserPreferencesChannel';
|
|
26
26
|
export { CourierUserPreferencesStatus } from './models/CourierUserPreferencesStatus';
|
|
27
|
+
export { CourierPushProvider } from './models/CourierPushProvider';
|
|
28
|
+
export { CourierInboxFont, CourierInboxButtonStyle, CourierInboxButton, CourierInboxTextStyle, CourierInboxInfoViewStyle, CourierInboxUnreadIndicatorStyle, CourierInboxTheme } from './models/CourierInboxTheme';
|
|
27
29
|
export type iOSForegroundPresentationOptions = 'sound' | 'badge' | 'list' | 'banner';
|
|
28
30
|
|
|
29
31
|
const LINKING_ERROR =
|
|
@@ -128,25 +130,25 @@ class Courier {
|
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
/**
|
|
131
|
-
* Gets
|
|
133
|
+
* Gets a token for key
|
|
132
134
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return CourierReactNativeModules.getApnsToken();
|
|
135
|
+
public getToken(props: { key: string }): Promise<string | undefined> {
|
|
136
|
+
return CourierReactNativeModules.getToken(props.key);
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*/
|
|
141
|
-
get fcmToken(): Promise<string | undefined> {
|
|
142
|
-
return CourierReactNativeModules.getFcmToken();
|
|
139
|
+
public getTokenForProvider(props: { provider: CourierPushProvider }): Promise<string | undefined> {
|
|
140
|
+
return CourierReactNativeModules.getToken(props.provider);
|
|
143
141
|
}
|
|
144
142
|
|
|
145
143
|
/**
|
|
146
144
|
* Sets the fcm token to be used by Courier
|
|
147
145
|
*/
|
|
148
|
-
public
|
|
149
|
-
return CourierReactNativeModules.
|
|
146
|
+
public setToken(props: { key: string, token: string }): Promise<void> {
|
|
147
|
+
return CourierReactNativeModules.setToken(props.key, props.token);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public setTokenForProvider(props: { provider: CourierPushProvider, token: string }): Promise<void> {
|
|
151
|
+
return CourierReactNativeModules.setToken(props.provider, props.token);
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
/**
|
|
@@ -154,13 +156,7 @@ class Courier {
|
|
|
154
156
|
* Only supported on iOS
|
|
155
157
|
*/
|
|
156
158
|
public getNotificationPermissionStatus(): Promise<string> {
|
|
157
|
-
|
|
158
|
-
if (Platform.OS === 'ios') {
|
|
159
|
-
return CourierReactNativeModules.getNotificationPermissionStatus();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return Promise.reject('unknown')
|
|
163
|
-
|
|
159
|
+
return CourierReactNativeModules.getNotificationPermissionStatus();
|
|
164
160
|
}
|
|
165
161
|
|
|
166
162
|
/**
|
|
@@ -169,13 +165,7 @@ class Courier {
|
|
|
169
165
|
* Only supported on iOS
|
|
170
166
|
*/
|
|
171
167
|
public requestNotificationPermission(): Promise<string> {
|
|
172
|
-
|
|
173
|
-
if (Platform.OS === 'ios') {
|
|
174
|
-
return CourierReactNativeModules.requestNotificationPermission();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return Promise.reject('unknown')
|
|
178
|
-
|
|
168
|
+
return CourierReactNativeModules.requestNotificationPermission();
|
|
179
169
|
}
|
|
180
170
|
|
|
181
171
|
/**
|
|
@@ -4,20 +4,40 @@ export interface CourierInboxFont {
|
|
|
4
4
|
color?: string
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export interface
|
|
7
|
+
export interface CourierInboxButtonStyle {
|
|
8
|
+
unread?: CourierInboxButton
|
|
9
|
+
read?: CourierInboxButton
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CourierInboxButton {
|
|
8
13
|
font?: CourierInboxFont
|
|
9
14
|
backgroundColor?: string
|
|
10
15
|
cornerRadius?: number
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
export
|
|
14
|
-
|
|
18
|
+
export interface CourierInboxTextStyle {
|
|
19
|
+
unread?: CourierInboxFont
|
|
20
|
+
read?: CourierInboxFont
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CourierInboxInfoViewStyle {
|
|
24
|
+
font?: CourierInboxFont
|
|
25
|
+
button?: CourierInboxButton
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface CourierInboxUnreadIndicatorStyle {
|
|
29
|
+
indicator?: 'dot' | 'line'
|
|
30
|
+
color?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CourierInboxTheme {
|
|
15
34
|
loadingIndicatorColor?: string
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
unreadIndicatorStyle?: CourierInboxUnreadIndicatorStyle
|
|
36
|
+
titleStyle?: CourierInboxTextStyle
|
|
37
|
+
timeStyle?: CourierInboxTextStyle
|
|
38
|
+
bodyStyle?: CourierInboxTextStyle
|
|
39
|
+
buttonStyle?: CourierInboxButtonStyle
|
|
40
|
+
infoViewStyle?: CourierInboxInfoViewStyle
|
|
21
41
|
iOS?: {
|
|
22
42
|
messageAnimationStyle?: 'fade' | 'right' | 'left' | 'top' | 'bottom' | 'none' | 'middle' | 'automatic',
|
|
23
43
|
cellStyles?: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { useEffect } from "react";
|
|
2
2
|
import { Platform, requireNativeComponent, UIManager, ViewStyle, DeviceEventEmitter, EmitterSubscription } from "react-native";
|
|
3
|
-
import CourierInboxTheme from "../models/CourierInboxTheme";
|
|
4
3
|
import { InboxAction } from "../models/InboxAction";
|
|
5
4
|
import { InboxMessage } from "../models/InboxMessage";
|
|
5
|
+
import { CourierInboxTheme } from "src/models/CourierInboxTheme";
|
|
6
6
|
|
|
7
7
|
type CourierInboxViewProps = {
|
|
8
8
|
theme?: {
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useCourierPush = exports.useCourierInbox = exports.useCourierAuth = exports.CourierProvider = void 0;
|
|
7
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _ = _interopRequireDefault(require(".."));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
-
let authListener = undefined;
|
|
13
|
-
let pushListener = undefined;
|
|
14
|
-
let inboxListener = undefined;
|
|
15
|
-
const CourierContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
16
|
-
const CourierProvider = _ref => {
|
|
17
|
-
let {
|
|
18
|
-
children
|
|
19
|
-
} = _ref;
|
|
20
|
-
// Auth
|
|
21
|
-
const [auth_userId, auth_setUserId] = (0, _react.useState)(undefined);
|
|
22
|
-
const [auth_isLoading, auth_setIsLoading] = (0, _react.useState)(false);
|
|
23
|
-
const [auth_error, auth_setError] = (0, _react.useState)(undefined);
|
|
24
|
-
|
|
25
|
-
// Push
|
|
26
|
-
const [push_pushNotificationDelivered, inbox_setPushNotificationDelivered] = (0, _react.useState)(undefined);
|
|
27
|
-
const [push_pushNotificationClicked, inbox_setPushNotificationClicked] = (0, _react.useState)(undefined);
|
|
28
|
-
const [push_apnsToken, push_setApnsToken] = (0, _react.useState)(undefined);
|
|
29
|
-
const [push_fcmToken, push_setFcmToken] = (0, _react.useState)(undefined);
|
|
30
|
-
const [push_notificationPermission, push_setNotificationPermission] = (0, _react.useState)(undefined);
|
|
31
|
-
|
|
32
|
-
// Inbox
|
|
33
|
-
const [inbox_isLoading, inbox_setIsLoading] = (0, _react.useState)(false);
|
|
34
|
-
const [inbox_isRefreshing, inbox_setIsRefreshing] = (0, _react.useState)(false);
|
|
35
|
-
const [inbox_error, inbox_setError] = (0, _react.useState)(undefined);
|
|
36
|
-
const [inbox_messages, inbox_setMessages] = (0, _react.useState)([]);
|
|
37
|
-
const [inbox_unreadMessageCount, inbox_setUnreadMessageCount] = (0, _react.useState)(0);
|
|
38
|
-
const [inbox_totalMessageCount, inbox_setTotalMessageCount] = (0, _react.useState)(0);
|
|
39
|
-
const [inbox_canPaginate, inbox_setCanPaginate] = (0, _react.useState)(false);
|
|
40
|
-
(0, _react.useEffect)(() => {
|
|
41
|
-
// Get the initial values
|
|
42
|
-
const userId = _.default.shared.userId;
|
|
43
|
-
auth_setUserId(userId);
|
|
44
|
-
}, []);
|
|
45
|
-
(0, _react.useEffect)(() => {
|
|
46
|
-
return () => {
|
|
47
|
-
var _authListener, _pushListener, _inboxListener;
|
|
48
|
-
(_authListener = authListener) === null || _authListener === void 0 ? void 0 : _authListener.remove();
|
|
49
|
-
(_pushListener = pushListener) === null || _pushListener === void 0 ? void 0 : _pushListener.remove();
|
|
50
|
-
(_inboxListener = inboxListener) === null || _inboxListener === void 0 ? void 0 : _inboxListener.remove();
|
|
51
|
-
};
|
|
52
|
-
}, []);
|
|
53
|
-
const startAuth = () => {
|
|
54
|
-
if (!authListener) {
|
|
55
|
-
authListener = _.default.shared.addAuthenticationListener({
|
|
56
|
-
onUserChanged: userId => auth_setUserId(userId)
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const startPush = () => {
|
|
61
|
-
// Permissions
|
|
62
|
-
syncNotificationPermissions();
|
|
63
|
-
|
|
64
|
-
// Push tokens
|
|
65
|
-
syncTokens();
|
|
66
|
-
if (!pushListener) {
|
|
67
|
-
pushListener = _.default.shared.addPushNotificationListener({
|
|
68
|
-
onPushNotificationDelivered: push => inbox_setPushNotificationDelivered(push),
|
|
69
|
-
onPushNotificationClicked: push => inbox_setPushNotificationClicked(push)
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const startInbox = () => {
|
|
74
|
-
if (!inboxListener) {
|
|
75
|
-
inboxListener = _.default.shared.addInboxListener({
|
|
76
|
-
onInitialLoad: () => {
|
|
77
|
-
inbox_setIsLoading(true);
|
|
78
|
-
inbox_setError(undefined);
|
|
79
|
-
},
|
|
80
|
-
onError: error => {
|
|
81
|
-
inbox_setIsLoading(false);
|
|
82
|
-
inbox_setError(error);
|
|
83
|
-
},
|
|
84
|
-
onMessagesChanged: (messages, unreadMessageCount, totalMessageCount, canPaginate) => {
|
|
85
|
-
inbox_setIsLoading(false);
|
|
86
|
-
inbox_setError(undefined);
|
|
87
|
-
inbox_setMessages(messages);
|
|
88
|
-
inbox_setUnreadMessageCount(unreadMessageCount);
|
|
89
|
-
inbox_setTotalMessageCount(totalMessageCount);
|
|
90
|
-
inbox_setCanPaginate(canPaginate);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const signIn = async props => {
|
|
96
|
-
auth_setIsLoading(true);
|
|
97
|
-
auth_setError(undefined);
|
|
98
|
-
try {
|
|
99
|
-
await _.default.shared.signIn(props);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
auth_setError(error);
|
|
102
|
-
}
|
|
103
|
-
auth_setIsLoading(false);
|
|
104
|
-
};
|
|
105
|
-
const signOut = async () => {
|
|
106
|
-
auth_setIsLoading(true);
|
|
107
|
-
auth_setError(undefined);
|
|
108
|
-
try {
|
|
109
|
-
await _.default.shared.signOut();
|
|
110
|
-
} catch (error) {
|
|
111
|
-
auth_setError(error);
|
|
112
|
-
}
|
|
113
|
-
auth_setIsLoading(false);
|
|
114
|
-
};
|
|
115
|
-
const syncNotificationPermissions = async () => {
|
|
116
|
-
const status = await _.default.shared.getNotificationPermissionStatus();
|
|
117
|
-
push_setNotificationPermission(status);
|
|
118
|
-
};
|
|
119
|
-
const syncTokens = async () => {
|
|
120
|
-
// APNS
|
|
121
|
-
const apnsToken = _.default.shared.apnsToken;
|
|
122
|
-
push_setApnsToken(apnsToken);
|
|
123
|
-
const fcmToken = await _.default.shared.fcmToken;
|
|
124
|
-
push_setFcmToken(fcmToken);
|
|
125
|
-
};
|
|
126
|
-
const requestNotificationPermission = async () => {
|
|
127
|
-
const status = await _.default.shared.requestNotificationPermission();
|
|
128
|
-
push_setNotificationPermission(status);
|
|
129
|
-
};
|
|
130
|
-
const iOSForegroundPresentationOptions = options => {
|
|
131
|
-
_.default.shared.iOSForegroundPresentationOptions({
|
|
132
|
-
options: options
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
const setPaginationLimit = limit => {
|
|
136
|
-
_.default.shared.setInboxPaginationLimit({
|
|
137
|
-
limit
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
const fetchNextPageOfMessages = () => {
|
|
141
|
-
return _.default.shared.fetchNextPageOfMessages();
|
|
142
|
-
};
|
|
143
|
-
const refresh = async () => {
|
|
144
|
-
inbox_setIsRefreshing(true);
|
|
145
|
-
await _.default.shared.refreshInbox();
|
|
146
|
-
inbox_setIsRefreshing(false);
|
|
147
|
-
};
|
|
148
|
-
const readAllMessages = () => {
|
|
149
|
-
// Skip if no user is found
|
|
150
|
-
if (!_.default.shared.userId) {
|
|
151
|
-
return Promise.resolve();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Read the messages
|
|
155
|
-
return _.default.shared.readAllInboxMessages();
|
|
156
|
-
};
|
|
157
|
-
const readMessage = messageId => {
|
|
158
|
-
return _.default.shared.readMessage({
|
|
159
|
-
messageId
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
const unreadMessage = messageId => {
|
|
163
|
-
return _.default.shared.unreadMessage({
|
|
164
|
-
messageId
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
return /*#__PURE__*/_react.default.createElement(CourierContext.Provider, {
|
|
168
|
-
value: {
|
|
169
|
-
auth: {
|
|
170
|
-
start: startAuth,
|
|
171
|
-
isLoading: auth_isLoading,
|
|
172
|
-
error: auth_error,
|
|
173
|
-
userId: auth_userId,
|
|
174
|
-
signIn,
|
|
175
|
-
signOut
|
|
176
|
-
},
|
|
177
|
-
push: {
|
|
178
|
-
start: startPush,
|
|
179
|
-
delivered: push_pushNotificationDelivered,
|
|
180
|
-
clicked: push_pushNotificationClicked,
|
|
181
|
-
tokens: {
|
|
182
|
-
fcm: push_fcmToken,
|
|
183
|
-
apns: push_apnsToken
|
|
184
|
-
},
|
|
185
|
-
iOSForegroundPresentationOptions,
|
|
186
|
-
notificationPermissionStatus: push_notificationPermission,
|
|
187
|
-
requestNotificationPermission
|
|
188
|
-
},
|
|
189
|
-
inbox: {
|
|
190
|
-
start: startInbox,
|
|
191
|
-
isLoading: inbox_isLoading,
|
|
192
|
-
error: inbox_error,
|
|
193
|
-
messages: inbox_messages,
|
|
194
|
-
unreadMessageCount: inbox_unreadMessageCount,
|
|
195
|
-
totalMessageCount: inbox_totalMessageCount,
|
|
196
|
-
canPaginate: inbox_canPaginate,
|
|
197
|
-
setPaginationLimit,
|
|
198
|
-
fetchNextPageOfMessages,
|
|
199
|
-
refresh,
|
|
200
|
-
isRefreshing: inbox_isRefreshing,
|
|
201
|
-
readAllMessages,
|
|
202
|
-
readMessage,
|
|
203
|
-
unreadMessage
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}, children);
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// Auth Hook
|
|
210
|
-
exports.CourierProvider = CourierProvider;
|
|
211
|
-
const useCourierAuth = () => {
|
|
212
|
-
const context = (0, _react.useContext)(CourierContext);
|
|
213
|
-
if (!context) {
|
|
214
|
-
throw new Error('useCourierAuth must be used within an CourierProvider');
|
|
215
|
-
}
|
|
216
|
-
context.auth.start();
|
|
217
|
-
return context.auth;
|
|
218
|
-
};
|
|
219
|
-
exports.useCourierAuth = useCourierAuth;
|
|
220
|
-
// Push Hook
|
|
221
|
-
const useCourierPush = function () {
|
|
222
|
-
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
223
|
-
const context = (0, _react.useContext)(CourierContext);
|
|
224
|
-
if (!context) {
|
|
225
|
-
throw new Error('useCourierPush must be used within an CourierProvider');
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Set the presentation options
|
|
229
|
-
const options = props.iOSForegroundPresentationOptions;
|
|
230
|
-
if (options) {
|
|
231
|
-
context.push.iOSForegroundPresentationOptions(options);
|
|
232
|
-
}
|
|
233
|
-
context.push.start();
|
|
234
|
-
return context.push;
|
|
235
|
-
};
|
|
236
|
-
exports.useCourierPush = useCourierPush;
|
|
237
|
-
// Inbox Hook
|
|
238
|
-
const useCourierInbox = function () {
|
|
239
|
-
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
240
|
-
const context = (0, _react.useContext)(CourierContext);
|
|
241
|
-
if (!context) {
|
|
242
|
-
throw new Error('useCourierInbox must be used within an CourierProvider');
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Set the initial pagination limit if needed
|
|
246
|
-
const limit = props.paginationLimit;
|
|
247
|
-
if (limit) {
|
|
248
|
-
context.inbox.setPaginationLimit(limit);
|
|
249
|
-
}
|
|
250
|
-
context.inbox.start();
|
|
251
|
-
return context.inbox;
|
|
252
|
-
};
|
|
253
|
-
exports.useCourierInbox = useCourierInbox;
|
|
254
|
-
//# sourceMappingURL=CourierProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_","_interopRequireDefault","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","authListener","undefined","pushListener","inboxListener","CourierContext","createContext","CourierProvider","_ref","children","auth_userId","auth_setUserId","useState","auth_isLoading","auth_setIsLoading","auth_error","auth_setError","push_pushNotificationDelivered","inbox_setPushNotificationDelivered","push_pushNotificationClicked","inbox_setPushNotificationClicked","push_apnsToken","push_setApnsToken","push_fcmToken","push_setFcmToken","push_notificationPermission","push_setNotificationPermission","inbox_isLoading","inbox_setIsLoading","inbox_isRefreshing","inbox_setIsRefreshing","inbox_error","inbox_setError","inbox_messages","inbox_setMessages","inbox_unreadMessageCount","inbox_setUnreadMessageCount","inbox_totalMessageCount","inbox_setTotalMessageCount","inbox_canPaginate","inbox_setCanPaginate","useEffect","userId","Courier","shared","_authListener","_pushListener","_inboxListener","remove","startAuth","addAuthenticationListener","onUserChanged","startPush","syncNotificationPermissions","syncTokens","addPushNotificationListener","onPushNotificationDelivered","push","onPushNotificationClicked","startInbox","addInboxListener","onInitialLoad","onError","error","onMessagesChanged","messages","unreadMessageCount","totalMessageCount","canPaginate","signIn","props","signOut","status","getNotificationPermissionStatus","apnsToken","fcmToken","requestNotificationPermission","iOSForegroundPresentationOptions","options","setPaginationLimit","limit","setInboxPaginationLimit","fetchNextPageOfMessages","refresh","refreshInbox","readAllMessages","Promise","resolve","readAllInboxMessages","readMessage","messageId","unreadMessage","createElement","Provider","value","auth","start","isLoading","delivered","clicked","tokens","fcm","apns","notificationPermissionStatus","inbox","isRefreshing","exports","useCourierAuth","context","useContext","Error","useCourierPush","arguments","length","useCourierInbox","paginationLimit"],"sourceRoot":"../../../src","sources":["hooks/CourierProvider.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,CAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAyI,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAR,wBAAAI,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAQ,KAAA,GAAAL,wBAAA,CAAAC,WAAA,OAAAI,KAAA,IAAAA,KAAA,CAA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KAAK,CAAC6C,eAAe;EACnC,IAAInC,KAAK,EAAE;IACT4B,OAAO,CAACJ,KAAK,CAACzB,kBAAkB,CAACC,KAAK,CAAC;EACzC;EAEA4B,OAAO,CAACJ,KAAK,CAACR,KAAK,CAAC,CAAC;EAErB,OAAOY,OAAO,CAACJ,KAAK;AAEtB,CAAC;AAACE,OAAA,CAAAQ,eAAA,GAAAA,eAAA"}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
2
|
-
import Courier from '..';
|
|
3
|
-
let authListener = undefined;
|
|
4
|
-
let pushListener = undefined;
|
|
5
|
-
let inboxListener = undefined;
|
|
6
|
-
const CourierContext = /*#__PURE__*/createContext(undefined);
|
|
7
|
-
export const CourierProvider = _ref => {
|
|
8
|
-
let {
|
|
9
|
-
children
|
|
10
|
-
} = _ref;
|
|
11
|
-
// Auth
|
|
12
|
-
const [auth_userId, auth_setUserId] = useState(undefined);
|
|
13
|
-
const [auth_isLoading, auth_setIsLoading] = useState(false);
|
|
14
|
-
const [auth_error, auth_setError] = useState(undefined);
|
|
15
|
-
|
|
16
|
-
// Push
|
|
17
|
-
const [push_pushNotificationDelivered, inbox_setPushNotificationDelivered] = useState(undefined);
|
|
18
|
-
const [push_pushNotificationClicked, inbox_setPushNotificationClicked] = useState(undefined);
|
|
19
|
-
const [push_apnsToken, push_setApnsToken] = useState(undefined);
|
|
20
|
-
const [push_fcmToken, push_setFcmToken] = useState(undefined);
|
|
21
|
-
const [push_notificationPermission, push_setNotificationPermission] = useState(undefined);
|
|
22
|
-
|
|
23
|
-
// Inbox
|
|
24
|
-
const [inbox_isLoading, inbox_setIsLoading] = useState(false);
|
|
25
|
-
const [inbox_isRefreshing, inbox_setIsRefreshing] = useState(false);
|
|
26
|
-
const [inbox_error, inbox_setError] = useState(undefined);
|
|
27
|
-
const [inbox_messages, inbox_setMessages] = useState([]);
|
|
28
|
-
const [inbox_unreadMessageCount, inbox_setUnreadMessageCount] = useState(0);
|
|
29
|
-
const [inbox_totalMessageCount, inbox_setTotalMessageCount] = useState(0);
|
|
30
|
-
const [inbox_canPaginate, inbox_setCanPaginate] = useState(false);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
// Get the initial values
|
|
33
|
-
const userId = Courier.shared.userId;
|
|
34
|
-
auth_setUserId(userId);
|
|
35
|
-
}, []);
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
return () => {
|
|
38
|
-
var _authListener, _pushListener, _inboxListener;
|
|
39
|
-
(_authListener = authListener) === null || _authListener === void 0 ? void 0 : _authListener.remove();
|
|
40
|
-
(_pushListener = pushListener) === null || _pushListener === void 0 ? void 0 : _pushListener.remove();
|
|
41
|
-
(_inboxListener = inboxListener) === null || _inboxListener === void 0 ? void 0 : _inboxListener.remove();
|
|
42
|
-
};
|
|
43
|
-
}, []);
|
|
44
|
-
const startAuth = () => {
|
|
45
|
-
if (!authListener) {
|
|
46
|
-
authListener = Courier.shared.addAuthenticationListener({
|
|
47
|
-
onUserChanged: userId => auth_setUserId(userId)
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const startPush = () => {
|
|
52
|
-
// Permissions
|
|
53
|
-
syncNotificationPermissions();
|
|
54
|
-
|
|
55
|
-
// Push tokens
|
|
56
|
-
syncTokens();
|
|
57
|
-
if (!pushListener) {
|
|
58
|
-
pushListener = Courier.shared.addPushNotificationListener({
|
|
59
|
-
onPushNotificationDelivered: push => inbox_setPushNotificationDelivered(push),
|
|
60
|
-
onPushNotificationClicked: push => inbox_setPushNotificationClicked(push)
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const startInbox = () => {
|
|
65
|
-
if (!inboxListener) {
|
|
66
|
-
inboxListener = Courier.shared.addInboxListener({
|
|
67
|
-
onInitialLoad: () => {
|
|
68
|
-
inbox_setIsLoading(true);
|
|
69
|
-
inbox_setError(undefined);
|
|
70
|
-
},
|
|
71
|
-
onError: error => {
|
|
72
|
-
inbox_setIsLoading(false);
|
|
73
|
-
inbox_setError(error);
|
|
74
|
-
},
|
|
75
|
-
onMessagesChanged: (messages, unreadMessageCount, totalMessageCount, canPaginate) => {
|
|
76
|
-
inbox_setIsLoading(false);
|
|
77
|
-
inbox_setError(undefined);
|
|
78
|
-
inbox_setMessages(messages);
|
|
79
|
-
inbox_setUnreadMessageCount(unreadMessageCount);
|
|
80
|
-
inbox_setTotalMessageCount(totalMessageCount);
|
|
81
|
-
inbox_setCanPaginate(canPaginate);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
const signIn = async props => {
|
|
87
|
-
auth_setIsLoading(true);
|
|
88
|
-
auth_setError(undefined);
|
|
89
|
-
try {
|
|
90
|
-
await Courier.shared.signIn(props);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
auth_setError(error);
|
|
93
|
-
}
|
|
94
|
-
auth_setIsLoading(false);
|
|
95
|
-
};
|
|
96
|
-
const signOut = async () => {
|
|
97
|
-
auth_setIsLoading(true);
|
|
98
|
-
auth_setError(undefined);
|
|
99
|
-
try {
|
|
100
|
-
await Courier.shared.signOut();
|
|
101
|
-
} catch (error) {
|
|
102
|
-
auth_setError(error);
|
|
103
|
-
}
|
|
104
|
-
auth_setIsLoading(false);
|
|
105
|
-
};
|
|
106
|
-
const syncNotificationPermissions = async () => {
|
|
107
|
-
const status = await Courier.shared.getNotificationPermissionStatus();
|
|
108
|
-
push_setNotificationPermission(status);
|
|
109
|
-
};
|
|
110
|
-
const syncTokens = async () => {
|
|
111
|
-
// APNS
|
|
112
|
-
const apnsToken = Courier.shared.apnsToken;
|
|
113
|
-
push_setApnsToken(apnsToken);
|
|
114
|
-
const fcmToken = await Courier.shared.fcmToken;
|
|
115
|
-
push_setFcmToken(fcmToken);
|
|
116
|
-
};
|
|
117
|
-
const requestNotificationPermission = async () => {
|
|
118
|
-
const status = await Courier.shared.requestNotificationPermission();
|
|
119
|
-
push_setNotificationPermission(status);
|
|
120
|
-
};
|
|
121
|
-
const iOSForegroundPresentationOptions = options => {
|
|
122
|
-
Courier.shared.iOSForegroundPresentationOptions({
|
|
123
|
-
options: options
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
const setPaginationLimit = limit => {
|
|
127
|
-
Courier.shared.setInboxPaginationLimit({
|
|
128
|
-
limit
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
const fetchNextPageOfMessages = () => {
|
|
132
|
-
return Courier.shared.fetchNextPageOfMessages();
|
|
133
|
-
};
|
|
134
|
-
const refresh = async () => {
|
|
135
|
-
inbox_setIsRefreshing(true);
|
|
136
|
-
await Courier.shared.refreshInbox();
|
|
137
|
-
inbox_setIsRefreshing(false);
|
|
138
|
-
};
|
|
139
|
-
const readAllMessages = () => {
|
|
140
|
-
// Skip if no user is found
|
|
141
|
-
if (!Courier.shared.userId) {
|
|
142
|
-
return Promise.resolve();
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Read the messages
|
|
146
|
-
return Courier.shared.readAllInboxMessages();
|
|
147
|
-
};
|
|
148
|
-
const readMessage = messageId => {
|
|
149
|
-
return Courier.shared.readMessage({
|
|
150
|
-
messageId
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
const unreadMessage = messageId => {
|
|
154
|
-
return Courier.shared.unreadMessage({
|
|
155
|
-
messageId
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
return /*#__PURE__*/React.createElement(CourierContext.Provider, {
|
|
159
|
-
value: {
|
|
160
|
-
auth: {
|
|
161
|
-
start: startAuth,
|
|
162
|
-
isLoading: auth_isLoading,
|
|
163
|
-
error: auth_error,
|
|
164
|
-
userId: auth_userId,
|
|
165
|
-
signIn,
|
|
166
|
-
signOut
|
|
167
|
-
},
|
|
168
|
-
push: {
|
|
169
|
-
start: startPush,
|
|
170
|
-
delivered: push_pushNotificationDelivered,
|
|
171
|
-
clicked: push_pushNotificationClicked,
|
|
172
|
-
tokens: {
|
|
173
|
-
fcm: push_fcmToken,
|
|
174
|
-
apns: push_apnsToken
|
|
175
|
-
},
|
|
176
|
-
iOSForegroundPresentationOptions,
|
|
177
|
-
notificationPermissionStatus: push_notificationPermission,
|
|
178
|
-
requestNotificationPermission
|
|
179
|
-
},
|
|
180
|
-
inbox: {
|
|
181
|
-
start: startInbox,
|
|
182
|
-
isLoading: inbox_isLoading,
|
|
183
|
-
error: inbox_error,
|
|
184
|
-
messages: inbox_messages,
|
|
185
|
-
unreadMessageCount: inbox_unreadMessageCount,
|
|
186
|
-
totalMessageCount: inbox_totalMessageCount,
|
|
187
|
-
canPaginate: inbox_canPaginate,
|
|
188
|
-
setPaginationLimit,
|
|
189
|
-
fetchNextPageOfMessages,
|
|
190
|
-
refresh,
|
|
191
|
-
isRefreshing: inbox_isRefreshing,
|
|
192
|
-
readAllMessages,
|
|
193
|
-
readMessage,
|
|
194
|
-
unreadMessage
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}, children);
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
// Auth Hook
|
|
201
|
-
export const useCourierAuth = () => {
|
|
202
|
-
const context = useContext(CourierContext);
|
|
203
|
-
if (!context) {
|
|
204
|
-
throw new Error('useCourierAuth must be used within an CourierProvider');
|
|
205
|
-
}
|
|
206
|
-
context.auth.start();
|
|
207
|
-
return context.auth;
|
|
208
|
-
};
|
|
209
|
-
// Push Hook
|
|
210
|
-
export const useCourierPush = function () {
|
|
211
|
-
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
212
|
-
const context = useContext(CourierContext);
|
|
213
|
-
if (!context) {
|
|
214
|
-
throw new Error('useCourierPush must be used within an CourierProvider');
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Set the presentation options
|
|
218
|
-
const options = props.iOSForegroundPresentationOptions;
|
|
219
|
-
if (options) {
|
|
220
|
-
context.push.iOSForegroundPresentationOptions(options);
|
|
221
|
-
}
|
|
222
|
-
context.push.start();
|
|
223
|
-
return context.push;
|
|
224
|
-
};
|
|
225
|
-
// Inbox Hook
|
|
226
|
-
export const useCourierInbox = function () {
|
|
227
|
-
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
228
|
-
const context = useContext(CourierContext);
|
|
229
|
-
if (!context) {
|
|
230
|
-
throw new Error('useCourierInbox must be used within an CourierProvider');
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Set the initial pagination limit if needed
|
|
234
|
-
const limit = props.paginationLimit;
|
|
235
|
-
if (limit) {
|
|
236
|
-
context.inbox.setPaginationLimit(limit);
|
|
237
|
-
}
|
|
238
|
-
context.inbox.start();
|
|
239
|
-
return context.inbox;
|
|
240
|
-
};
|
|
241
|
-
//# sourceMappingURL=CourierProvider.js.map
|