Changeset View
Changeset View
Standalone View
Standalone View
lib/utils/push-alerts.js
// @flow | // @flow | ||||
export type NotifPermissionAlertInfo = { | export type NotifPermissionAlertInfo = { | ||||
+totalAlerts: number, | +totalAlerts: number, | ||||
+lastAlertTime: number, | +lastAlertTime: number, | ||||
}; | }; | ||||
const defaultNotifPermissionAlertInfo: NotifPermissionAlertInfo = { | const defaultNotifPermissionAlertInfo: NotifPermissionAlertInfo = { | ||||
totalAlerts: 0, | totalAlerts: 0, | ||||
lastAlertTime: 0, | lastAlertTime: 0, | ||||
}; | }; | ||||
const recordNotifPermissionAlertActionType = 'RECORD_NOTIF_PERMISSION_ALERT'; | const recordNotifPermissionAlertActionType = 'RECORD_NOTIF_PERMISSION_ALERT'; | ||||
const msInDay = 24 * 60 * 60 * 1000; | |||||
const shouldSkipPushPermissionAlert = ( | |||||
alertInfo: NotifPermissionAlertInfo, | |||||
): boolean => | |||||
(alertInfo.totalAlerts > 3 && | |||||
alertInfo.lastAlertTime > Date.now() - msInDay) || | |||||
(alertInfo.totalAlerts > 6 && | |||||
alertInfo.lastAlertTime > Date.now() - msInDay * 3) || | |||||
(alertInfo.totalAlerts > 9 && | |||||
alertInfo.lastAlertTime > Date.now() - msInDay * 7); | |||||
export { | export { | ||||
defaultNotifPermissionAlertInfo, | defaultNotifPermissionAlertInfo, | ||||
recordNotifPermissionAlertActionType, | recordNotifPermissionAlertActionType, | ||||
shouldSkipPushPermissionAlert, | |||||
}; | }; |