@trycourier/courier-react-native 2.0.0-beta4 → 2.0.0-beta6

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.
@@ -23,6 +23,7 @@ interface CourierPushContext {
23
23
  apns?: string;
24
24
  fcm?: string;
25
25
  };
26
+ iOSForegroundPresentationOptions: (options: iOSForegroundPresentationOptions[]) => void;
26
27
  notificationPermissionStatus?: string;
27
28
  requestNotificationPermission: () => Promise<void>;
28
29
  }
@@ -35,14 +36,13 @@ interface CourierInboxContext {
35
36
  unreadMessageCount: number;
36
37
  totalMessageCount: number;
37
38
  canPaginate: boolean;
38
- iOSForegroundPresentationOptions: (options: iOSForegroundPresentationOptions[]) => void;
39
39
  setPaginationLimit: (limit: number) => void;
40
40
  fetchNextPageOfMessages: () => Promise<InboxMessage[]>;
41
41
  refresh: () => Promise<void>;
42
42
  isRefreshing: boolean;
43
43
  readAllMessages: () => Promise<void>;
44
- readMessage: (messageId: string) => Promise<void>;
45
- unreadMessage: (messageId: string) => Promise<void>;
44
+ readMessage: (messageId: string) => string;
45
+ unreadMessage: (messageId: string) => string;
46
46
  }
47
47
 
48
48
  interface CourierContext {
@@ -189,13 +189,13 @@ export const CourierProvider: React.FC<{ children: ReactNode }> = ({ children })
189
189
 
190
190
  }
191
191
 
192
- const syncTokens = () => {
192
+ const syncTokens = async () => {
193
193
 
194
194
  // APNS
195
195
  const apnsToken = Courier.shared.apnsToken;
196
196
  push_setApnsToken(apnsToken);
197
197
 
198
- const fcmToken = Courier.shared.fcmToken;
198
+ const fcmToken = await Courier.shared.fcmToken;
199
199
  push_setFcmToken(fcmToken);
200
200
 
201
201
  }
@@ -263,6 +263,7 @@ export const CourierProvider: React.FC<{ children: ReactNode }> = ({ children })
263
263
  fcm: push_fcmToken,
264
264
  apns: push_apnsToken,
265
265
  },
266
+ iOSForegroundPresentationOptions,
266
267
  notificationPermissionStatus: push_notificationPermission,
267
268
  requestNotificationPermission,
268
269
  },
@@ -274,7 +275,6 @@ export const CourierProvider: React.FC<{ children: ReactNode }> = ({ children })
274
275
  unreadMessageCount: inbox_unreadMessageCount,
275
276
  totalMessageCount: inbox_totalMessageCount,
276
277
  canPaginate: inbox_canPaginate,
277
- iOSForegroundPresentationOptions,
278
278
  setPaginationLimit,
279
279
  fetchNextPageOfMessages,
280
280
  refresh,
@@ -305,8 +305,12 @@ export const useCourierAuth = (): CourierAuthContext => {
305
305
 
306
306
  };
307
307
 
308
+ interface UseCourierPushProps {
309
+ iOSForegroundPresentationOptions?: iOSForegroundPresentationOptions[]
310
+ }
311
+
308
312
  // Push Hook
309
- export const useCourierPush = (): CourierPushContext => {
313
+ export const useCourierPush = (props: UseCourierPushProps = {}): CourierPushContext => {
310
314
 
311
315
  const context = useContext(CourierContext);
312
316
 
@@ -314,6 +318,12 @@ export const useCourierPush = (): CourierPushContext => {
314
318
  throw new Error('useCourierPush must be used within an CourierProvider');
315
319
  }
316
320
 
321
+ // Set the presentation options
322
+ const options = props.iOSForegroundPresentationOptions;
323
+ if (options) {
324
+ context.push?.iOSForegroundPresentationOptions(options);
325
+ }
326
+
317
327
  context.push.start();
318
328
 
319
329
  return context.push;
@@ -322,9 +332,6 @@ export const useCourierPush = (): CourierPushContext => {
322
332
 
323
333
  interface UseCourierInboxProps {
324
334
  paginationLimit?: number;
325
- iOS?: {
326
- foregroundPresentationOptions?: iOSForegroundPresentationOptions[]
327
- }
328
335
  }
329
336
 
330
337
  // Inbox Hook
@@ -342,12 +349,6 @@ export const useCourierInbox = (props: UseCourierInboxProps = {}): CourierInboxC
342
349
  context.inbox?.setPaginationLimit(limit);
343
350
  }
344
351
 
345
- // Set the presentation options
346
- const options = props.iOS?.foregroundPresentationOptions;
347
- if (options) {
348
- context.inbox?.iOSForegroundPresentationOptions(options);
349
- }
350
-
351
352
  context.inbox?.start();
352
353
 
353
354
  return context.inbox;
package/src/index.tsx CHANGED
@@ -136,7 +136,7 @@ class Courier {
136
136
  * using Courier token management apis
137
137
  * @example const fcmToken = await Courier.fcmToken
138
138
  */
139
- get fcmToken(): string | undefined {
139
+ get fcmToken(): Promise<string | undefined> {
140
140
  return CourierReactNativeModules.getFcmToken();
141
141
  }
142
142
 
@@ -305,7 +305,7 @@ class Courier {
305
305
  * @param props
306
306
  * @returns
307
307
  */
308
- public readMessage(props: { messageId: string }): Promise<void> {
308
+ public readMessage(props: { messageId: string }): string {
309
309
  return CourierReactNativeModules.readMessage(props.messageId);
310
310
  }
311
311
 
@@ -314,7 +314,7 @@ class Courier {
314
314
  * @param props
315
315
  * @returns
316
316
  */
317
- public unreadMessage(props: { messageId: string }): Promise<void> {
317
+ public unreadMessage(props: { messageId: string }): string {
318
318
  return CourierReactNativeModules.unreadMessage(props.messageId);
319
319
  }
320
320
 
@@ -338,26 +338,32 @@ class Courier {
338
338
  const inboxListener = new CourierInboxListener();
339
339
 
340
340
  if (props.onInitialLoad) {
341
+
341
342
  inboxListener.onInitialLoad = CourierEventEmitter.addListener('inboxInitialLoad', () => {
342
- props.onInitialLoad!()
343
+ props.onInitialLoad!();
343
344
  });
345
+
344
346
  }
345
347
 
346
348
  if (props.onError) {
349
+
347
350
  inboxListener.onError = CourierEventEmitter.addListener('inboxError', event => {
348
- props.onError!(event)
351
+ props.onError!(event);
349
352
  });
353
+
350
354
  }
351
355
 
352
356
  if (props.onMessagesChanged) {
357
+
353
358
  inboxListener.onMessagesChanged = CourierEventEmitter.addListener('inboxMessagesChanged', event => {
354
359
  props.onMessagesChanged!(
355
360
  event.messages,
356
361
  event.unreadMessageCount,
357
362
  event.totalMessageCount,
358
363
  event.canPaginate,
359
- )
364
+ );
360
365
  });
366
+
361
367
  }
362
368
 
363
369
  inboxListener.listenerId = CourierReactNativeModules.addInboxListener();
@@ -395,6 +401,8 @@ class Courier {
395
401
 
396
402
  /**
397
403
  * TODO
404
+ * Min = 1
405
+ * Max = 100
398
406
  * @param props
399
407
  * @returns
400
408
  */