@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","createContext","useContext","useEffect","useState","Courier","authListener","undefined","pushListener","inboxListener","CourierContext","CourierProvider","_ref","children","auth_userId","auth_setUserId","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","userId","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","useCourierAuth","context","Error","useCourierPush","arguments","length","useCourierInbox","paginationLimit"],"sourceRoot":"../../../src","sources":["hooks/CourierProvider.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAaC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAExF,OAAOC,OAAO,MAAsH,IAAI;AAExI,IAAIC,YAAuD,GAAGC,SA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AAO,MAAMuD,eAAe,GAAG,SAAAA,CAAA,EAA2D;EAAA,IAA1D1C,KAA2B,GAAAwC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAxG,SAAA,GAAAwG,SAAA,MAAG,CAAC,CAAC;EAE9D,MAAMH,OAAO,GAAG1G,UAAU,CAACQ,cAAc,CAAC;EAE1C,IAAI,CAACkG,OAAO,EAAE;IACZ,MAAM,IAAIC,KAAK,CAAC,wDAAwD,CAAC;EAC3E;;EAEA;EACA,MAAM5B,KAAK,GAAGV,KAAK,CAAC2C,eAAe;EACnC,IAAIjC,KAAK,EAAE;IACT2B,OAAO,CAACH,KAAK,CAACzB,kBAAkB,CAACC,KAAK,CAAC;EACzC;EAEA2B,OAAO,CAACH,KAAK,CAACR,KAAK,CAAC,CAAC;EAErB,OAAOW,OAAO,CAACH,KAAK;AAEtB,CAAC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import { InboxMessage } from '../models/InboxMessage';
|
|
3
|
-
import { iOSForegroundPresentationOptions } from '..';
|
|
4
|
-
interface CourierAuthContext {
|
|
5
|
-
start: () => void;
|
|
6
|
-
isLoading: boolean;
|
|
7
|
-
error?: string;
|
|
8
|
-
userId?: string;
|
|
9
|
-
signIn: (props: {
|
|
10
|
-
accessToken: string;
|
|
11
|
-
clientKey?: string;
|
|
12
|
-
userId: string;
|
|
13
|
-
}) => Promise<void>;
|
|
14
|
-
signOut: () => Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
interface CourierPushContext {
|
|
17
|
-
start: () => void;
|
|
18
|
-
delivered: any;
|
|
19
|
-
clicked: any;
|
|
20
|
-
tokens: {
|
|
21
|
-
apns?: string;
|
|
22
|
-
fcm?: string;
|
|
23
|
-
};
|
|
24
|
-
iOSForegroundPresentationOptions: (options: iOSForegroundPresentationOptions[]) => void;
|
|
25
|
-
notificationPermissionStatus?: string;
|
|
26
|
-
requestNotificationPermission: () => Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
interface CourierInboxContext {
|
|
29
|
-
start: () => void;
|
|
30
|
-
isLoading: boolean;
|
|
31
|
-
error?: string;
|
|
32
|
-
messages: InboxMessage[];
|
|
33
|
-
unreadMessageCount: number;
|
|
34
|
-
totalMessageCount: number;
|
|
35
|
-
canPaginate: boolean;
|
|
36
|
-
setPaginationLimit: (limit: number) => void;
|
|
37
|
-
fetchNextPageOfMessages: () => Promise<InboxMessage[]>;
|
|
38
|
-
refresh: () => Promise<void>;
|
|
39
|
-
isRefreshing: boolean;
|
|
40
|
-
readAllMessages: () => Promise<void>;
|
|
41
|
-
readMessage: (messageId: string) => string;
|
|
42
|
-
unreadMessage: (messageId: string) => string;
|
|
43
|
-
}
|
|
44
|
-
export declare const CourierProvider: React.FC<{
|
|
45
|
-
children: ReactNode;
|
|
46
|
-
}>;
|
|
47
|
-
export declare const useCourierAuth: () => CourierAuthContext;
|
|
48
|
-
interface UseCourierPushProps {
|
|
49
|
-
iOSForegroundPresentationOptions?: iOSForegroundPresentationOptions[];
|
|
50
|
-
}
|
|
51
|
-
export declare const useCourierPush: (props?: UseCourierPushProps) => CourierPushContext;
|
|
52
|
-
interface UseCourierInboxProps {
|
|
53
|
-
paginationLimit?: number;
|
|
54
|
-
}
|
|
55
|
-
export declare const useCourierInbox: (props?: UseCourierInboxProps) => CourierInboxContext;
|
|
56
|
-
export {};
|
|
57
|
-
//# sourceMappingURL=CourierProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CourierProvider.d.ts","sourceRoot":"","sources":["../../../src/hooks/CourierProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,SAAS,EAAmC,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAgB,EAA4E,gCAAgC,EAAE,MAAM,IAAI,CAAC;AAMzI,UAAU,kBAAkB;IAC1B,KAAK,EAAE,MAAM,I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AAC,IAAI,CAAC,CAAC;IACrC,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;CAC9C;AAUD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,CA2O7D,CAAC;AAGF,eAAO,MAAM,cAAc,QAAO,kBAYjC,CAAC;AAEF,UAAU,mBAAmB;IAC3B,gCAAgC,CAAC,EAAE,gCAAgC,EAAE,CAAA;CACtE;AAGD,eAAO,MAAM,cAAc,WAAW,mBAAmB,KAAQ,kBAkBhE,CAAC;AAEF,UAAU,oBAAoB;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAGD,eAAO,MAAM,eAAe,WAAW,oBAAoB,KAAQ,mBAkBlE,CAAC"}
|
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
import React, { createContext, ReactNode, useContext, useEffect, useState } from 'react';
|
|
2
|
-
import { InboxMessage } from '../models/InboxMessage';
|
|
3
|
-
import Courier, { CourierPushListener, CourierInboxListener, CourierAuthenticationListener, iOSForegroundPresentationOptions } from '..';
|
|
4
|
-
|
|
5
|
-
let authListener: CourierAuthenticationListener | undefined = undefined
|
|
6
|
-
let pushListener: CourierPushListener | undefined = undefined
|
|
7
|
-
let inboxListener: CourierInboxListener | undefined = undefined
|
|
8
|
-
|
|
9
|
-
interface CourierAuthContext {
|
|
10
|
-
start: () => void;
|
|
11
|
-
isLoading: boolean;
|
|
12
|
-
error?: string;
|
|
13
|
-
userId?: string;
|
|
14
|
-
signIn: (props: { accessToken: string; clientKey?: string; userId: string }) => Promise<void>;
|
|
15
|
-
signOut: () => Promise<void>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface CourierPushContext {
|
|
19
|
-
start: () => void;
|
|
20
|
-
delivered: any;
|
|
21
|
-
clicked: any;
|
|
22
|
-
tokens: {
|
|
23
|
-
apns?: string;
|
|
24
|
-
fcm?: string;
|
|
25
|
-
};
|
|
26
|
-
iOSForegroundPresentationOptions: (options: iOSForegroundPresentationOptions[]) => void;
|
|
27
|
-
notificationPermissionStatus?: string;
|
|
28
|
-
requestNotificationPermission: () => Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface CourierInboxContext {
|
|
32
|
-
start: () => void;
|
|
33
|
-
isLoading: boolean;
|
|
34
|
-
error?: string;
|
|
35
|
-
messages: InboxMessage[];
|
|
36
|
-
unreadMessageCount: number;
|
|
37
|
-
totalMessageCount: number;
|
|
38
|
-
canPaginate: boolean;
|
|
39
|
-
setPaginationLimit: (limit: number) => void;
|
|
40
|
-
fetchNextPageOfMessages: () => Promise<InboxMessage[]>;
|
|
41
|
-
refresh: () => Promise<void>;
|
|
42
|
-
isRefreshing: boolean;
|
|
43
|
-
readAllMessages: () => Promise<void>;
|
|
44
|
-
readMessage: (messageId: string) => string;
|
|
45
|
-
unreadMessage: (messageId: string) => string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface CourierContext {
|
|
49
|
-
auth: CourierAuthContext;
|
|
50
|
-
push: CourierPushContext;
|
|
51
|
-
inbox: CourierInboxContext;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const CourierContext = createContext<CourierContext | undefined>(undefined);
|
|
55
|
-
|
|
56
|
-
export const CourierProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
|
57
|
-
|
|
58
|
-
// Auth
|
|
59
|
-
const [auth_userId, auth_setUserId] = useState<string | undefined>(undefined);
|
|
60
|
-
const [auth_isLoading, auth_setIsLoading] = useState<boolean>(false);
|
|
61
|
-
const [auth_error, auth_setError] = useState<string | undefined>(undefined);
|
|
62
|
-
|
|
63
|
-
// Push
|
|
64
|
-
const [push_pushNotificationDelivered, inbox_setPushNotificationDelivered] = useState<any>(undefined);
|
|
65
|
-
const [push_pushNotificationClicked, inbox_setPushNotificationClicked] = useState<any>(undefined);
|
|
66
|
-
const [push_apnsToken, push_setApnsToken] = useState<string | undefined>(undefined);
|
|
67
|
-
const [push_fcmToken, push_setFcmToken] = useState<string | undefined>(undefined);
|
|
68
|
-
const [push_notificationPermission, push_setNotificationPermission] = useState<string | undefined>(undefined);
|
|
69
|
-
|
|
70
|
-
// Inbox
|
|
71
|
-
const [inbox_isLoading, inbox_setIsLoading] = useState<boolean>(false);
|
|
72
|
-
const [inbox_isRefreshing, inbox_setIsRefreshing] = useState<boolean>(false);
|
|
73
|
-
const [inbox_error, inbox_setError] = useState<string | undefined>(undefined);
|
|
74
|
-
const [inbox_messages, inbox_setMessages] = useState<InboxMessage[]>([]);
|
|
75
|
-
const [inbox_unreadMessageCount, inbox_setUnreadMessageCount] = useState<number>(0);
|
|
76
|
-
const [inbox_totalMessageCount, inbox_setTotalMessageCount] = useState<number>(0);
|
|
77
|
-
const [inbox_canPaginate, inbox_setCanPaginate] = useState<boolean>(false);
|
|
78
|
-
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
|
|
81
|
-
// Get the initial values
|
|
82
|
-
const userId = Courier.shared.userId;
|
|
83
|
-
auth_setUserId(userId);
|
|
84
|
-
|
|
85
|
-
}, []);
|
|
86
|
-
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
|
|
89
|
-
return () => {
|
|
90
|
-
authListener?.remove();
|
|
91
|
-
pushListener?.remove();
|
|
92
|
-
inboxListener?.remove();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
}, []);
|
|
96
|
-
|
|
97
|
-
const startAuth = () => {
|
|
98
|
-
|
|
99
|
-
if (!authListener) {
|
|
100
|
-
|
|
101
|
-
authListener = Courier.shared.addAuthenticationListener({
|
|
102
|
-
onUserChanged: (userId) => auth_setUserId(userId)
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const startPush = () => {
|
|
110
|
-
|
|
111
|
-
// Permissions
|
|
112
|
-
syncNotificationPermissions();
|
|
113
|
-
|
|
114
|
-
// Push tokens
|
|
115
|
-
syncTokens();
|
|
116
|
-
|
|
117
|
-
if (!pushListener) {
|
|
118
|
-
|
|
119
|
-
pushListener = Courier.shared.addPushNotificationListener({
|
|
120
|
-
onPushNotificationDelivered: (push) => inbox_setPushNotificationDelivered(push),
|
|
121
|
-
onPushNotificationClicked: (push) => inbox_setPushNotificationClicked(push)
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const startInbox = () => {
|
|
129
|
-
|
|
130
|
-
if (!inboxListener) {
|
|
131
|
-
|
|
132
|
-
inboxListener = Courier.shared.addInboxListener({
|
|
133
|
-
onInitialLoad: () => {
|
|
134
|
-
inbox_setIsLoading(true);
|
|
135
|
-
inbox_setError(undefined);
|
|
136
|
-
},
|
|
137
|
-
onError: (error) => {
|
|
138
|
-
inbox_setIsLoading(false);
|
|
139
|
-
inbox_setError(error);
|
|
140
|
-
},
|
|
141
|
-
onMessagesChanged: (messages, unreadMessageCount, totalMessageCount, canPaginate) => {
|
|
142
|
-
inbox_setIsLoading(false);
|
|
143
|
-
inbox_setError(undefined);
|
|
144
|
-
inbox_setMessages(messages);
|
|
145
|
-
inbox_setUnreadMessageCount(unreadMessageCount);
|
|
146
|
-
inbox_setTotalMessageCount(totalMessageCount);
|
|
147
|
-
inbox_setCanPaginate(canPaginate);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const signIn = async (props: { accessToken: string, clientKey?: string, userId: string }): Promise<void> => {
|
|
156
|
-
|
|
157
|
-
auth_setIsLoading(true);
|
|
158
|
-
auth_setError(undefined);
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
await Courier.shared.signIn(props);
|
|
162
|
-
} catch (error) {
|
|
163
|
-
auth_setError(error as string);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
auth_setIsLoading(false);
|
|
167
|
-
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const signOut = async (): Promise<void> => {
|
|
171
|
-
|
|
172
|
-
auth_setIsLoading(true);
|
|
173
|
-
auth_setError(undefined);
|
|
174
|
-
|
|
175
|
-
try {
|
|
176
|
-
await Courier.shared.signOut();
|
|
177
|
-
} catch (error) {
|
|
178
|
-
auth_setError(error as string);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
auth_setIsLoading(false);
|
|
182
|
-
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const syncNotificationPermissions = async () => {
|
|
186
|
-
|
|
187
|
-
const status = await Courier.shared.getNotificationPermissionStatus();
|
|
188
|
-
push_setNotificationPermission(status);
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const syncTokens = async () => {
|
|
193
|
-
|
|
194
|
-
// APNS
|
|
195
|
-
const apnsToken = Courier.shared.apnsToken;
|
|
196
|
-
push_setApnsToken(apnsToken);
|
|
197
|
-
|
|
198
|
-
const fcmToken = await Courier.shared.fcmToken;
|
|
199
|
-
push_setFcmToken(fcmToken);
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const requestNotificationPermission = async () => {
|
|
204
|
-
const status = await Courier.shared.requestNotificationPermission();
|
|
205
|
-
push_setNotificationPermission(status);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const iOSForegroundPresentationOptions = (options: iOSForegroundPresentationOptions[]) => {
|
|
209
|
-
Courier.shared.iOSForegroundPresentationOptions({
|
|
210
|
-
options: options,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const setPaginationLimit = (limit: number) => {
|
|
215
|
-
Courier.shared.setInboxPaginationLimit({ limit });
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const fetchNextPageOfMessages = (): Promise<InboxMessage[]> => {
|
|
219
|
-
return Courier.shared.fetchNextPageOfMessages();
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const refresh = async () => {
|
|
223
|
-
inbox_setIsRefreshing(true);
|
|
224
|
-
await Courier.shared.refreshInbox();
|
|
225
|
-
inbox_setIsRefreshing(false);
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const readAllMessages = () => {
|
|
229
|
-
|
|
230
|
-
// Skip if no user is found
|
|
231
|
-
if (!Courier.shared.userId) {
|
|
232
|
-
return Promise.resolve();
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Read the messages
|
|
236
|
-
return Courier.shared.readAllInboxMessages();
|
|
237
|
-
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
const readMessage = (messageId: string) => {
|
|
241
|
-
return Courier.shared.readMessage({ messageId });
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const unreadMessage = (messageId: string) => {
|
|
245
|
-
return Courier.shared.unreadMessage({ messageId });
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
return (
|
|
249
|
-
<CourierContext.Provider value={{
|
|
250
|
-
auth: {
|
|
251
|
-
start: startAuth,
|
|
252
|
-
isLoading: auth_isLoading,
|
|
253
|
-
error: auth_error,
|
|
254
|
-
userId: auth_userId,
|
|
255
|
-
signIn,
|
|
256
|
-
signOut
|
|
257
|
-
},
|
|
258
|
-
push: {
|
|
259
|
-
start: startPush,
|
|
260
|
-
delivered: push_pushNotificationDelivered,
|
|
261
|
-
clicked: push_pushNotificationClicked,
|
|
262
|
-
tokens: {
|
|
263
|
-
fcm: push_fcmToken,
|
|
264
|
-
apns: push_apnsToken,
|
|
265
|
-
},
|
|
266
|
-
iOSForegroundPresentationOptions,
|
|
267
|
-
notificationPermissionStatus: push_notificationPermission,
|
|
268
|
-
requestNotificationPermission,
|
|
269
|
-
},
|
|
270
|
-
inbox: {
|
|
271
|
-
start: startInbox,
|
|
272
|
-
isLoading: inbox_isLoading,
|
|
273
|
-
error: inbox_error,
|
|
274
|
-
messages: inbox_messages,
|
|
275
|
-
unreadMessageCount: inbox_unreadMessageCount,
|
|
276
|
-
totalMessageCount: inbox_totalMessageCount,
|
|
277
|
-
canPaginate: inbox_canPaginate,
|
|
278
|
-
setPaginationLimit,
|
|
279
|
-
fetchNextPageOfMessages,
|
|
280
|
-
refresh,
|
|
281
|
-
isRefreshing: inbox_isRefreshing,
|
|
282
|
-
readAllMessages,
|
|
283
|
-
readMessage,
|
|
284
|
-
unreadMessage,
|
|
285
|
-
}
|
|
286
|
-
}}>
|
|
287
|
-
{children}
|
|
288
|
-
</CourierContext.Provider>
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
// Auth Hook
|
|
294
|
-
export const useCourierAuth = (): CourierAuthContext => {
|
|
295
|
-
|
|
296
|
-
const context = useContext(CourierContext);
|
|
297
|
-
|
|
298
|
-
if (!context) {
|
|
299
|
-
throw new Error('useCourierAuth must be used within an CourierProvider');
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
context.auth.start();
|
|
303
|
-
|
|
304
|
-
return context.auth;
|
|
305
|
-
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
interface UseCourierPushProps {
|
|
309
|
-
iOSForegroundPresentationOptions?: iOSForegroundPresentationOptions[]
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Push Hook
|
|
313
|
-
export const useCourierPush = (props: UseCourierPushProps = {}): CourierPushContext => {
|
|
314
|
-
|
|
315
|
-
const context = useContext(CourierContext);
|
|
316
|
-
|
|
317
|
-
if (!context) {
|
|
318
|
-
throw new Error('useCourierPush must be used within an CourierProvider');
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Set the presentation options
|
|
322
|
-
const options = props.iOSForegroundPresentationOptions;
|
|
323
|
-
if (options) {
|
|
324
|
-
context.push.iOSForegroundPresentationOptions(options);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
context.push.start();
|
|
328
|
-
|
|
329
|
-
return context.push;
|
|
330
|
-
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
interface UseCourierInboxProps {
|
|
334
|
-
paginationLimit?: number;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Inbox Hook
|
|
338
|
-
export const useCourierInbox = (props: UseCourierInboxProps = {}): CourierInboxContext => {
|
|
339
|
-
|
|
340
|
-
const context = useContext(CourierContext);
|
|
341
|
-
|
|
342
|
-
if (!context) {
|
|
343
|
-
throw new Error('useCourierInbox must be used within an CourierProvider');
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// Set the initial pagination limit if needed
|
|
347
|
-
const limit = props.paginationLimit;
|
|
348
|
-
if (limit) {
|
|
349
|
-
context.inbox.setPaginationLimit(limit);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
context.inbox.start();
|
|
353
|
-
|
|
354
|
-
return context.inbox;
|
|
355
|
-
|
|
356
|
-
};
|