UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

11 lines 1.44 kB
import{DataRequest}from'@shopgate/pwa-core';import{openPushNotification}from"../../action-creators/app";import handleLink from"./handleLink";var PUSH_MESSAGE_OPENED='ajax_push_message_opened';/** * Handles the opening of a push notification. If the payload contains a link, it calls * the openDeepLink actions additionally. * @param {Object} payload The push notification payload. * @return {Function} A redux thunk. */export default function handlePushNotification(){var payload=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){var _payload$link=payload.link,link=_payload$link===void 0?'':_payload$link,_payload$notification=payload.notificationId,notificationId=_payload$notification===void 0?null:_payload$notification,nativeNotificationNotShown=payload.nativeNotificationNotShown;/** * The following property is only available on iOS. A value of TRUE indicates that the push * message came in, while the app was open. Since the app would instantly open the link of the * message in those situations, the link handling is suppressed to not distract the user. */if(nativeNotificationNotShown===true){return;}if(notificationId){var id=notificationId.toString();// Send tracking event to the backend new DataRequest(PUSH_MESSAGE_OPENED).setPayload({notificationId:id}).dispatch();}dispatch(handleLink(payload,true));dispatch(openPushNotification(notificationId,link));};}