@bigbinary/neeto-commons-rn 1.0.88 → 1.0.89

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.
@@ -1 +1 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.usePushNotification=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _react=require("react");var _reactNative=require("react-native");var _dayjs=_interopRequireDefault(require("dayjs"));var _reactNativeNotifications=require("react-native-notifications");var _reactNativePermissions=require("react-native-permissions");var _reactNativePushNotification=_interopRequireDefault(require("react-native-push-notification"));var _bugsnag=require("../../config/bugsnag");var _constants=require("../../constants");var _asyncStore=require("../asyncStore");var _useNotification2=require("../../hooks/query/useNotification");var _useAppState=require("../../hooks/useAppState");var usePushNotification=exports.usePushNotification=function usePushNotification(isLoggedIn,_ref){var handleClick=_ref.handleClick;var appState=(0,_useAppState.useAppState)();var _useNotification=(0,_useNotification2.useNotification)(),useRegisterTokenMutation=_useNotification.useRegisterTokenMutation,useMarkReadUnreadNotification=_useNotification.useMarkReadUnreadNotification;var _useRegisterTokenMuta=useRegisterTokenMutation(),registerToken=_useRegisterTokenMuta.mutate;var _useMarkReadUnreadNot=useMarkReadUnreadNotification(),markReadUnreadNotification=_useMarkReadUnreadNot.mutate;(0,_react.useEffect)(function(){var events=initializeNotificationEvents();return function(){events.forEach(function(event){return event.remove();});};},[]);(0,_react.useEffect)(function(){if(isLoggedIn&&appState==="active"){initializePN();}},[initializePN,isLoggedIn,appState]);var initializePN=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){var notificationPermission=yield(0,_reactNativePermissions.checkNotifications)();if(["blocked","unavailable"].includes(notificationPermission.status)){return;}var isRegisteredAlready=yield _reactNativeNotifications.Notifications.isRegisteredForRemoteNotifications();var storedDeviceToken=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(isRegisteredAlready&&storedDeviceToken)return;registerForRemoteNotifications();});return function initializePN(){return _ref2.apply(this,arguments);};}();var registerForRemoteNotifications=function registerForRemoteNotifications(){_reactNativeNotifications.Notifications.registerRemoteNotifications();var registerDeviceOnce=function(event){var isRegistereed=false;return function(){var _ref3=(0,_asyncToGenerator2.default)(function*(event){if(!isRegistereed){isRegistereed=true;if(event.deviceToken){var payload={device:{device_token:event.deviceToken,platform:_reactNative.Platform.OS}};var notificationDeviceId=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(typeof notificationDeviceId!=="string"){registerToken(payload,{onError:function onError(){return isRegistereed=false;}});}}}});return function(_x){return _ref3.apply(this,arguments);};}();}();_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistered(function(){var _ref4=(0,_asyncToGenerator2.default)(function*(event){return registerDeviceOnce(event);});return function(_x2){return _ref4.apply(this,arguments);};}());_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistrationFailed(function(event){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(event),"notification");});};var markNotificationsAsRead=function markNotificationsAsRead(notification){var _notification$payload,_notification$payload2,_notification$payload3,_notification$payload4;var notificationId=(notification==null?void 0:(_notification$payload=notification.payload)==null?void 0:_notification$payload.notification_id)||(notification==null?void 0:(_notification$payload2=notification.payload)==null?void 0:(_notification$payload3=_notification$payload2.aps)==null?void 0:(_notification$payload4=_notification$payload3.alert)==null?void 0:_notification$payload4.notification_id);handleClick(notification);if(notificationId){markReadUnreadNotification({readAt:(0,_dayjs.default)().toISOString(),notificationId:notificationId});}};_reactNativePushNotification.default.configure({onNotification:function onNotification(notification){return handleClick(notification);}});var initializeNotificationEvents=function initializeNotificationEvents(){var foregroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedForeground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload5,_notification$payload6,_notification$payload7;_reactNativeNotifications.Notifications.postLocalNotification({body:notification==null?void 0:(_notification$payload5=notification.payload)==null?void 0:_notification$payload5["gcm.notification.body"],title:notification==null?void 0:(_notification$payload6=notification.payload)==null?void 0:_notification$payload6["gcm.notification.title"],url:notification==null?void 0:(_notification$payload7=notification.payload)==null?void 0:_notification$payload7.url});}completion({alert:true,sound:true,badge:false});});var backgroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedBackground(function(_,completion){completion({alert:true,sound:true,badge:false});});var openedEvent=_reactNativeNotifications.Notifications.events().registerNotificationOpened(function(notification,completion){markNotificationsAsRead(notification);completion();});if(_reactNative.Platform.OS==="android"){_reactNativeNotifications.Notifications.setNotificationChannel({channelId:"default",name:"default",importance:5,enableLights:true,enableVibration:true,showBadge:true});}return[foregroundEvent,backgroundEvent,openedEvent];};return[];};
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.usePushNotification=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _react=require("react");var _reactNative=require("react-native");var _dayjs=_interopRequireDefault(require("dayjs"));var _reactNativeNotifications=require("react-native-notifications");var _reactNativePermissions=require("react-native-permissions");var _reactNativePushNotification=_interopRequireDefault(require("react-native-push-notification"));var _bugsnag=require("../../config/bugsnag");var _constants=require("../../constants");var _asyncStore=require("../asyncStore");var _useNotification2=require("../../hooks/query/useNotification");var _useAppState=require("../../hooks/useAppState");var _store=require("../../store");var usePushNotification=exports.usePushNotification=function usePushNotification(isLoggedIn,_ref){var handleClick=_ref.handleClick;var appState=(0,_useAppState.useAppState)();var _useNotification=(0,_useNotification2.useNotification)(),useRegisterTokenMutation=_useNotification.useRegisterTokenMutation,useMarkReadUnreadNotification=_useNotification.useMarkReadUnreadNotification;var _useRegisterTokenMuta=useRegisterTokenMutation(),registerToken=_useRegisterTokenMuta.mutate;var _useMarkReadUnreadNot=useMarkReadUnreadNotification(),markReadUnreadNotification=_useMarkReadUnreadNot.mutate;(0,_react.useEffect)(function(){var events=initializeNotificationEvents();return function(){events.forEach(function(event){return event.remove();});};},[]);(0,_react.useEffect)(function(){if(isLoggedIn&&appState==="active"){initializePN();}},[initializePN,isLoggedIn,appState]);var initializePN=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){var notificationPermission=yield(0,_reactNativePermissions.checkNotifications)();if(["blocked","unavailable"].includes(notificationPermission.status)){return;}var isRegisteredAlready=yield _reactNativeNotifications.Notifications.isRegisteredForRemoteNotifications();var storedDeviceToken=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(isRegisteredAlready&&storedDeviceToken)return;registerForRemoteNotifications();});return function initializePN(){return _ref2.apply(this,arguments);};}();var registerForRemoteNotifications=function registerForRemoteNotifications(){_reactNativeNotifications.Notifications.registerRemoteNotifications();var registerDeviceOnce=function(){var isRegistered=false;return function(){var _ref3=(0,_asyncToGenerator2.default)(function*(event){var _Store$getState,_Store$getState$auth;if(isRegistered)return;var isLoggedIn=((_Store$getState=_store.Store.getState())==null?void 0:(_Store$getState$auth=_Store$getState.auth)==null?void 0:_Store$getState$auth.isLoggedIn)||false;if(isLoggedIn&&event.deviceToken){isRegistered=true;var payload={device:{device_token:event.deviceToken,platform:_reactNative.Platform.OS}};var notificationDeviceId=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(typeof notificationDeviceId!=="string"){registerToken(payload,{onError:function onError(){return isRegistered=false;}});}}});return function(_x){return _ref3.apply(this,arguments);};}();}();_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistered(function(event){return registerDeviceOnce(event);});_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistrationFailed(function(event){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(event),"notification");});};var markNotificationsAsRead=function markNotificationsAsRead(notification){var _notification$payload,_notification$payload2,_notification$payload3,_notification$payload4;var notificationId=(notification==null?void 0:(_notification$payload=notification.payload)==null?void 0:_notification$payload.notification_id)||(notification==null?void 0:(_notification$payload2=notification.payload)==null?void 0:(_notification$payload3=_notification$payload2.aps)==null?void 0:(_notification$payload4=_notification$payload3.alert)==null?void 0:_notification$payload4.notification_id);handleClick(notification);if(notificationId){markReadUnreadNotification({readAt:(0,_dayjs.default)().toISOString(),notificationId:notificationId});}};_reactNativePushNotification.default.configure({onNotification:function onNotification(notification){return handleClick(notification);}});var initializeNotificationEvents=function initializeNotificationEvents(){var foregroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedForeground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload5,_notification$payload6,_notification$payload7;_reactNativeNotifications.Notifications.postLocalNotification({body:notification==null?void 0:(_notification$payload5=notification.payload)==null?void 0:_notification$payload5["gcm.notification.body"],title:notification==null?void 0:(_notification$payload6=notification.payload)==null?void 0:_notification$payload6["gcm.notification.title"],url:notification==null?void 0:(_notification$payload7=notification.payload)==null?void 0:_notification$payload7.url});}completion({alert:true,sound:true,badge:false});});var backgroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedBackground(function(_,completion){completion({alert:true,sound:true,badge:false});});var openedEvent=_reactNativeNotifications.Notifications.events().registerNotificationOpened(function(notification,completion){markNotificationsAsRead(notification);completion();});if(_reactNative.Platform.OS==="android"){_reactNativeNotifications.Notifications.setNotificationChannel({channelId:"default",name:"default",importance:5,enableLights:true,enableVibration:true,showBadge:true});}return[foregroundEvent,backgroundEvent,openedEvent];};return[];};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-rn",
3
- "version": "1.0.88",
3
+ "version": "1.0.89",
4
4
  "main": ".",
5
5
  "files": [
6
6
  "api",