Changeset View
Changeset View
Standalone View
Standalone View
native/push/push-handler.react.js
Show All 23 Lines | |||||
import { | import { | ||||
useServerCall, | useServerCall, | ||||
useDispatchActionPromise, | useDispatchActionPromise, | ||||
type DispatchActionPromise, | type DispatchActionPromise, | ||||
} from 'lib/utils/action-utils.js'; | } from 'lib/utils/action-utils.js'; | ||||
import { | import { | ||||
type NotifPermissionAlertInfo, | type NotifPermissionAlertInfo, | ||||
recordNotifPermissionAlertActionType, | recordNotifPermissionAlertActionType, | ||||
shouldSkipPushPermissionAlert, | |||||
} from 'lib/utils/push-alerts.js'; | } from 'lib/utils/push-alerts.js'; | ||||
import { | import { | ||||
androidNotificationChannelID, | androidNotificationChannelID, | ||||
handleAndroidMessage, | handleAndroidMessage, | ||||
getCommAndroidNotificationsEventEmitter, | getCommAndroidNotificationsEventEmitter, | ||||
type AndroidForegroundMessage, | type AndroidForegroundMessage, | ||||
CommAndroidNotifications, | CommAndroidNotifications, | ||||
Show All 27 Lines | |||||
import type { EventSubscription } from '../types/react-native.js'; | import type { EventSubscription } from '../types/react-native.js'; | ||||
import { type GlobalTheme } from '../types/themes.js'; | import { type GlobalTheme } from '../types/themes.js'; | ||||
LogBox.ignoreLogs([ | LogBox.ignoreLogs([ | ||||
// react-native-in-app-message | // react-native-in-app-message | ||||
'ForceTouchGestureHandler is not available', | 'ForceTouchGestureHandler is not available', | ||||
]); | ]); | ||||
const msInDay = 24 * 60 * 60 * 1000; | |||||
type BaseProps = { | type BaseProps = { | ||||
+navigation: RootNavigationProp<'App'>, | +navigation: RootNavigationProp<'App'>, | ||||
}; | }; | ||||
type Props = { | type Props = { | ||||
...BaseProps, | ...BaseProps, | ||||
// Navigation state | // Navigation state | ||||
+activeThread: ?string, | +activeThread: ?string, | ||||
// Redux state | // Redux state | ||||
▲ Show 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | if (deviceType === 'ios') { | ||||
iosPushPermissionResponseReceived(); | iosPushPermissionResponseReceived(); | ||||
} else { | } else { | ||||
this.showNotifAlertOnAndroid(); | this.showNotifAlertOnAndroid(); | ||||
} | } | ||||
}; | }; | ||||
showNotifAlertOnAndroid() { | showNotifAlertOnAndroid() { | ||||
const alertInfo = this.props.notifPermissionAlertInfo; | const alertInfo = this.props.notifPermissionAlertInfo; | ||||
if ( | if (shouldSkipPushPermissionAlert(alertInfo)) { | ||||
(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) | |||||
) { | |||||
return; | return; | ||||
} | } | ||||
this.props.dispatch({ | this.props.dispatch({ | ||||
type: recordNotifPermissionAlertActionType, | type: recordNotifPermissionAlertActionType, | ||||
payload: { time: Date.now() }, | payload: { time: Date.now() }, | ||||
}); | }); | ||||
Alert.alert( | Alert.alert( | ||||
▲ Show 20 Lines • Show All 208 Lines • Show Last 20 Lines |