diff --git a/native/chat/settings/thread-settings-push-notifs.react.js b/native/chat/settings/thread-settings-push-notifs.react.js --- a/native/chat/settings/thread-settings-push-notifs.react.js +++ b/native/chat/settings/thread-settings-push-notifs.react.js @@ -1,7 +1,10 @@ // @flow +import { Entypo } from '@expo/vector-icons'; import * as React from 'react'; -import { View, Switch } from 'react-native'; +import { View, Switch, TouchableOpacity, Platform } from 'react-native'; +import Alert from 'react-native/Libraries/Alert/Alert'; +import Linking from 'react-native/Libraries/Linking/Linking'; import { updateSubscriptionActionTypes, @@ -19,6 +22,7 @@ } from 'lib/utils/action-utils'; import { SingleLine } from '../../components/single-line.react'; +import { useSelector } from '../../redux/redux-utils'; import { useStyles } from '../../themes/colors'; type BaseProps = { @@ -31,6 +35,7 @@ // Redux dispatch functions +dispatchActionPromise: DispatchActionPromise, // async functions that hit server APIs + +hasPushPermissions: boolean, +updateSubscription: ( subscriptionUpdate: SubscriptionUpdateRequest, ) => Promise, @@ -48,15 +53,29 @@ render() { const componentLabel = 'Push notifs'; + let notificationsSettingsLinkingIcon = undefined; + if (!this.props.hasPushPermissions) { + notificationsSettingsLinkingIcon = ( + + + + + + ); + } return ( {componentLabel} + {notificationsSettingsLinkingIcon} @@ -75,6 +94,40 @@ }), ); }; + + onNotificationsSettingsLinkingIconPress = () => { + const alertTitle = + Platform.OS === 'ios' + ? 'Need notif permissions' + : 'Unable to initialize notifs'; + let alertMessage; + if (Platform.OS === 'ios' && this.state.currentValue) { + alertMessage = + 'Notifs for this thread are enabled, but cannot be delivered ' + + 'to this device because you haven’t granted notif permissions to Comm. ' + + 'Please enable them in Settings App → Notifications → Comm'; + } else if (Platform.OS === 'ios') { + alertMessage = + 'In order to enable push notifs for this thread, ' + + 'you need to first grant notif permissions to Comm. ' + + 'Please enable them in Settings App → Notifications → Comm'; + } else { + alertMessage = + 'Please check your network connection, make sure Google Play ' + + 'services are installed and enabled, and confirm that your Google ' + + 'Play credentials are valid in the Google Play Store.'; + } + Alert.alert(alertTitle, alertMessage, [ + { + text: 'Go to settings', + onPress: () => Linking.openSettings(), + }, + { + text: 'Cancel', + style: 'cancel', + }, + ]); + }; } const unboundStyles = { @@ -97,6 +150,9 @@ paddingHorizontal: 24, paddingVertical: 3, }, + infoIcon: { + paddingRight: 20, + }, }; const ConnectedThreadSettingsPushNotifs: React.ComponentType = React.memo( @@ -104,12 +160,14 @@ const styles = useStyles(unboundStyles); const dispatchActionPromise = useDispatchActionPromise(); const callUpdateSubscription = useServerCall(updateSubscription); + const hasPushPermissions = useSelector(state => state.deviceToken !== null); return ( ); },